1 .Von Neumann invented RAM model in Princeton .\matrix{1 1;1 0}^n = \matrix{F_{n+1} F_n; F_n F_{n-1}} 2 ."fudge factor" c: g(n) \leq c f(n) \forall n \geq n_0 .L'Hospital rule # (1+1/n)^n = e^{n \ln(1+1/n)}; when n goes to infinity, \ln(1+1/n) goes to 0 .bound of H_n: \int_1^{1+n}(1/x)dx \leq H_n \leq 1+\int_1^n (1/x)dx 3 //613 is prime //3702 = 2*3*617 //660 = 2^2*3*5*11 //4003 is prime 4 .O(n) median algorithm *partition n numbers to groups of 5 elements *find the median-of-5 in constant time *find the median of these (n/5) medians in O(n/5) *then (3n/10) of the n numbers can be safely discarded 5 .n! reads "n factorial" .the merge step is called the "finger algorithm" *use your fingers as pointers *lower bound (2n-1) is proved by "adversary analysis" .use adversary analysis to prove max(n numbers) has lower time complexity bound (n-1) *everyone except the winner must lose at least once .similarly, second best has lower bound (n-1)+\lceil\lg n\rceil-1 .sortings which beat (n\lg n) bound: *bucket sort (every number in range 1..k)- O(n+k) time, O(k \lg k) space *radix sort (select k=O(n) buckets)- O(n\lg k/lg n) time, O(n) space .Note: Andersson & Nilsson (1997): a new sorting algorithm 6 .Probability theory .prob density function f_A VS. prob distribution function F_A .moment generating function s:E(e^{sA}) VS. prob generating func z:E(z^A) .Erd\"os & Spencer (p18) *\binom{n}{k} ~ n^ke^{-k^2/(2n)-k^3/(6n^2)}/k!*(1-o(1)) if n=o(n^{3/4}) .Bernoulli variable A_i = 1 with prob p .binomial variable B = \sum_1^n A_i \\plato .Poisson trial A_i = 1 with prob p_i *H\"offding's Thm: \sum P_i is upper bounded by B(n,\sum P_i/n) .geometric variable V: Prob(V=n) = p(1-p)^n \forall n \geq 0 .\Phi(x) (normal distribution F_x) is bounded by functions of \Psi(x) (normal density f_x) *\Psi(x)(1/x-1/x^3) \leq 1-\Phi(x) \leq \Psi(x)/x .Strong Law of large numbers: *as n goes to infinity, any (S_n-\mu)/\sigma goes to normal distribution *Corollary: P(|S_n-\mu|>\sigma x) \leq 2\Psi(x)/x .Markov, Chebyshev, and Chernoff bounds *continuous: P(A\geq X)\leq e^{-sx} E(e^{sA}) \forall s\geq 0 *discrete: P(A\geq X)\leq z^{-x} E(z^x) \forall z\geq 1 .bound for binomial variable B *P(B \geq x)\leq e^{-x-\mu} \forall x \geq e^2 \mu ~ 6\mu 7 .quiz scope: recurrence, function, sorting, selection, and comparison trees 8 .Randomized algorithm .Sampling *SampleRank(x, X) { * Let S be a random sample of X-{x} of size s * output 1+N/s*(rank(x,S)-1) *} *analysis: s Prob(y\in S, yi_1)RandSelect(i-i_1, {b_i|i>i_1}) * else RandSelect(i, {b_i|i find biconnected components from DFS tree *Root is an A.P. iff it has \geq 2 children *nonroot a is an A.P. iff there exists v in a's subtree s.t. low(v)\geq a .For directed graph DFS, types of edges include DFS edges, backward (cycle) edges, forward edges, and crossedges .Kosaraju invented the Strong Components Algorithm *DFS search, renumber vertices by postorder (pop) order *Reverse all edges *DFS on the edge-reversed graph, starting on the highest numbered vertices *Output all connected DFS trees *O(V+E) time *Proof of correctness: for any two vertices u, v with lca(u,v)= r, by DFS tree of the reversed graph there is a path from u to r and a path from v to r. Suppose there is no path from r to u. Then, since r is poped later than u, r is either an ancestor of u in the first DFS tree (contradiction) or r and u are in different subtrees (contradicts to the path from u to r, which should be used for the first DFS search). Similarly, there must be a path from v to r. QED 16 .Minimum Spanning Tree, Union-Find (CLRS Ch. 21, 23) .cut: a cut "respects" an edge set E if no edge in E crosses the cut .Prim's algorithm: greedily find min weight crossing the cut respecting current subtree (like DFS) *need heap structure .Kruskal's algorithm: greedily choose min weight edge s.t. no cycles are induced. Stop when all nodes are connected (like BFS) *need Union-Find structure to merge tree. O(E \alpha(V)) time. .Amortized analysis (by Tarjan) of path compression: \log^*V bound //assessed = charged *lemma: Total rank in block j \leq 3/(2 B(j)) where B(j) is the # of blocks in block j 17 .Shortest Paths (CLRS 24.0-24.3, 25.2) .Any subsequence of a shortest path is a shortest subpath *Proof: "surgery" or "cut-and-paste" method .Dijkstra's algorithm: maintain S \subset V *If d(u) + w(adj(u),u) < d(adj(u)) then d(adj(u)) = d(u)+ w(adj(u),u) .Ford-Bellman algorithm: maintain shortest-path tree with less than i edges .All-pair: matrix solution d_{ij}^{m hops} = min(d_{ik}^{m-1 hops}+w(k,j)) *(Change operation: min=>\sum, + =>*) = \sum d_{ik}^{m-1}*w_{kj}=D^{m-1}W *O(n^3 \log n) .Floyd-Warshall: (Floyd from Stanford, Turing Award) *d_{ij}^k = min(d_{ij}^{k-1}, d_{ik}^{k-1} + d_{kj}^{k-1}) *O(n^3) 18 .BFS: define level distance of any edge .Dijkstra's algorithm is BFS if all weights are 1 .O(VE) matching algorithm: Find augmenting path, which is alternating edges of mathced and unmatched vertices. (Aug)\xor(Current Match) = (New Match) by BFS from any unmatched vertex .Adams: for non-bipartite graph, "shrink the blossom" when odd cycle discovered. Time bound O(n^4) => O(nm) => O(\sqrt{n} m)