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

CHEAT

Ratings: (0)|Views: 16 |Likes:
Published by shabedekam

More info:

Published by: shabedekam on May 30, 2008
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

06/14/2009

pdf

text

original

 
Theoretical Computer Science Cheat Sheet
Denitions Series
(
n
) =
O
(
g
(
n
)) iff 
positive
c,n
0
such that0
(
n
)
cg
(
n
)
n
n
0
.
n
i
=1
i
=
n
(
n
+ 1)2
,
n
i
=1
i
2
=
n
(
n
+ 1)(2
n
+ 1)6
,
n
i
=1
i
3
=
n
2
(
n
+ 1)
2
4
.
In general:
n
i
=1
i
m
=1
m
+ 1
(
n
+ 1)
m
+1
1
n
i
=1
(
i
+ 1)
m
+1
i
m
+1
(
m
+ 1)
i
m
n
1
i
=1
i
m
=1
m
+ 1
m
k
=0
m
+ 1
k
B
k
n
m
+1
k
.
Geometric series:
n
i
=0
c
i
=
c
n
+1
1
c
1
, c
= 1
,
i
=0
c
i
=11
c,
i
=1
c
i
=
c
1
c,
|
c
|
<
1
,
n
i
=0
ic
i
=
nc
n
+2
(
n
+ 1)
c
n
+1
+
c
(
c
1)
2
, c
= 1
,
i
=0
ic
i
=
c
(1
c
)
2
,
|
c
|
<
1
.
Harmonic series:
n
=
n
i
=1
1
i,
n
i
=1
iH 
i
=
n
(
n
+ 1)2
n
n
(
n
1)4
.
n
i
=1
i
= (
n
+ 1)
n
n,
n
i
=1
im
i
=
n
+ 1
m
+ 1
n
+1
1
m
+ 1
.
(
n
) = Ω(
g
(
n
)) iff 
positive
c,n
0
such that
(
n
)
cg
(
n
)
0
n
n
0
.
(
n
) = Θ(
g
(
n
)) iff 
(
n
) =
O
(
g
(
n
)) and
(
n
) = Ω(
g
(
n
)).
(
n
) =
o
(
g
(
n
)) ilim
n
→∞
(
n
)
/g
(
n
) = 0.lim
n
→∞
a
n
=
a
iff 
>
0,
n
0
such that
|
a
n
a
|
< 
,
n
n
0
.sup
least
b
R
such that
b
s
,
s
.inf 
greatest
b
R
such that
b
s
,
s
.liminf 
n
→∞
a
n
lim
n
→∞
inf 
{
a
i
|
i
n,i
N
}
.limsup
n
→∞
a
n
lim
n
→∞
sup
{
a
i
|
i
n,i
N
}
.
nk
Combinations: Size
k
sub-sets of a size
n
set.
nk
Stirling numbers (1st kind):Arrangements of an
n
ele-ment set into
k
cycles.
1.
nk
=
n
!(
n
k
)!
k
!
,
2.
n
k
=0
nk
= 2
n
,
3.
nk
=
nn
k
,
4.
nk
=
nk
n
1
k
1
,
5.
nk
=
n
1
k
+
n
1
k
1
,
6.
nm

mk
=
nk

n
km
k
,
7.
n
k
=0
r
+
kk
=
r
+
n
+ 1
n
,
8.
n
k
=0
km
=
n
+ 1
m
+ 1
,
9.
n
k
=0
rk

sn
k
=
r
+
sn
,
10.
nk
= (
1)
k
k
n
1
k
,
11.
n
1
=
nn
= 1
,
12.
n
2
= 2
n
1
1
,
13.
nk
=
k
n
1
k
+
n
1
k
1
,
nk
Stirling numbers (2nd kind):Partitions of an
n
elementset into
k
non-empty sets.
nk
1st order Eulerian numbers:Permutations
π
1
π
2
...π
n
on
{
1
,
2
,...,n
}
with
k
ascents.
nk
2nd order Eulerian numbers.
n
Catalan Numbers: Binarytrees with
n
+ 1 vertices.
14.
n
1
= (
n
1)!
,
15.
n
2
= (
n
1)!
n
1
,
16.
nn
= 1
,
17.
nk
nk
,
18.
nk
= (
n
1)
n
1
k
+
n
1
k
1
,
19.
nn
1
=
nn
1
=
n
2
,
20.
n
k
=0
nk
=
n
!
,
21.
n
=1
n
+ 1
2
nn
,
22.
n
0
=
nn
1
= 1
,
23.
nk
=
nn
1
k
,
24.
nk
= (
k
+ 1)
n
1
k
+ (
n
k
)
n
1
k
1
,
25.
0
k
=
1 if 
k
= 0,0 otherwise
26.
n
1
= 2
n
n
1
,
27.
n
2
= 3
n
(
n
+ 1)2
n
+
n
+ 12
,
28.
x
n
=
n
k
=0
nk

x
+
kn
,
29.
nm
=
m
k
=0
n
+ 1
k
(
m
+ 1
k
)
n
(
1)
k
,
30.
m
!
nm
=
n
k
=0
nk

kn
m
,
31.
nm
=
n
k
=0
nk

n
km
(
1)
n
k
m
k
!
,
32.
n
0
= 1
,
33.
nn
= 0 for
n
= 0
,
34.
nk
= (
k
+ 1)
n
1
k
+ (2
n
1
k
)
n
1
k
1
,
35.
n
k
=0
nk
=(2
n
)
n
2
n
,
36.
xx
n
=
n
k
=0
nk

x
+
n
1
k
2
n
,
37.
n
+ 1
m
+ 1
=
k
nk

km
=
n
k
=0
km
(
m
+ 1)
n
k
,
 
Theoretical Computer Science Cheat Sheet
Identities Cont. Trees
38.
n
+ 1
m
+ 1
=
k
nk

km
=
n
k
=0
km
n
n
k
=
n
!
n
k
=0
1
k
!
km
,
39.
xx
n
=
n
k
=0
nk

x
+
k
2
n
,
40.
nm
=
k
nk

k
+ 1
m
+ 1
(
1)
n
k
,
41.
nm
=
k
n
+ 1
k
+ 1

km
(
1)
m
k
,
42.
m
+
n
+ 1
m
=
m
k
=0
k
n
+
kk
,
43.
m
+
n
+ 1
m
=
m
k
=0
k
(
n
+
k
)
n
+
kk
,
44.
nm
=
k
n
+ 1
k
+ 1

km
(
1)
m
k
,
45.
(
n
m
)!
nm
=
k
n
+ 1
k
+ 1

km
(
1)
m
k
,
for
n
m
,
46.
nn
m
=
k
m
nm
+
k

m
+
nn
+
k

m
+
kk
,
47.
nn
m
=
k
m
nm
+
k

m
+
nn
+
k

m
+
kk
,
48.
n
+
m

+
m
=
k
k

n
km

nk
,
49.
n
+
m

+
m
=
k
k

n
km

nk
.
Every tree with
n
vertices has
n
1edges.Kraft inequal-ity: If the depthsof the leaves of a binary tree are
d
1
,...,d
n
:
n
i
=1
2
d
i
1
,
and equality holdsonly if every in-ternal node has 2sons.RecurrencesMaster method:
(
n
) =
aT 
(
n/b
) +
(
n
)
, a
1
,b >
1If 
 >
0 such that
(
n
) =
O
(
n
log
b
a
)then
(
n
) = Θ(
n
log
b
a
)
.
If 
(
n
) = Θ(
n
log
b
a
) then
(
n
) = Θ(
n
log
b
a
log
2
n
)
.
If 
 >
0 such that
(
n
) = Ω(
n
log
b
a
+
),and
c <
1 such that
af 
(
n/b
)
cf 
(
n
)for large
n
, then
(
n
) = Θ(
(
n
))
.
Substitution (example): Consider thefollowing recurrence
i
+1
= 2
2
i
·
2
i
,
1
= 2
.
Note that
i
is always a power of two.Let
t
i
= log
2
i
. Then we have
t
i
+1
= 2
i
+ 2
t
i
, t
1
= 1
.
Let
u
i
=
t
i
/
2
i
. Dividing both sides of the previous equation by 2
i
+1
we get
t
i
+1
2
i
+1
=2
i
2
i
+1
+
t
i
2
i
.
Substituting we find
u
i
+1
=
12
+
u
i
, u
1
=
12
,
which is simply
u
i
=
i/
2. So we findthat
i
has the closed form
i
= 2
i
2
i
1
.Summing factors (example): Considerthe following recurrence
(
n
) = 3
(
n/
2) +
n,
(1) = 1
.
Rewrite so that all terms involving
are on the left side
(
n
)
3
(
n/
2) =
n.
Now expand the recurrence, and choosea factor which makes the left side “tele-scope”1
(
n
)
3
(
n/
2) =
n
3
(
n/
2)
3
(
n/
4) =
n/
2
.........3
log
2
n
1
(2)
3
(1) = 2
Let
m
= log
2
n
. Summing the left sidewe get
(
n
)
3
m
(1) =
(
n
)
3
m
=
(
n
)
n
k
where
k
= log
2
3
1
.
58496.Summing the right side we get
m
1
i
=0
n
2
i
3
i
=
n
m
1
i
=0
32
i
.
Let
c
=
32
. Then we have
n
m
1
i
=0
c
i
=
n
c
m
1
c
1
= 2
n
(
c
log
2
n
1)= 2
n
(
c
(
k
1)log
c
n
1)= 2
n
k
2
n,
and so
(
n
) = 3
n
k
2
n
. Full history re-currences can often be changed to limitedhistory ones (example): Consider
i
= 1 +
i
1
j
=0
j
,
0
= 1
.
Note that
i
+1
= 1 +
i
j
=0
j
.
Subtracting we find
i
+1
i
= 1 +
i
j
=0
j
1
i
1
j
=0
j
=
i
.
And so
i
+1
= 2
i
= 2
i
+1
.Generating functions:1. Multiply both sides of the equa-tion by
x
i
.2. Sum both sides over all
i
forwhich the equation is valid.3. Choose a generating function
G
(
x
). Usually
G
(
x
) =
i
=0
x
i
g
i
.3. Rewrite the equation in terms of the generating function
G
(
x
).4. Solve for
G
(
x
).5. The coefficient of 
x
i
in
G
(
x
) is
g
i
.Example:
g
i
+1
= 2
g
i
+ 1
, g
0
= 0
.
Multiply and sum:
i
0
g
i
+1
x
i
=
i
0
2
g
i
x
i
+
i
0
x
i
.
We choose
G
(
x
) =
i
0
x
i
g
i
. Rewritein terms of 
G
(
x
):
G
(
x
)
g
0
x
= 2
G
(
x
) +
i
0
x
i
.
Simplify:
G
(
x
)
x
= 2
G
(
x
) +11
x.
Solve for
G
(
x
):
G
(
x
) =
x
(1
x
)(1
2
x
)
.
Expand this using partial fractions:
G
(
x
) =
x
21
2
x
11
x
=
x
2
i
0
2
i
x
i
i
0
x
i
=
i
0
(2
i
+1
1)
x
i
+1
.
So
g
i
= 2
i
1.
 
Theoretical Computer Science Cheat Sheet
π
3
.
14159,
e
2
.
71828,
γ 
0
.
57721,
φ
=
1+
52
1
.
61803,ˆ
φ
=
1
52
.
61803
i
2
i
 p
i
General Probability1 2 2Bernoulli Numbers (
B
i
= 0, odd
i
= 1):
B
0
= 1,
B
1
=
12
,
B
2
=
16
,
B
4
=
130
,
B
6
=
142
,
B
8
=
130
,
B
10
=
566
.Change of base, quadratic formula:log
b
x
=log
a
x
log
a
b,
b
±
b
2
4
ac
2
a.
Euler’s number
e
:
e
= 1 +
12
+
16
+
124
+
1120
+
···
lim
n
→∞
1 +
xn
n
=
e
x
.
1 +
1
n
n
< e <
1 +
1
n
n
+1
.
1 +
1
n
n
=
e
e
2
n
+11
e
24
n
2
O
1
n
3
.
Harmonic numbers:1,
32
,
116
,
2512
,
13760
,
4920
,
363140
,
761280
,
71292520
,...
ln
n < H 
n
<
ln
n
+ 1
,
n
= ln
n
+
γ 
+
O
1
n
.
Factorial, Stirling’s approximation:
1, 2, 6, 24, 120, 720, 5040, 40320, 362880,
...n
! =
2
πn
ne
n
1 + Θ
1
n

.
Ackermann’s function and inverse:
a
(
i,j
) =
2
j
i
= 1
a
(
i
1
,
2)
j
= 1
a
(
i
1
,a
(
i,j
1))
i,j
2
α
(
i
) = min
{
 j
|
a
(
 j,j
)
i
}
.
Continuous distributions: If Pr[
a < X < b
] =
 
ba
 p
(
x
)
dx,
then
p
is the probability density function of 
. If Pr[
X < a
] =
(
a
)
,
then
is the distribution function of 
. If 
and
p
both exist then
(
a
) =
 
a
−∞
 p
(
x
)
dx.
Expectation: If 
is discreteE[
g
(
)] =
x
g
(
x
)Pr[
=
x
]
.
If 
continuous thenE[
g
(
)] =
 
−∞
g
(
x
)
 p
(
x
)
dx
=
 
−∞
g
(
x
)
dP 
(
x
)
.
Variance, standard deviation:VAR[
] =E[
2
]
E[
]
2
,σ
=
 
VAR[
]
.
For events
A
and
B
:Pr[
A
B
] = Pr[
A
] + Pr[
B
]
Pr[
A
B
]Pr[
A
B
] = Pr[
A
]
·
Pr[
B
]
,
iff 
A
and
B
are independent.Pr[
A
|
B
] =Pr[
A
B
]Pr[
B
]For random variables
and
:E[
·
] =E[
]
·
E[
]
,
if 
and
are independent.E[
+
] =E[
] +E[
]
,
E[
cX 
] =
c
E[
]
.
Bayes’ theorem:Pr[
A
i
|
B
] =Pr[
B
|
A
i
]Pr[
A
i
]
nj
=1
Pr[
A
j
]Pr[
B
|
A
j
]
.
Inclusion-exclusion:Pr
n
i
=1
i
=
n
i
=1
Pr[
i
] +
n
k
=2
(
1)
k
+1
i
i
<
···
<i
k
Pr
k
j
=1
i
j
.
Moment inequalities:Pr
|
|
λ
E[
]
1
λ,
Pr
E[
]
λ
·
σ
1
λ
2
.
Geometric distribution:Pr[
=
k
] =
pq
k
1
, q
= 1
 p,
E[
] =
k
=1
kpq
k
1
=1
 p.
2 4 33 8 54 16 75 32 116 64 137 128 178 256 199 512 2310 1,024 2911 2,048 3112 4,096 3713 8,192 4114 16,384 4315 32,768 4716 65,536 5317 131,072 5918 262,144 6119 524,288 6720 1,048,576 7121 2,097,152 7322 4,194,304 7923 8,388,608 8324 16,777,216 8925 33,554,432 9726 67,108,864 10127 134,217,728 10328 268,435,456 107 Binomial distribution:Pr[
=
k
] =
nk
 p
k
q
n
k
, q
= 1
 p,
E[
] =
n
k
=1
k
nk
 p
k
q
n
k
=
np.
Poisson distribution:Pr[
=
k
] =
e
λ
λ
k
k
!
,
E[
] =
λ.
Normal (Gaussian) distribution:
 p
(
x
) =1
2
πσe
(
x
µ
)
2
/
2
σ
2
,
E[
] =
µ.
The “coupon collector”: We are given arandom coupon each day, and there are
n
different types of coupons. The distribu-tion of coupons is uniform. The expectednumber of days to pass before we to col-lect all
n
types is
nH 
n
.
29 536,870,912 10930 1,073,741,824 11331 2,147,483,648 12732 4,294,967,296 131Pascal’s Triangle11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 11 6 15 20 15 6 11 7 21 35 35 21 7 11 8 28 56 70 56 28 8 11 9 36 84 126 126 84 36 9 11 10 45 120 210 252 210 120 45 10 1

You're Reading a Free Preview

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