Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
csformulae

csformulae

Ratings: (0)|Views: 0|Likes:
Published by api-26368914

More info:

Published by: api-26368914 on Nov 28, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Theoretical Computer Science Cheat Sheet
De\ufb01nitions
Series
f(n) = O(g(n))
i\ufb00\u2203 positivec, n0 such that
0\u2264f (n)\u2264cg(n)\u2200n \u2265n0.
n
\ue01d
i=1
i=n(n+ 1)
2
,
n
\ue01d
i=1
i2=n(n+ 1)(2n+ 1)
6
,
n
\ue01d
i=1
i3=n2( n+ 1)2
4
.
In general:
n
\ue01d
i=1
im=1
m+1
\ue00d
(n + 1)m+1\u22121 \u2212n
\ue01d
i=1
\ue000
(i + 1)m+1\u2212im+1\u2212 (m + 1)im
\ue001\ue00e
n\u22121
\ue01d
i=1
im=1
m+1
m
\ue01d
k=0
\ue00b
m+1
k
\ue00c
Bknm+1\u2212k .
Geometric series:
n
\ue01d
i=0
ci=cn+1\u22121
c\u22121, c\ue002= 1 ,
\u221e
\ue01d
i=0
ci=1
1\u2212c,
\u221e
\ue01d
i=1
ci=c
1\u2212c,|c| <1,
n
\ue01d
i=0
ici=ncn+2\u2212(n+ 1)cn+1+ c
(c\u2212 1)2
, c\ue002= 1 ,
\u221e
\ue01d
i=0
ici=
c
(1\u2212c)2,|c| <1.
Harmonic series:
Hn=
n
\ue01d
i=1
1i,
n
\ue01d
i=1
iHi=n(n+ 1)
2
Hn\u2212n(n\u22121)
4
.
n
\ue01d
i=1
Hi= (n+ 1)Hn\u2212 n,
n
\ue01d
i=1
\ue00b
i
m
\ue00c
Hi=
\ue00b
n+1
m+1\ue00c
\ue00b
Hn+1\u22121
m+1
\ue00c
.
f(n) = \u2126(g(n))
i\ufb00\u2203 positivec, n0 such that
f(n)\u2265 cg(n)\u2265 0\u2200n\u2265 n0.
f(n) = \u0398(g(n))
i\ufb00f(n) =O(g(n)) and
f(n) = \u2126(g(n)).
f(n) = o(g(n))
i\ufb00 limn\u2192\u221ef (n)/g(n) = 0.
lim
n\u2192\u221ean= a
i\ufb00\u2200\ue000 > 0,\u2203n0 such that
|an\u2212a|< \ue000, \u2200n \u2265n0.
supS
leastb\u2208R such thatb\u2265 s,
\u2200s \u2208S.
infS
greatestb\u2208R such thatb\u2264
s,\u2200s\u2208 S.
lim inf
n\u2192\u221ean
lim
n\u2192\u221einf{ai |i \u2265n, i \u2208N}.
lim sup
n\u2192\u221ean
lim
n\u2192\u221esup{ai |i \u2265n, i \u2208N}.
\ue000
nk
\ue001
Combinations: Sizek sub-
sets of a sizen set.
\ue002
nk
\ue003

Stirling numbers (1st kind): Arrangements of ann ele- ment set intok cycles.

1.
\ue00b
nk
\ue00c
=
n!
(n\u2212 k)!k!,
2.
n
\ue01d
k=0
\ue00b
nk
\ue00c
= 2n,
3.
\ue00b
nk
\ue00c
=
\ue00b
n
n\u2212 k
\ue00c,
4.
\ue00b
nk
\ue00c
=nk
\ue00b
n\u22121
k\u22121
\ue00c
,
5.
\ue00b
nk
\ue00c
=
\ue00b
n\u22121
k
\ue00c
+
\ue00b
n\u22121
k\u22121
\ue00c,
6.
\ue00b
n
m
\ue00c\ue00b
mk
\ue00c
=
\ue00b
nk
\ue00c\ue00b
n\u2212 k
m\u2212 k
\ue00c
,
7.
n
\ue01d
k=0
\ue00b
r+ k
k
\ue00c
=
\ue00b
r+ n+1
n
\ue00c,
8.
n
\ue01d
k=0
\ue00b
k
m
\ue00c
=
\ue00b
n+1
m+1\ue00c
,
9.
n
\ue01d
k=0
\ue00b
r
k
\ue00c\ue00b
s
n\u2212 k
\ue00c
=
\ue00b
r+ s
n
\ue00c,
10.
\ue00b
nk
\ue00c
= (\u22121)k
\ue00b
k\u2212 n\u22121
k
\ue00c
,
11.
\ue00f
n1
\ue010
=
\ue00f
nn
\ue010
= 1,
12.
\ue00f
n2
\ue010
= 2n\u22121\u22121,
13.
\ue00f
nk
\ue010
=k
\ue00f
n\u22121
k
\ue010
+
\ue00f
n\u22121
k\u22121
\ue010,
\ue004
nk
\ue005

Stirling numbers (2nd kind): Partitions of ann element set intok non-empty sets.

\ue006
nk
\ue007
1st order Eulerian numbers:
Permutations\u03c01\u03c02...\u03c0non
{1, 2,...,n}withk ascents.
\ue006
\ue006
nk
\ue007
\ue007
2nd order Eulerian numbers.
Cn
Catalan Numbers: Binary
trees withn + 1 vertices.
14.
\ue00d
n1
\ue00e
= (n\u2212 1)!,
15.
\ue00d
n2
\ue00e
= (n\u2212 1)!Hn\u22121,
16.
\ue00d
nn
\ue00e
= 1,
17.
\ue00d
nk
\ue00e
\u2265
\ue00f
nk
\ue010
,
18.
\ue00d
nk
\ue00e
= (n\u2212 1)\ue00d
n\u22121
k
\ue00e
+
\ue00d
n\u22121
k\u22121
\ue00e
,
19.
\ue00f
n
n\u22121
\ue010
=
\ue00d
n
n\u22121
\ue00e
=
\ue00b
n2
\ue00c,
20.
n
\ue01d
k=0
\ue00d
nk
\ue00e
=n!,
21.Cn=1
n+1
\ue00b
2n
n
\ue00c
,
22.
\ue011
n0
\ue012
=
\ue011
n
n\u22121
\ue012
= 1,
23.
\ue011
nk
\ue012
=
\ue011
n
n\u22121 \u2212 k
\ue012,
24.
\ue011
nk
\ue012
= (k + 1)\ue011
n\u22121
k
\ue012
+ (n\u2212 k)\ue011
n\u22121
k\u22121
\ue012
,
25.
\ue011
0
k
\ue012
=
\ue024
1 ifk=0,
0 otherwise
26.
\ue011
n1
\ue012
= 2n\u2212n \u22121,
27.
\ue011
n2
\ue012
= 3n\u2212 (n + 1)2n +
\ue00b
n+1
2
\ue00c
,
28.xn=
n
\ue01d
k=0
\ue011
nk
\ue012\ue00b
x+ k
n
\ue00c
,
29.
\ue011
n
m
\ue012
=
m
\ue01d
k=0
\ue00b
n+1
k
\ue00c
(m + 1\u2212k)n(\u22121)k,
30.m!\ue00f
n
m
\ue010
=
n
\ue01d
k=0
\ue011
nk
\ue012\ue00b
k
n\u2212 m\ue00c
,
31.
\ue011
n
m
\ue012
=
n
\ue01d
k=0
\ue00f
nk
\ue010\ue00bn\u2212 k
m
\ue00c
(\u22121)n\u2212k\u2212mk!,
32.
\ue011
\ue011
n0
\ue012
\ue012
= 1,
33.
\ue011
\ue011
nn
\ue012
\ue012
= 0 forn\ue002= 0,
34.
\ue011
\ue011
nk
\ue012
\ue012
= (k + 1)\ue011
\ue011
n\u22121
k
\ue012
\ue012
+ (2n\u2212 1\u2212k)\ue011
\ue011
n\u22121
k\u22121
\ue012
\ue012,
35.
n
\ue01d
k=0
\ue011
\ue011
nk
\ue012
\ue012
=(2n)n
2n,
36.
\ue00f
x
x\u2212 n
\ue010
=
n
\ue01d
k=0
\ue011
\ue011
nk
\ue012
\ue012\ue00bx+ n\u22121 \u2212 k
2n
\ue00c,
37.
\ue00f
n+1
m+1
\ue010
=
\ue01d
k
\ue00b
nk
\ue00c\ue00f
k
m
\ue010
=
n
\ue01d
k=0
\ue00f
k
m
\ue010
(m + 1)n\u2212k,
Theoretical Computer Science Cheat Sheet
Identities Cont.
Trees
38.
\ue00d
n+1
m+1
\ue00e
=
\ue01d
k
\ue00d
nk
\ue00e\ue00b
k
m
\ue00c
=
n
\ue01d
k=0
\ue00d
k
m
\ue00e
nn\u2212k=n!
n
\ue01d
k=0
1
k!
\ue00d
k
m
\ue00e
,
39.
\ue00d
x
x\u2212 n
\ue00e
=
n
\ue01d
k=0
\ue011
\ue011
nk
\ue012
\ue012\ue00bx+ k
2n
\ue00c
,
40.
\ue00f
n
m
\ue010
=
\ue01d
k
\ue00b
nk
\ue00c\ue00f
k+1
m+1
\ue010(\u22121)n\u2212k,
41.
\ue00d
n
m
\ue00e
=
\ue01d
k
\ue00d
n+1
k+1
\ue00e\ue00b
k
m
\ue00c
(\u22121)m\u2212k,
42.
\ue00f
m+ n+1
m
\ue010
=
m
\ue01d
k=0
k
\ue00f
n+ k
k
\ue010,
43.
\ue00d
m+ n+1
m
\ue00e
=
m
\ue01d
k=0
k(n+ k)\ue00d
n+ k
k
\ue00e
,
44.
\ue00b
n
m
\ue00c
=
\ue01d
k
\ue00f
n+1
k+1
\ue010\ue00d
k
m
\ue00e
(\u22121)m\u2212k,45.(n\u2212 m)!\ue00b
n
m
\ue00c
=
\ue01d
k
\ue00d
n+1
k+1
\ue00e\ue00f
k
m
\ue010(\u22121)m\u2212k,for n\u2265 m,
46.
\ue00f
n
n\u2212 m
\ue010
=
\ue01d
k
\ue00b
m\u2212 n
m+ k
\ue00c\ue00b
m+ n
n+ k
\ue00c\ue00d
m+ k
k
\ue00e
,
47.
\ue00d
n
n\u2212 m
\ue00e
=
\ue01d
k
\ue00b
m\u2212 n
m+ k
\ue00c\ue00b
m+ n
n+ k
\ue00c\ue00f
m+ k
k
\ue010,
48.
\ue00f
n
\ue001+ m
\ue010\ue00b
\ue001+ m
\ue001
\ue00c
=
\ue01d
k
\ue00f
k\ue001
\ue010\ue00f
n\u2212 k
m
\ue010\ue00b
nk
\ue00c,
49.
\ue00d
n
\ue001+ m
\ue00e\ue00b\ue001+ m
\ue001
\ue00c
=
\ue01d
k
\ue00d
k\ue001
\ue00e\ue00d
n\u2212 k
m
\ue00e\ue00bnk
\ue00c
.

Every tree withn vertices hasn\u2212 1 edges.

Kraft

inequal- ity: If the depths of the leaves of a binary tree are

d1,...,dn:
n
\ue01d
i=1
2\u2212di\u2264 1,

and equality holds only if every in- ternal node has 2 sons.

Recurrences
Master method:
T(n) =aT(n/b)+f(n), a\u22651,b>1
If\u2203\ue000 > 0 such thatf (n) =O(nlogba\u2212\ue000)
then
T(n) = \u0398(nlogba).
Iff (n) = \u0398(nlogba) then
T(n) = \u0398(nlogbalog2n).

If\u2203\ue000 > 0 such thatf (n) = \u2126(nlogba+\ue000), and\u2203c < 1 such thataf (n/b)\u2264cf (n) for largen, then

T(n) = \u0398(f(n)).
Substitution (example): Consider the
following recurrence
Ti+1= 22i\u00b7T 2
i, T1= 2 .
Note thatTiis always a power of two.
Letti= log2Ti. Then we have
ti+1= 2i +2ti, t1= 1 .
Letui=ti/2i. Dividing both sides of
the previous equation by 2i+1we get
ti+1
2i+1=2i
2i+1+ti
2i.
Substituting we \ufb01nd
ui+1=12 +ui,
u1=12 ,
which is simplyui=i/2. So we \ufb01nd
thatTihas the closed formTi= 2i2i\u22121
.
Summing factors (example): Consider
the following recurrence
T(n) = 3T(n/2) +n, T(1) = 1.
Rewrite so that all terms involvingT
are on the left side
T(n)\u2212 3T(n/2) = n.

Now expand the recurrence, and choose a factor which makes the left side \u201ctele- scope\u201d

1\ue000
T(n)\u2212 3T(n/2) = n\ue001
3\ue000
T(n/2)\u2212 3T(n/4) = n/2\ue001
...
...
...
3log2n\u22121
\ue000
T(2)\u2212 3T(1) = 2\ue001
Letm = log2n. Summing the left side
we getT (n)\u2212 3mT(1) = T(n)\u2212 3m=
T(n)\u2212 nkwherek = log2 3\u2248 1.58496.
Summing the right side we get
m\u22121
\ue01d
i=0
n
2i3i =n
m\u22121
\ue01d
i=0
\ue000
32
\ue001i.
Letc =32. Then we have
n
m\u22121
\ue01d
i=0
ci= n
\ue00b
cm\u22121
c\u22121
\ue00c
= 2n(clog2n\u22121)
= 2n(c(k\u22121) logcn\u22121)
= 2nk\u22122n,

and soT (n) = 3nk\u22122n. Full history re- currences can often be changed to limited history ones (example): Consider

Ti= 1+
i\u22121
\ue01d
j=0
Tj , T0= 1 .
Note that
Ti+1= 1+
i
\ue01d
j=0
Tj .
Subtracting we \ufb01nd
Ti+1\u2212Ti= 1+
i
\ue01d
j=0
Tj\u22121 \u2212i\u22121
\ue01d
j=0
Tj
=Ti.
And soTi+1= 2Ti= 2i+1 .
Generating functions:
1. Multiply both sides of the equa-
tion byxi.
2. Sum both sides over alli for
which the equation is valid.
3. Choose a generating function
G(x). Usually G(x) =
\ue01b\u221ei=0xigi.
3. Rewrite the equation in terms of
the generating functionG(x).
4. Solve forG(x).
5. The coe\ufb03cient ofxiinG(x) isgi.
Example:
gi+1= 2gi+1, g0 = 0.
Multiply and sum:
\ue01d
i\u22650
gi+1xi=
\ue01d
i\u22650
2gixi +
\ue01d
i\u22650
xi.
We chooseG(x) =
\ue01b
i\u22650xigi. Rewrite
in terms ofG(x):
G(x)\u2212 g0
x
= 2G (x )+
\ue01d
i\u22650
xi.
Simplify:
G(x)
x= 2G(x) +1
1\u2212x.
Solve forG(x):
G(x) =
x
(1\u2212x)(1\u2212 2x).
Expand this using partial fractions:
G(x) = x
\ue00b
2
1\u2212 2x\u22121
1\u2212x
\ue00c
=x
\ue013
\ue0192
\ue01d
i\u22650
2ixi\u2212
\ue01d
i\u22650
xi
\ue014
\ue01a
=
\ue01d
i\u22650
(2i+1\u2212 1)xi+1.
Sogi= 2i\u2212 1.
Theoretical Computer Science Cheat Sheet
\u03c0\u22483.14159,
e\u22482.71828,
\u03b3\u22480.57721,
\u03c6=1+\u221a5
2
\u22481.61803,
\u02c6
\u03c6=1\u2212\u221a5
2
\u2248\u2212.61803
i
2i
pi
General
Probability
1
2
2
Bernoulli Numbers (Bi = 0, oddi\ue002
= 1):
B0= 1,B1=\u22121
2,B2 =16,B4 =\u22121
30,
B6=1
42,B8 =\u22121
30,B10 =5
66.
Change of base, quadratic formula:
logbx=logax
logab,
\u2212b \u00b1\u221ab2\u22124ac
2a
.
Euler\u2019s numbere:
e= 1+12+ 16+ 1
24+1
120+\u00b7\u00b7\u00b7
lim
n\u2192\u221e
\ue009
1+x
n
\ue00an
=ex.
\ue000
1+1
n
\ue001n< e <
\ue000
1+1
n
\ue001n+1.
\ue000
1+1
n
\ue001n=e\u2212e
2n+11e
24n2\u2212O
\ue00b
1
n3
\ue00c
.
Harmonic numbers:
1,32, 11
6,25
12,137
60,49
20,363
140,761
280,7129
2520,...
lnn < Hn<ln n+1,
Hn= lnn +\u03b3 +O
\ue00b
1
n
\ue00c
.
Factorial, Stirling\u2019s approximation:
1, 2, 6, 24, 120, 720, 5040, 40320, 362880,...
n! =\u221a2\u03c0n\ue00b
ne
\ue00cn\ue00b
1+\u0398
\ue00b
1
n
\ue00c\ue00c
.
Ackermann\u2019s function and inverse:
a(i, j) =
\ue015
\ue017
\ue016
2j
i= 1
a(i\u22121,2)
j= 1
a(i\u22121, a(i, j\u22121)) i, j\u22652
\u03b1(i) = min{j| a(j, j)\u2265 i}.
Continuous distributions: If
Pr[a < X < b] =
\ue01f
b
ap(x) dx,
thenp is the probability density function of
X. If
Pr[X < a] =P (a),
thenP is the distribution function ofX. If
Pand pboth exist then
P(a) =
\ue01f
a
\u2212\u221ep(x) dx.
Expectation: IfX is discrete
E[g(X )] =
\ue01d
x
g(x) Pr[X= x].
IfX continuous then
E[g(X )] =
\ue01f
\u221e
\u2212\u221eg(x)p(x) dx=
\ue01f
\u221e
\u2212\u221eg(x) dP(x).
Variance, standard deviation:
VAR[X ] =E[X2]\u2212E[X ]2,
\u03c3=
\ue025
VAR[X ].
For eventsA andB:
Pr[A\u2228 B] = Pr[A] + Pr[B]\u2212 Pr[A\u2227 B]
Pr[A\u2227 B] = Pr[A]\u00b7 Pr[B],
i\ufb00A andB are independent.
Pr[A|B] =Pr[A\u2227 B]
Pr[B]
For random variablesX andY :
E[X\u00b7 Y ] = E[X ]\u00b7 E[Y ],
ifX andY are independent.
E[X +Y ] = E[X ]+ E[Y ],
E[cX ] =c E[X ].
Bayes\u2019 theorem:
Pr[Ai|B] =
Pr[B|Ai] Pr[Ai]
\ue01b
nj=1Pr[Aj ] Pr[B|Aj ].
Inclusion-exclusion:
Pr
\ue022
n
\ue021
i=1
Xi
\ue023
=
n
\ue01d
i=1
Pr[Xi] +
n
\ue01d
k=2(\u22121)k+1
\ue01d
ii <\u00b7\u00b7\u00b7<ik
Pr
\ue022
k
\ue020
j=1
Xij
\ue023
.
Moment inequalities:
Pr
\ue002|X| \u2265\u03bbE[X]\ue003
\u22641
\u03bb,
Pr
\ue022\ue008
\ue008X\u2212E[X]\ue008
\ue008
\u2265\u03bb \u00b7\u03c3
\ue023
\u22641
\u03bb2.
Geometric distribution:
Pr[X =k] =pqk\u22121,
q= 1\u2212 p,
E[X ] =
\u221e
\ue01d
k=1
kpqk\u22121=1
p.
2
4
3
3
8
5
4
16
7
5
32
11
6
64
13
7
128
17
8
256
19
9
512
23
10
1,024
29
11
2,048
31
12
4,096
37
13
8,192
41
14
16,384
43
15
32,768
47
16
65,536
53
17
131,072
59
18
262,144
61
19
524,288
67
20
1,048,576
71
21
2,097,152
73
22
4,194,304
79
23
8,388,608
83
24
16,777,216
89
25
33,554,432
97
26
67,108,864
101
27
134,217,728
103
28
268,435,456
107
Binomial distribution:
Pr[X =k] =
\ue00b
nk
\ue00c
pkqn\u2212k,
q= 1\u2212 p,
E[X ] =
n
\ue01d
k=1
k
\ue00b
nk
\ue00c
pk qn\u2212k= np.
Poisson distribution:
Pr[X =k] =e\u2212\u03bb\u03bbk
k!,E[X] = \u03bb.
Normal (Gaussian) distribution:
p(x) =1
\u221a2\u03c0\u03c3e\u2212(x\u2212\u00b5)2 /2\u03c32
,E[X] = \u00b5.

The \u201ccoupon collector\u201d: We are given a random coupon each day, and there aren di\ufb00erent types of coupons. The distribu- tion of coupons is uniform. The expected number of days to pass before we to col- lect alln types is

nHn.
29
536,870,912
109
30
1,073,741,824
113
31
2,147,483,648
127
32
4,294,967,296
131
Pascal\u2019s Triangle
1
1 1

12 1
1 3 3 1
1 4 6 4 1

1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->