
Theoretical Computer Science Cheat Sheet Definitions Series f(n)= O(g(n)) iff positive c,n0 such that n n n 2 2 ∃ n(n + 1) 2 n(n + 1)(2n + 1) 3 n (n + 1) 0 f(n) cg(n) n n0. i = , i = , i = . ≤ ≤ ∀ ≥ 2 6 4 i=1 i=1 i=1 f(n)=Ω(g(n)) iff positive c,n such that X X X 0 In general: f(n∃) cg(n) 0 n n . ≥ ≥ ∀ ≥ 0 n n m 1 m+1 m+1 m+1 m f(n)=Θ(g(n)) iff f(n) = O(g(n)) and i = (n + 1) 1 (i + 1) i (m + 1)i m +1 − − − − i=1 i=1 f(n)=Ω(g(n)). X X n 1 m − m 1 m +1 m+1 k f(n)= o(g(n)) iff limn f(n)/g(n) = 0. i = B n − . →∞ m +1 k k i=1 k=0 lim an = a iff ǫ > 0, n0 such that X X n →∞ ∀ ∃ Geometric series: an a <ǫ, n n0. n | − | ∀ ≥ cn+1 1 ∞ 1 ∞ c R ci = − , c =1, ci = , ci = , c < 1, sup S least b such that b s, c 1 6 1 c 1 c | | s S.∈ ≥ i=0 − i=0 − i=1 − Xn X X ∀ ∈ ncn+2 (n + 1)cn+1 + c ∞ c inf S greatest b R such that b ici = − , c =1, ici = , c < 1. ∈ ≤ (c 1)2 6 (1 c)2 | | s, s S. i=0 i=0 ∀ ∈ X − X − N Harmonic series: lim inf an lim inf ai i n,i . n n n n { | ≥ ∈ } 1 n(n + 1) n(n 1) →∞ →∞ H = , iH = H − . N n i i 2 n − 4 lim sup an lim sup ai i n,i . i=1 i=1 n n { | ≥ ∈ } →∞ n X Xn →∞ i n +1 1 n Combinations: Size k sub- H = (n + 1)H n, H = H . k i n − m i m +1 n+1 − m +1 sets of a size n set. i=1 i=1 X X n n k Stirling numbers (1st kind): n n! n n n n Arrangements of an n ele- 1. = , 2. =2 , 3. = , k (n k)!k! k k n k ment set into k cycles. − k=0 − n n n 1 X n n 1 n 1 n 4. = − , 5. = − + − , Stirling numbers (2nd kind): k k k 1 k k k 1 k − − Partitions of an n element n m n n k n r + k r + n +1 set into k non-empty sets. 6. = − , 7. = , m k k m k k n n − k=0 1st order Eulerian numbers: n Xn k k n +1 r s r + s Permutations π π ...π on 8. = , 9. = , 1 2 n m m +1 k n k n 1, 2,...,n with k ascents. k=0 k=0 − { } X X n k k n 1 n n n 2nd order Eulerian numbers. 10. = ( 1) − − , 11. = =1, k k − k 1 n Cn Catalan Numbers: Binary n n 1 n n 1 n 1 trees with n + 1 vertices. 12. =2 − 1, 13. = k − + − , 2 − k k k 1 − n n n n n 14. = (n 1)!, 15. = (n 1)!Hn 1, 16. =1, 17. , 1 − 2 − − n k ≥ k n n 1 n 1 n n n n n 1 2n 18. = (n 1) − + − , 19. = = , 20. = n!, 21. C = , k − k k 1 n 1 n 1 2 k n n +1 n − − − k=0 n n n n n X n 1 n 1 22. = =1, 23. = , 24. = (k + 1) − + (n k) − , 0 n 1 k n 1 k k k − k 1 − − − − 0 1 if k = 0, n n n +1 25. = 26. =2n n 1, 27. =3n (n + 1)2n + , k 0 otherwise 1 − − 2 − 2 n n m n n x + k n n +1 n n k 28. xn = , 29. = (m +1 k)n( 1)k, 30. m! = , k n m k − − m k n m k=0 k=0 k=0 X n X X − n n n k n k m n n 31. = − ( 1) − − k!, 32. =1, 33. =0 for n =0, m k m − 0 n 6 k=0 X n n n 1 n 1 n (2n)n 34. = (k + 1) − + (2n 1 k) − , 35. = , k k − − k 1 k 2n k=0 n − nX x n x + n 1 k n +1 n k k n k 36. = − − , 37. = = (m + 1) − , x n k 2n m +1 k m m − Xk=0 Xk kX=0 Theoretical Computer Science Cheat Sheet Identities Cont. Trees n n n n +1 n k k n k 1 k x n x + k Every tree with n 38. = = n − = n! , 39. = , m +1 k m m k! m x n k 2n vertices has n 1 k k=0 k=0 k=0 − X X X − X edges. n n k +1 n k n n +1 k m k 40. = ( 1) − , 41. = ( 1) − , m k m +1 − m k +1 m − Kraft inequal- k k X m X m ity: If the depths m + n +1 n + k m + n +1 n + k 42. = k , 43. = k(n + k) , of the leaves of m k m k a binary tree are k=0 k=0 X X d ,...,d : n n +1 k m k n n +1 k m k 1 n 44. = ( 1) − , 45. (n m)! = ( 1) − , for n m, n m k +1 m − − m k +1 m − ≥ di k k 2− 1, X X ≤ n m n m + n m + k n m n m + n m + k i=1 46. = − , 47. = − , X n m m + k n + k k n m m + k n + k k − k − k and equality holds n ℓ +Xm k n k n n Xℓ + m k n k n only if every in- 48. = − , 49. = − . ℓ + m ℓ ℓ m k ℓ + m ℓ ℓ m k ternal node has 2 Xk Xk sons. Recurrences Master method: Generating functions: T (n)= aT (n/b)+ f(n), a 1,b> 1 1 T (n) 3T (n/2) = n 1. Multiply both sides of the equa- ≥ − 3 T (n/2) 3T (n/4) = n/2 tion by xi. If ǫ> 0 such that f(n)= O(nlogb a ǫ) − − 2. Sum both sides over all i for then∃ . which the equation is valid. T (n)=Θ(nlogb a). log n 1 3 2 − T (2) 3T (1) = 2 3. Choose a generating function logb a − i If f(n)=Θ(n ) then G(x). Usually G(x)= i∞=0 x gi. T (n)=Θ(nlogb a log n). Let m = log 2 n. Summing the left side 3. Rewrite the equation in terms of 2 m m P we get T (n) 3 T (1) = T (n) 3 = the generating function G(x). If ǫ> 0 such that f(n)=Ω(nlogb a+ǫ), T (n) nk where− k = log 3 −1.58496. ∃ − 2 ≈ 4. Solve for G(x). and c < 1 such that af(n/b) cf(n) Summing the right side we get i ∃ ≤ m 1 m 1 5. The coefficient of x in G(x) is gi. for large n, then − − n i 3 i Example: T (n)=Θ(f(n)). 3 = n . 2i 2 i=0 i=0 gi+1 =2gi +1, g0 =0. Substitution (example): Consider the X X 3 Multiply and sum: following recurrence Let c = 2 . Then we have i m 1 i i i 2 2 − m gi+1x = 2gix + x . Ti+1 =2 Ti , T1 =2. i c 1 · n c = n − i 0 i 0 i 0 c 1 X≥ X≥ X≥ Note that Ti is always a power of two. i=0 − X We choose G(x)= xig . Rewrite log2 n i 0 i Let ti = log2 Ti. Then we have =2n(c 1) ≥ i − in terms of G(x): ti+1 =2 +2ti, t1 =1. (k 1) logc n P =2n(c − 1) G(x) g0 i i − − =2G(x)+ x . Let ui = ti/2 . Dividing both sides of k x =2n 2n, i 0 the previous equation by 2i+1 we get − X≥ i k ti+1 2 ti and so T (n)=3n 2n. Full history re- Simplify: i+1 = i+1 + i . − G(x) 1 2 2 2 currences can often be changed to limited =2G(x)+ . x 1 x Substituting we find history ones (example): Consider i 1 − 1 1 − ui+1 = + ui, u1 = , Solve for G(x): 2 2 Ti =1+ Tj, T0 =1. x G(x)= . which is simply ui = i/2. So we find j=0 (1 x)(1 2x) − X i2i 1 − − that Ti has the closed form Ti =2 . Note that i Expand this using partial fractions: Summing factors (example): Consider 2 1 the following recurrence Ti+1 =1+ Tj. G(x)= x j=0 1 2x − 1 x T (n)=3T (n/2)+ n, T (1) = 1. X − − Subtracting we find i i i Rewrite so that all terms involving T i i 1 = x 2 2 x x − − are on the left side T T =1+ T 1 T i 0 i 0 i+1 − i j − − j X≥ X≥ T (n) 3T (n/2) = n. j=0 j=0 i+1 i+1 − X X = (2 1)x . − Now expand the recurrence, and choose = Ti. i 0 X≥ a factor which makes the left side “tele- And so T =2T =2i+1.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-