Cheat Sheet

download Cheat Sheet

If you can't read please download the document

Embed Size (px)

description

 

Transcript of Cheat Sheet

  • 1. Theoretical Computer Science Cheat Sheet Denitions Series f (n) = O(g(n))i positive c, n0 such thatnnnn(n + 1) n(n + 1)(2n + 1) n2 (n + 1)20 f (n) cg(n) n n0 . i= ,i2 =,i3 = . i=1 2 i=16 i=1 4 f (n) = (g(n))i positive c, n0 such thatIn general:f (n) cg(n) 0 n n0 .n n1 f (n) = (g(n))i f (n) = O(g(n)) and im =(n + 1)m+1 1 (i + 1)m+1 im+1 (m + 1)imi=1 m+1i=1f (n) = (g(n)).n1 m1 m+1 f (n) = o(g(n))i limn f (n)/g(n) = 0.im = Bk nm+1k .i=1 m+1 kk=0 lim an = a i > 0, n0 such that nGeometric series:|an a| < , n n0 .n cn+1 11c sup Sleast b R such that b s, ci =, c = 1,ci =, ci = ,|c| < 1,c11c1cs S.i=0 i=0i=1 n ncn+2 (n + 1)cn+1 + ccinf S greatest b R such that b ici =,c = 1,ici = , |c| < 1.s, s S.i=0 (c 1)2i=0(1 c)2Harmonic series:lim inf anlim inf{ai | i n, i N}. nn nn 1n(n + 1)n(n 1) Hn = , iHi = Hn . lim sup an lim sup{ai | i n, i N}. i=1i i=12 4 nnn n n i n+11 kCombinations: Size k sub-Hi = (n + 1)Hn n, Hi =Hn+1 .sets of a size n set.i=1i=1 m m+1 m+1 n nStirling numbers (1st kind):n n! n nn kArrangements of an n ele- 1.=,2.= 2n ,3. = ,k (n k)!k! k k nkk=0ment set into k cycles.n n n1n n1 n1 n4.= , 5. = + , kStirling numbers (2nd kind):k k k1kkk1Partitions of an n elementnmn nk n r+k r+n+1set into k non-empty sets.6. =, 7. = ,mkk mk kn nk=01st order Eulerian numbers:nn kk n+1rsr+sPermutations 1 2 . . . n on8.= , 9. = ,m m+1k nkn{1, 2, . . . , n} with k ascents. k=0 k=0 nkn1 nn n2nd order Eulerian numbers. 10. = (1)k,11.= = 1, k kk 1nCnCatalan Numbers: Binary nn1 nn1trees with n + 1 vertices.12. = 2n1 1,, 13. =k +2k1 k kn n n nn 14.= (n 1)!, 15. = (n 1)!Hn1 , 16.= 1,17. ,1 2 n kknn n1 n1nnnn 1 2n 18.= (n 1) +, 19. = = , 20. = n!,21. Cn = ,kkk1 n1 n12k n+1 n k=0 n nnnn n1 n1 22. = = 1, 23.= ,24. = (k + 1)+ (n k) , 0 n1 k n1kk k k1 0 1 if k = 0, n nn+1 25. = 26. = 2n n 1, 27. = 3n (n + 1)2n +, k 0 otherwise 1 22 n mnn x+kn n+1 nn k 28. xn = , 29.= (m + 1 k)n (1)k ,30. m!= ,knmkm k nmk=0 k=0k=0n nn nk nn 31.= (1)nkm k!, 32. = 1, 33. = 0 for n = 0, mkm0nk=0n n n1n1 n(2n)n 34. = (k + 1) + (2n 1 k), 35. = , kk k1 k2nk=0nnxn x+n1kn+1nkk 36.=,37. == (m + 1)nk , xn k2nm+1kmmk=0 k k=0

2. Theoretical Computer Science Cheat Sheet Identities Cont. Trees nnn n+1n k k nk 1 k x n x+kEvery tree with n 38. == n = n! ,39.=,vertices has n 1 m+1k m m k! m xnk2nk k=0 k=0 k=0 edges. nn k+1 nn+1k 40.= (1)nk , 41. = (1)mk ,Kraftinequal- mk m+1 mk+1mkk ity: If the depthsmm m+n+1n+k m+n+1 n+kof the leaves of 42.= k ,43.=k(n + k) , m kmk a binary tree arek=0k=0 nn+1 kn n+1kd1 , . . . , dn : 44.= (1)mk , 45. (n m)!= (1)mk , for n m, n mk+1 mm k+1m 2di 1,k kn mn m+n m+kn mn m+nm+k i=1 46.= , 47. = , nmm+k n+kknmm+k n+k k and equality holdsk k n+m knk n n +m k nk n only if every in- 48.= , 49. =. ternal node has 2 +mmk +mmkkk sons. RecurrencesMaster method: Generating functions:T (n) = aT (n/b) + f (n), a 1, b > 11 T (n) 3T (n/2) = n 1. Multiply both sides of the equa-3 T (n/2) 3T (n/4) = n/2tion by xi .If > 0 such that f (n) = O(nlogb a ) ... 2. Sum both sides over all i forthen ... ...which the equation is valid.T (n) = (nlogb a ). 3log2 n1 T (2) 3T (1) = 23. Choose a generating function If f (n) = (nlogb a ) then G(x). Usually G(x) = i=0 xi gi . T (n) = (nlogb a log2 n). Let m = log2 n. Summing the left side3. Rewrite the equation in terms ofwe get T (n) 3m T (1) = T (n) 3m =the generating function G(x).If > 0 such that f (n) = (nlogb a+ ),T (n) nk where k = log2 3 1.58496. 4. Solve for G(x).and c < 1 such that af (n/b) cf (n)Summing the right side we getfor large n, thenm1m15. The coecient of xi in G(x) is gi . n i 3 i Example:T (n) = (f (n)). 3 =n 2 . i=0 2ii=0gi+1 = 2gi + 1, g0 = 0.Substitution (example): Consider thefollowing recurrenceLet c = 3 . Then we have2 Multiply and sum: i Ti+1 = 22 Ti2 , T1 = 2.m1c 1m gi+1 xi =2gi xi + xi . in c =ni0 i0i0 c1Note that Ti is always a power of two.i=0 We choose G(x) = i0 xi gi . RewriteLet ti = log2 Ti . Then we have= 2n(clog2 n 1) in terms of G(x):ti+1 = 2i + 2ti , t1 = 1. = 2n(c(k1) logc n 1)G(x) g0= 2G(x) + xi .Let ui = ti /2i . Dividing both sides of = 2nk 2n,xi0the previous equation by 2i+1 we get ti+12iti and so T (n) = 3n 2n. Full history re- k Simplify: = i+1 + i .G(x)12 i+12 2currences can often be changed to limited= 2G(x) + .history ones (example): Consider x 1xSubstituting we nd i1ui+1 = 1 + ui ,2 u1 = 1 ,2 Solve for G(x):Ti = 1 +Tj , T0 = 1. xG(x) =.which is simply ui = i/2. So we nd j=0(1 x)(1 2x)i1that Ti has the closed form Ti = 2i2 .Note that i Expand this using partial fractions:Summing factors (example): Consider 21the following recurrenceTi+1 = 1 +Tj . G(x) = x 1 2x 1 x T (n) = 3T (n/2) + n, T (1) = 1. j=0 Subtracting we ndRewrite so that all terms involving T i i1= x 2 2i xi xi are on the left side Ti+1 Ti = 1 +Tj 1 Tji0 i0 T (n) 3T (n/2) = n. j=0j=0 =i+1 (2 1)xi+1 .Now expand the recurrence, and choose = Ti . i0a factor which makes the left side tele-scopeAnd so Ti+1 = 2Ti = 2i+1 . So gi = 2i 1. 3. Theoretical Computer Science Cheat Sheet 1+ 5 1 5 3.14159,e 2.71828, 0.57721,= 2 1.61803, =2 .61803i 2ipi GeneralProbability 1 2 2Bernoulli Numbers (Bi = 0, odd i = 1):Continuous distributions: If 1 11b 2 4 3 B0 = 1, B1 = B2 =2,B4 = 6, 30 ,Pr[a < X < b] = p(x) dx, 115 385 B6 = 42 , B8 = 30 , B10 = 66 .a4 167Change of base, quadratic formula:then p is the probability density function of X. If 5 3211 loga xb b2 4acPr[X < a] = P (a), logb x =,. 6 6413 loga b2athen P is the distribution function of X. If 712817 Eulers number e: P and p both exist then11 11 825619e=1+ 2 + 24 + 120 + + 6 ax n P (a) =p(x) dx. 951223lim 1 += ex . nnExpectation: If X is discrete10 1,024 29 1 n 1 n+11+ n b are in- each vertex exactly once. y = mx + b (m, 1, b) tegers thenCutA set of edges whose re-x=c (1, 0, c) gcd(a, b) = gcd(a mod b, b).moval increases the num-Distance formula, Lp and Ln If i=1 pei is the prime factorization of xber of components.metric: i then Cut-setA minimal cut. (x1 x0 )2 + (y1 y0 )2 , pi i +1 1n e Cut edge A size 1 cut.1/pS(x) = d=.k-ConnectedA graph connected with|x1 x0 |p + |y1 y0 |p, pi 1 d|x i=1 the removal of any k 1 lim |x1 x0 |p + |y1 y0 | p 1/p. Perfect Numbers: x is an even perfect num-vertices.pber i x = 2n1 (2n 1) and 2n 1 is prime.k-ToughS V, S = we have Area of triangle (x0 , y0 ), (x1 , y1 ) Wilsons theorem: n is a prime i k c(G S) |S|. and (x2 , y2 ):(n 1)! 1 mod n.k-RegularA graph where all vertices 1x1 x0 y1 y02 abs x x. have degree k.2 0 y2 y0 Mbius o inversion: k-Factor A k-regular spanning 1 if i = 1.Angle formed by three points: subgraph. 0if i is not square-free.(i) =Matching A set of edges, no two of (1)r if i is the product of(x2 , y2 )r distinct primes. which are adjacent. 2Clique A set of vertices, all of If which are adjacent. G(a) =F (d), (0, 0) 1(x1 , y1 )Ind. set A set of vertices, none of d|a which are adjacent. (x1 , y1 ) (x2 , y2 )cos =. then Vertex cover A set of vertices which 1 2aF (a) =(d)G.cover all edges.Line through two points (x0 , y0 )d d|aPlanar graph A graph which can be em-and (x1 , y1 ): Prime numbers:beded in the plane. x y 1 ln ln nPlane graphAn embedding of a planar x0 y0 1 = 0. pn = n ln n + n ln ln n n + nln n graph. x1 y1 1nArea of circle, volume of sphere:+O, deg(v) = 2m. ln n A = r2 , V = 4 r3 .vV 3 n n 2!n(n) = ++ If G is planar then n m + f = 2, soln n (ln n)2 (ln n)3 If I have seen farther than others,f 2n 4, m 3n 6.it is because I have stood on then+O. Any planar graph has a vertex with de- shoulders of giants. (ln n)4gree 5. Issac Newton 6. Theoretical Computer Science Cheat Sheet Calculus Wallis identity: Derivatives: 2 2 4 4 6 6 =2 d(cu) dud(u + v) du dvd(uv)dv du 1 3 3 5 5 71.=c ,2. =+, 3. =u+v ,dx dx dxdx dx dxdx dx Brounckers continued fraction expansion: 12d(un )dud(u/v)v du udv d(ecu ) du 4. = nun1 , 5.=dxdx, 6. = cecu , 4 =1+32dx dxdx v2 dxdx 2+ 522+ 2+72d(cu ) du d(ln u) 1 du2+ 7. = (ln c)cu ,8. =,dxdx dxu dx Gregrorys series: 1 1 1 1 4 =1 3 + + d(sin u)dud(cos u)du 5 7 9 9. = cos u , 10. = sin u , dxdx dx dx Newtons series:d(tan u) du d(cot u) du111311. = sec2 u , 12.= csc2 u , dxdxdxdx 6 = 2 + 2 3 23 + 2 4 5 25 + d(sec u)dud(csc u)du Sharps series: 13. = tan u sec u , 14. = cot u csc u , dx dxdxdx1111 d(arcsin u)1 dud(arccos u)1 du = 1 1+ 2 3 + 15. =,16. =, 6 3 3 3 5 3 7dx1u2 dxdx1 u2 dx 3 Eulers series: d(arctan u)1 dud(arccot u) 1 du 17. = ,18. = , dx1 + u2 dxdx1 + u2 dx2 111 11 6 = 12 + 22 + 32 +42 + 52 + d(arcsec u) 1dud(arccsc u)1du2 111 11 19. = ,20. = , u 1u2 dxu 1u2 dx 8 = 12 + 32 + 52 +72 + 92 + dx dx2 111 11d(sinh u) du d(cosh u)du12 = 12 22 + 32 42 + 52 21. = cosh u ,22.= sinh u ,dx dx dx dxPartial Fractions d(tanh u)dud(coth u)du 23.= sech2 u , 24.= csch2 u , Let N (x) and D(x) be polynomial func-dxdx dxdx tions of x.We can break down d(sech u)du d(csch u)du N (x)/D(x) using partial fraction expan-25.= sech u tanh u ,26.= csch u coth u , dxdxdxdx sion. First, if the degree of N is greater than or equal to the degree of D, divided(arcsinh u)1 du d(arccosh u)1 du 27.=, 28.=,dx1+u2 dxdx u 2 1 dx N by D, obtainingN (x) N (x)d(arctanh u)1 du d(arccoth u)1 du= Q(x) +,29.= , 30.= 2 ,D(x)D(x)dx1 u2 dxdx u 1 dx where the degree of N is less than that of d(arcsech u) 1dud(arccsch u) 1 du 31. = , 32. =. D. Second, factor D(x). Use the follow-dxu 1 u2 dx dx|u| 1 + u2 dx ing rules: For a non-repeated factor: Integrals:N (x) AN (x)= +,(x a)D(x) xa D(x) 1.cu dx = cu dx,2.(u + v) dx = u dx +v dx, where N (x)1 1A=.3.xn dx = xn+1 ,n = 1,4.dx = ln x, 5. ex dx = ex , D(x) x=a n+1x For a repeated factor:dx dv du 6. = arctan x, 7.udx = uv vdx, N (x)m1AkN (x)1 + x2 dx dx= + , (x a)m D(x)(x a)mk D(x)8.sin x dx = cos x, 9.cos x dx = sin x, k=0where1 dkN (x)10.tan x dx = ln | cos x|, 11. cot x dx = ln | cos x|, Ak = .k! dxkD(x)x=a12.sec x dx = ln | sec x + tan x|, 13. csc x dx = ln | csc x + cot x|, The reasonable man adapts himself to the world; the unreasonable persists in trying to adapt the world to himself. Therefore14.arcsin x dx = arcsin x + a aa2 x2 ,a > 0, all progress depends on the unreasonable. George Bernard Shaw 7. Theoretical Computer Science Cheat Sheet Calculus Cont.15. arccos x dx = arccos x a a a2 x2 ,a > 0, 16. arctan x dx = x arctan x a aa2 ln(a2 + x2 ),a > 0,17. sin2 (ax)dx =1 2a ax sin(ax) cos(ax) ,18.cos2 (ax)dx = 12aax + sin(ax) cos(ax) ,19. sec2 x dx = tan x, 20. csc2 x dx = cot x, sinn1 x cos x n 1cosn1 x sin x n 1 21. sinn x dx = + sinn2 x dx,22. cosn x dx = + cosn2 x dx,nn n n tann1 x cotn1 x 23. tann x dx = tann2 x dx, n = 1, 24.cotn x dx = cotn2 x dx, n = 1, n1 n1 tan x secn1 x n 2 25. secn x dx = + secn2 x dx, n = 1, n1 n1cot x cscn1 x n 2 26. cscn x dx = + cscn2 x dx, n = 1, 27. sinh x dx = cosh x,28.cosh x dx = sinh x,n1 n129. tanh x dx = ln | cosh x|, 30. coth x dx = ln | sinh x|, 31.sech x dx = arctan sinh x, 32. csch x dx = ln tanh x , 2 33. sinh2 x dx =1 4 sinh(2x) 1 x,2 34. cosh2 x dx =14 sinh(2x) + 1 x, 235.sech2 x dx = tanh x,36. arcsinh x dx = x arcsinh x aax2 + a2 ,a > 0,37. arctanh x dx = x arctanh x +aaa2 ln |a2 x2 |,x x arccosh x2 + a2 , if arccosh x > 0 and a > 0, a 38. x arccosh a dx =a x x arccosh + x2 + a2 , if arccosh x < 0 and a > 0, a adx 39. = ln x + a2 + x2 , a > 0, a2 + x2dx 1 a2 40. = a arctan x , a > 0,41. a2 x2 dx = x 2a2 x2 +2arcsin x , a > 0, a2 + x2 a a 3a4 42. (a2 x2 )3/2 dx = x (5a2 2x2 ) a2 x2 +8 8arcsin x ,a a > 0, dx dx1a+x dxx 43. = arcsin x ,a > 0,44. =ln , 45.= , a2 x2aa2 x 2 2aax (a2 x2 )3/2a2 a2 x2a2 dx 46. a2 x2 dx = x2 a2 x2 2ln x +a2 x2 , 47. = ln x + x2 a2 , a > 0,x2 a2 dx 1 x2(3bx 2a)(a + bx)3/2 48. = ln ,49.x a + bx dx = , ax2 + bxa a + bx 15b2 a + bx 1 x 1 a + bx a 50.dx = 2 a + bx + a dx,51.dx = ln , a > 0, xx a + bx a + bx 2a + bx + a a2 x2 a + a2 x2 52. dx = a2 x2 a ln ,53. x a2 x2 dx = 1 (a2 x2 )3/2 , 3 x x 222a4dx1a+ a2 x2 54. x a2 x2 dx =x 8 (2xa )a2 x2 + 8arcsin xa, a > 0, 55. = a ln,a2 x2 xx dx x2 dx2 56. = a2 x2 ,57. = x a2 x2 + a arcsin a, 2 2x a > 0, a2 x2 a2 x2 a2 + x2 2 + x2 a ln a + a2 + x2x2 a2 58. dx = a,59.dx = x2 a2 a arccos |x| ,a a > 0, xxx dx x 60. xx2 a2 dx = 1 (x2 a2 )3/2 , 361.= 1ln ,x x2 + a2 a a+ a2 + x2 8. Theoretical Computer Science Cheat SheetCalculus Cont. Finite Calculus dx 1 dxx2 a2 Dierence, shift operators: 62. a= a arccos |x| , a > 0,63.=,x x2 a2 x2 x2 a2 a2 xf (x) = f (x + 1) f (x), x dx x2 a2 (x2 + a2 )3/2 E f (x) = f (x + 1). 64.= x2 a2 ,65.dx = ,x2 a2 x4 3a2 x3 Fundamental Theorem: 12ax + b b2 4ac f (x) = F (x) f (x)x = F (x) + C. ln , if b2 > 4ac,dxb2 4ac 2ax + b + b2 4ac 66. = b b1ax2 + bx + c f (x)x = f (i). 2 arctan 2ax + b,if b2 < 4ac,a4ac b2 4ac b2i=aDierences: ln 2ax + b + 2a ax2 + bx + c , if a > 0, 1(cu) = cu, (u + v) = u + v, dx a 67. = (uv) = uv + E vu,ax2 + bx + c 1 arcsin 2ax b ,if a < 0,(xn ) = nxn1 ,a b2 4ac(Hx ) = x1 ,(2x ) = 2x , 2ax + b 4ax b2 dx 68. ax2 + bx + c dx =ax2 + bx + c + ,(cx ) = (c 1)cx , x=x. 4a 8aax2 + bx + c mm1Sums: x dxax2 + bx + cbdx cu x = c u x, 69.= ,ax2 + bx + c a2aax2 + bx + c(u + v) x =u x +v x, 2 1 ln 2 c ax + bx + c + bx + 2c ,uv x = uv E vu x, c if c > 0, dxx n+1 70. = xn x = xx1 x = Hx ,2 + bx + c 1 m+1 ,x ax arcsin + 2c ,bx if c < 0,cx x xc |x| b2 4accx x = c1 , m x = m+1 .Falling Factorial Powers: 71.x3 x2 + a2 dx = ( 1 x2 32 2 15 a )(x 2+ a2 )3/2 , xn = x(x 1) (x n + 1), n > 0, 1 x0 = 1, 72.xn sin(ax) dx = a xn cos(ax) +na xn1 cos(ax) dx,1 xn =,n < 0, (x + 1) (x + |n|) 1 n 73. nx cos(ax) dx = axsin(ax) nx n1sin(ax) dx,a xn+m = xm (x m)n .xn eaxRising Factorial Powers: 74.xn eax dx = n xn1 eax dx,aa xn = x(x + 1) (x + n 1), n > 0,75.xn ln(ax) dx = xn+1 ln(ax) 1 , x0 = 1,n+1 (n + 1)21 xn =,n < 0, xn+1 m (x 1) (x |n|) 76.xn (ln ax)m dx = (ln ax)m xn (ln ax)m1 dx. n+1n+1 xn+m = xm (x + m)n .Conversion: x1 =x1 =x1 xn = (1)n (x)n = (x n + 1)n x2 = x2 + x1 = x2 x1= 1/(x + 1)n , x3 =x3 + 3x2 + x1=x3 3x2 + x1xn = (1)n (x)n = (x + n 1)n x4 = x + 6x3 + 7x2 + x1 4= x 6x3 + 7x2 x1 4 = 1/(x 1)n , x5 = x5 + 15x4 + 25x3 + 10x2 + x1= x5 15x4 + 25x3 10x2 + x1 nn k n nxn =x =(1)nk xk ,kk x1 = x1x1 =x1 k=1 k=1n x2 = x + x1 2x2 =x x1 2xn = n (1)nk xk ,3 32 13 321k x = x + 3x + 2xx =x 3x + 2x k=1 x4 =x + 6x3 + 11x2 + 6x14x4 = x 6x3 + 11x2 6x14 n n k5543 21 55432 1 xn = x . x =x + 10x + 35x + 50x + 24x x = x 10x + 35x 50x + 24xk k=1 9. Theoretical Computer Science Cheat Sheet Series Taylors series: Ordinary power series:(x a)2 (x a)i (i) f (x) = f (a) + (x a)f (a) +f (a) + = f (a). A(x) =ai xi . 2 i=0i!i=0 Expansions: Exponential power series: 1 = 1 + x + x2 + x3 + x4 + =xi , xi1xi=0A(x) =ai.i! 1i=0= 1 + cx + c2 x2 + c3 x3 + = ci xi ,1 cxi=0Dirichlet power series: 1 ai=1+x +x n 2n+x 3n + = nix , A(x) = . 1 xn i=1ixi=0 Binomial theorem:x= x + 2x2 + 3x3 + 4x4 + = ixi , nn nk k (1 x)2 i=0(x + y)n = xy . k dn1k=0 xk = x + 2n x2 + 3n x3 + 4n x4 +...