Professional Documents
Culture Documents
Definitions Series
f(n) = O(g(n)) iff q positive c, no such that n
0 _< f(n) _< cgCn) vn >_ no. i - - nCn2+ 1 ) ' ~ - ~ i ~ : nCn+l)(2n6 + I ) ~--~ 13 _ n~-(" + 1) ~-
i=i i=1 ' i=l 4
f(n) = f~(g(n)) iff 3 positive c, no such that
In general:
f(n) >_ co(m) >_ 0 Vn >_ no.
f(n) = O(g(n)) iff f(n) = O(g(n)) and Ei'~ rn+l (n+ -1- ((i + 11"~+' _ i,-+~ _ (-, + 1 ) i ' ) ]
fCn) = n(g(n)). i=1 =1
m
n--1 £( : )
/(n) = o(g(n)) iff lin~_.~ f(n)Ig(n) = O. i~t i,.,, _ 1 m 1 B~n,~+1_k.
"= m ~ l k=O
lim a . = a iff Ve 6 R, qn0 such that
Geometric series:
" - ' = I~- - "I < e, Vn >_ n0.
£ cn+l -- I £ I £ C
sup S least b 6 R such that b >_ s, c~ -- c--l"
c # 1, ci = 1 - c ' c'=
" 1-c' c<l,
Vs6S. /=O i=0 i=1
£(:) co+,~(
Hi = \ r n - b 1) Hr*+I
,)
-~- 1 "
sets of a size n set. i=1 i=l m
[~] Stifling numbers (lst kind):
Arrangements of an n ele- 1. (~) -
°'
(n -7=)~k~'
2.£(:):~, 3. (:): (n)
k=D D -- k
ment set into k cycles.
{ ~. } Stirling numbers (2nd kind): , (:)=~(::~),
Partitions of an n element
set into k non-empty sets. o.(:)(:):(:)(:-~), ,.~(,+~):(,÷o+1).
~ o
( ~> " 1st order Eulerian numbers:
Permutations 7r171"2_..71"r~On
{1, 2 , . . . , n} with k ascents. k=o \m + I) o. k£=(O ; ) ( o : ~ ) = ¢:I.
((~ >) 2nd order Eulerian numbers. II.
{o} {o}
1 = n =I.
C. Catlan Numbers: Binary
trees with n + 1 vertices. 12. 2 = 13. k = k k + k 1 :
32.
n--1 1
35.
£ <<:>> ~2o,~_ = 2" '
k=o
3°{. _-o} £ <<:>>(. +o_~)2o
1_
=
k=O
37. f n - I ' 1 1
k
n k 1)n_ k
k=o
52
Theoretical C o m p u t e r Science Cheat Sheet
Identities Cont. Trees
[n+l]__~ [;](k) £[k] ~__o~1 [k] Every tree with n
38. Lm + l J =
k=0
n '~-j: = n! ,
,,. [.: o] _-£k=o ((:)):-+
\ 2n ) vertices has n - 1
edges.
n k+l . i'" k,
40" {:}=~(k)(rn_l_a}l,- )- 41. [ : ] :~[;:~](k)(-l)m-~,
Kraft inequal-
ity: If the depths
42. {rn+n-I-l} =£k{n+k} of the leaves of
m k f----O ""
' rn . k=0 k ' a binary tree are
44. (:) = t,~{;::}[k](-l) "-k, 45. (n--m),(:) :~[;:l]{km}(-l) ""-t, forn>__m,
dl, - -., d.:
fx
E 2-a: <- 1,
46. { n 7rn}:~(:--;)(m-l-n'~[rn:
+ kn+k)
k] ' 4T. [nTrn]---- rE(:--;)(:::){
+
re+k}
k '
i=1
Recurrences
Master method: Generating functions:
•T(n)=aT(n/b)+f(n), a>_ l , b > 1 l ( T ( n ) - a T ( n / 2 ) = n) I. Multiply both sides of the equa-
3 ( T ( n / 2 ) - 3 T ( n / 4 ) = n/2) tion by z i.
If Be > 0 such that f ( n ) = O ( n logb a - , )
then 2. S u m both sides over all i for
T ( n ) = O(n l°gb"). which the equation is valid_
31og, n-I (T(2)- 3T(1)= 2) 3. Choose a generating function
If 1(n) = O(n ~°~ ~) then G(~). Usually c(z) = E = o ~'.
T(n) = O(n~°g' ° 1og~ n).
3log,n (T(1) - 0 = 1)
3. l ~ w r i t e the equation in terms of
If 3e > 0 such that f ( n ) = f](n l°gb a+,), Summing the left side we get T(n). Sum- the generating function G(~').
ming the right side we get 4. Solve for G(z).
and 3c < 1 such that af(n/b) <_ cf(n) log 2 n
for large n, then n i
5. The coefficient o f x i in G ( x ) is gi.
T ( n ) = ®(f(n)). E#-
i=O
Example:
gi+z = 2gi + l, go = 0 .
Substitution (example): Consider the
following recurrence
Let c = .=~and rn = loll
2~ n. Then we have Multiply and sum:
rn (C m+l -- i'~
T~+z=22'.T~, TI=2- Egi+Zz i = E2gixi + E Z i.
n~c~=n \ 7:T / i_>o i_>o :_>o
i=O
Note t h a t T/ is always a power of two.
Let ti = log 2 T/. T h e n we have
= 2n(c. cl°g=" - i) We choose G ( z ) = ~ i > 0 zi- Rewrite
ti+l = 2 i + 2ti, t I = i. = 2n(c-C kl°g=" -- I) in terms of G(z):
C(=) - go
Let u~ = t;/2 i. Dividing both sides of = 2 n ~ + I -- 2 n ~ 2 n 1'sg4ss - 2n, - 2G(=) + ~ ~'.
i>O
the previous equation by 2 I+1 we get where k = (log 2 ~)
a - I . Full history recur-
ti+t 2i ti Simplify:
rences can often be changed to limited his-
2i+1 -- 2i+-----
[ + 2i.
tory ones (example): Consider the follow-
G(z) 1
Z
-- 2 G ( z ) + 1 x
Substituting we find ing recurrence
Ui+I = 21- + U i , U1 = 12, i--1 Solve for G(z):
T,: 1 + ~ , To=I. z
which is simply u{ = i/2. So we find j=0 G(z) = (1 - z)(1 - 2.r)
that T / h a s the closed form T~ = 2 {2~-' .
Note that Expand this using partial fractions:
Summing factors (example): Consider i
the following recurrence T,+I= 1+ ~ T j .
Ti = 3T.12 + n, Tl = n. j=0
G(z)=z '1--2z 1-z
53
Theoretical Con, puter Science Cheat Sheet
i 2i Pi General Probability
1 2 2 Bernoulli Numbers (B~ = O, odd £ # 1): Continuous distributions: If
t b
2 4 B0 1, B 1 - - ~I, ~I , B 4 -__- - - ~ '16 ,
3 = = B2 = Pr[a < x < bl = L p(~) d~:
3 8 5 B5 ~, =
i Bs = --~-6,
i B , o - -- ~'~"
5
then p is the probability density function of
4 16 7 Change of base, quadratic formula:
X. If
5 32 ii log s z - b 4 - ~ / b 2 - - 4ac P d X < ,q = e(.),
logb z -- l o g s b ' 2a
6 64 13 then P is the distributionfunction of X. If
7 128 17 Euler's number e: P and p both exist then
8 256 19 e = 1 + ½ + ~ + 2-!~+ i-~uo+ ---
9 512 23 lira ( l + Z ) " ---- e =.
Expectation: If X is discrete
I0 1,024 29 (1 + .1-)" < e < (i + ~)"+1 -
II 2,048 31 E[g(X)] = E g ( z ) P r [ X = z].
e lle (n~)
12 4,096 37 ( 1 + ~)~ = e - - ~n + 2-~n2 - O - If X continuous then
13 8,192 41 Harmonic numbers:
.14 16,384 43 25 137 49 363 761 7129
i, 3 ' 12' 60 ' 20 I 1 4 0 ' 2SO' 2 5 2 0 1 "
15 32,768 47 Variance, standard deviation:
16 65,536 53 Inn < H , < I n n + 1, VAR[X] = E[X 2] - E[XI "~,
17 131,072 • 59
H . = Inn + 7 + O(1) .
18 262,144 61 Basics:
19 524,288 67 Factorial, Stirling's approximation: Pr[X v YI = Pr[X] + Pr[Y] - P r [ X A ]']
20 1,048,576 71 1, "
_ , 8, 24, 120, 720, 5040, 40320,3628SO, . . .
Pr[X A Y] = Pr[X] - P r ~ ' ] ,
21 2,097,152 73 iff X mad Y are independent.
22 4,194,304 79 n' : 2x/2"~-~n(-he) ~ (1 + 0 ( 1 ) ) . Pr[X A Y]
Pr[XIY] - Pr[B]
23 8,388,608 83 Ackerm~nn's function and inverse:
24 16,777,216 89 '2 j i= 1 E [ X - Y ] = e [ X ] - ELY],
25 33,554,432 97 a(i,j)= , aCi--1,2) j=l iff X and Y are independent.
26 67,108,864 I01
l a(i- l,a(i,j--1)) i,j>2 E[X + Y] = E[X] + E [ Y ] ,
27 134,217,728 103 ~(i) = min{j [ a(j, j) >_ i}. E[cX] = c E[X].
+
Poisson distribution: i:I i:l
Pascal's Triangle e-~Ak k
1 Pr[X=k]- ' E[XI=A.
k!
£ (-1)'+' E Pr [ A " Y ' ,
11 Normal (Gauesian) distribution: k=l i~<..-<ik ]=1
detA
Cid = E
k=l
a~,#.bk,i.
= 0 iff A is n o n - s i n g u l a r .
h a
A c B
det A - B = det A- det B,
n
Law of cosines:
B (0,-1)
det A = E I'l sign(r)a','(0"
c2 = a~'+b2--2abcosC
Pythagorean theorem: 7r i=1
C 2 = A 2 + B 2. 2 × 2 and 3 x 3 determinant: Area:
sseiden@ies.uci.edu g 2 g tanh iz
~- I 0 o0 tanx =
http://wee.ics.uci.edu/-sseiden 2 i
55
T h e o r e t i c a l C o m p u t e r Science Cheat S h e e t
Number Theory Graph Theory
The Chinese remainder theorem: There ex- Definitions: Notation:
ists a number C such that: Loop An edge connecting a ver- E(G) Edge set
tex to itself• V(G) Vertex set
C = rl mod ml e(G) Number of components
Directed Each edge has a direction.
Simple Graph with no loops or G[S] Induced subgraph
multi-edges. deg(v) Degree of v
C -- rn rood rnn A(G) M a x i m u m degree
Walk A sequence voel vl ezvt.
• • •
The reasonable m a n adapts himself to the 12. f s e c ~ d x = Inlsecx + tanzl, 13. / csc z dx = In I cscz + cot
world; the unreasonable persists in trying
to adapt the world to himself. Therefore 14. / arcsin ~dx = arcsin -~ + ~ - x2, a>O,
all progress depends on the unreasonable.
- George Bernard Shaw
57
Theoretical Computer Science Cheat Sheet
Calculus Cone
17. /sin2(az)dz = ~-:a(az- sin(az) cos(az)), 18. f cos2(az)dz---- -~:(az + sin(az) cos(a,)).
~0/.~..~=,~.-o- ,~ .-2/
"
n--1 +
rt--1
sec n-~zdz, n~l,
,,../~.o..~.: oo,.o.o.-,.
n -- 1 +
°-_,
-
n
-
lJ
/ cscn-2~:dz, n ~- 1 27.
/ sinhzdz = coshz, 28.
/ coshzdz = sinhz.
/ ~
{zarccosh
( )
a
za
z a x c c o s h - + ~ / z 2 + a 2, ifarccosh~ < 0 a n d a > O ,
39. ~4f~..~_.~=In
z + ~ , a>O,
40. / a~ dz
+ == -- ~I ~¢tan-~, a > O, 41. / ~/a= -- ~ a~ = -~/a= - ~" + :~= arcsin ~-, a ~> O.
46.
J ~ a 2 -4- z 2 d z = ~ ~ z 2 4- ~ I n z + ~
I I, 47.
/ ~
x/z2 _ a 2 -
'nl'+ ~~-~1 °>°
48. / ~ ~ : 11~
- In , 49. / zVr~'-+bz dz : 2(3bz - 2a)(a + b~) a/~-
az 2 + bz a 15 b-~ :
s4. ='~- ~, d= = -~(2-2 - , , ' ) ~ / a ' - ~' + ~ ,,csi~, -~, a > O. 55. 4 " ~ - ~' : - '
5 8
Theoretical C o m p u t e r Science C h e a t S h e e t
Calculus Cont. Finite Calculus
f dz 1 Difference, shift operators:
62. ZV/-~ __ a z ~ arccos ~ [ , a > 0, 63. z2%/~ a ~ -- ~ a2--------~-- ,
a f ( z ) ----f ( z -I- 1) -- f(m).
64. ~ zdz V/~z~+ a 2 , . f ~ (Z 2 -I- a2) -a/2 Z f(z) ----f ( z -I-i).
65. ~ dz=q: ~ ,
Fundamental Theorem:
In 2a2 + b - b~V"~"L-'~4ac
c- b2 fCz) = / ' F ( z ) ~ ~ J'Cz)6z = r ( z ) + C.
2az + b + ~ ' if >4at,
66. - b b-1
az 2 + bz + c 2 2as + b
axctaa ~ , if b 2 < 4ac, | a
~vq-~- b~
Differences:
dx = { -~a ln ]2az + b + 2 V ~ / a z ~ + b2 + c ' i f a > 0, ~(c,.O = ~ ' ~ , ~(~ + ~) = ± . + ~.,,,
67. A(uv) = u A v + E v A u ,
/ %lax~ Jr bz -I- c 1 . -2as - b
arcsln ~ i r a < 0, A(~"--) = n ~ -1,
x/-a %/b 2 - - 4ac
, x ( n ~ ) = ~-1 "x(2":) = 2".
68. / ~/az2 + bz + cdz - 2az + b~/az 2 4ax - ba / dz
4"------'~ Jr bz + c "l- -8; ~/az~ Jr bz Jr c' ACez) = (c - 1)e =, A(~) = (roSs)-
Sums:
z dz ~/az ~ + bz + c b f dz E CU~. = C E U ~ 2 ,
69. x/az 2 + bz + c = a 2a J "Vaz ~ + bz + c I
E ( u + v) 6~ = E u 6. + E ~ 6,.
dz ~-1 In 2v/EV'az~ + bz_z+ c + bz + 2c , uAv 6z = uv - ~_, E vAu 6z.
i f e > 0,
TO.
/ z ~ / a z 2 + bz + c 1 bz + 2c EZn6 z = z.+l
m+l,
E2~ -1 ~,Z = War.
ar~in i~l~Z=_~_~_
~ , i r e < 0,
e--l' E (z) 62 = (re+l)"
Falling Factorial Powers:
rl. /.s~ + a~ d. = (1~, _ A # ) ( . ~ + .~)s/L
• "-= z(z- 1)-.-(.- rn + 1). n>O.
z~ : z2 + z I ¢~ = z 2 -- z I
~= (-) ,
z~ = z s + 3Z 2 + 2 z I z~ = zs _ 3z 2 + 2z I li--I k
zT=
z~ =
z 4 + 6 z s + 11z 2 + 6z I
z s + l O z 4 + 3 5 z s + 50z ~ + 24z*
z!=
zE =
z 4 _ 6zs + I 1 2 2 - 6zI
z s _ 1024 + 35z s - 50z 2 + 24z z
z~ = ~ °[;] zk-
I:----1
59
Theoretical C o m p u t e r Science Cheat Sheet
Series
Ei=0
- i Z:2i Qgk = Oi--kZJ "
1 2 I 4 1 6 (-1) (~,,
C O S ~C =l-~z +T,z --~.,x +..- = i=O
i--=O " " "
= l -- l z + l z U -- ~-~z'l- t- . . . .
e~ - 1 i! ' i z',
i=O i=1
1 =£ 1 {2i'~ , A(z) + A(-z) £
~-~.(1-- qT- 4z) = l+z+2z 2+5z a+--- 2 ---- a2iz2i'
i=o
A(~) A(-~) = £
V ~ ' - 4z
= l+z+2zz+6za+...
=.: t , i ) " -
2
i=O
a21+lz2i+l"
= z + z 2 + 2z -~ + 3 z 4 + . . . .
- . . . .
i=2
.
Fiz i,
i J A(~)B(~)= ajbi_j ) ~'.
1-z-z 2
i=O God made the natural numbers:
all t h e r e s t is t h e w o r k o f m a n .
= F . z + F~..z ~-+ F ~ . z a + . . . . £ F . i ~ i. - Leopold Kronecker
1 - (F.-1 + F.+l)x - (-1)nz 2 i=D
6O
T h e o r e t i c a l C o m p u t e r Science C h e a t Sheet
Series Escher's Knot
Expansions:
)
1 1
In m m
(1 - z ) - + l I- z
(ln _1 - - ~ ) " :
"----
~-~, ~cot= = 5
i=0
r, .~. , ,
!
~ ( _ 1 ) ~ _ 122i(22i - 1)B2iz 2i-1 £ 1
tan -~ = (2i)[ , ((z) = i-~,
i=1 i=1
¢(=) = . , - __ ,
i=1 ~(Z) i=1
1
¢(=1 :IIl_p-., Stieltjes Integration
P
If G is continuous in the interval [a, b] and F is nondecreasing then
¢2(z ) = £ d(i). where dCn) = ~"]~dl,',1,
i=1
b G(z) dR(z)
exists. If a < b < c then
¢'(x)¢(x - 1) = £ S(i). where S(n) = E d l . d,
Zt
i=1 G(z) dF(z) = G(z) dF(z) + G(x) dF(x).
22"-11B2.1 r2.,
((2n) -- (2n)! n • 1~, If the integrals involved exist
b b b
2il2
'"
sin "T zi,
c- G(z) d F ( z ) G(z) d(c- F ( z ) ) = c G(z) dF(x).
e~ sin z =
b b
i=1
/ V ( z ) dF(:r) = G(b)F(b) - G(a)F(a) - / F ( z ) dV(z).
If the integrals involved exist, and F possesses a derivative F" at every
z ~=o 16iv/'2(2i)!( 2i + 1) !x'' point in [a, b] then
(arc~n x.] -~ =~-~ 4ii[2 . b b
61