You are on page 1of 10

# Theoretical Computer Science Cheat Sheet

Denitions Series
f(n) = O(g(n)) i positive c, n
0
such that
0 f(n) cg(n) n n
0
.
n

i=1
i =
n(n + 1)
2
,
n

i=1
i
2
=
n(n + 1)(2n + 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
_
_
n1

i=1
i
m
=
1
m+ 1
m

k=0
_
m+ 1
k
_
B
k
n
m+1k
.
Geometric series:
n

i=0
c
i
=
c
n+1
1
c 1
, c = 1,

i=0
c
i
=
1
1 c
,

i=
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:
H
n
=
n

i=1
1
i
,
n

i=1
iH
n(n + 1)
2
H
n

n(n 1)
4
.
n

i=1
H
i
= (n + 1)H
n

i=1
_
i
m
_
H
i
=
_
n + 1
m+ 1
__
H
n+1

1
m+ 1
_
.
f(n) = (g(n)) i positive c, n
0
such that
f(n) cg(n) 0 n n
0
.
f(n) = (g(n)) i f(n) = O(g(n)) and
f(n) = (g(n)).
f(n) = o(g(n)) i lim
n
f(n)/g(n) = 0.
lim
n
a
n
= a i > 0, n
0
such that
|a
n
a| < , n n
0
.
sup S least b R such that b s,
s S.
inf S greatest b R such that b
s, 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}.
_
n
k
_
Combinations: Size k sub-
sets of a size n set.
_
n
k

## Stirling numbers (1st kind):

Arrangements of an n ele-
ment set into k cycles.
1.
_
n
k
_
=
n!
(n k)!k!
, 2.
n

k=0
_
n
k
_
= 2
n
, 3.
_
n
k
_
=
_
n
n k
_
,
4.
_
n
k
_
=
n
k
_
n 1
k 1
_
, 5.
_
n
k
_
=
_
n 1
k
_
+
_
n 1
k 1
_
,
6
_
n
m
__
m
k
_
=
_
n
k
__
n k
mk
_
, 7.
n

k=0
_
r +k
k
_
=
_
r +n + 1
n
_
,
8.
n

k=0
_
k
m
_
=
_
n + 1
m+ 1
_
, 9.
n

k=0
_
r
k
__
s
n k
_
=
_
r +s
n
_
,
10.
_
n
k
_
= (1)
k
_
k n 1
k
_
, 11.
_
n
1
_
=
_
n
n
_
= 1,
12.
_
n
2
_
= 2
n1
1, 13.
_
n
k
_
= k
_
n 1
k
_
+
_
n 1
k 1
_
,
_
n
k
_
Stirling numbers (2nd kind):
Partitions of an n element
set into k non-empty sets.

n
k
_
1st order Eulerian numbers:
Permutations
1

2
. . .
n
on
{1, 2, . . . , n} with k asce ts.

n
k
__
2nd order Eulerian n mbers.
C
n
Catalan Numbers: Binary
trees with n + 1 vertices.
14.
_
n
1
_
= (n 1)!, 15.
_
n
2
_
= (n 1)!H
n1
, 16.
_
n
n
_
= 1, 17.
_
n
k
_

_
n
k
_
,
18.
_
n
k
_
= (n 1)
_
n 1
k
_
+
_
n 1
k 1
_
, 19.
_
n
n 1
_
=
_
n
n 1
_
=
_
n
2
_
, 20.
n

k=0
_
n
k
_
= n!, 21. C
n
=
1
n + 1
_
2n
n
_
,
22.
_
n
0
_
=
_
n
n
_
= 1, 23.
_
n
k
_
=
_
n
n 1 k
_
, 24.
_
n
k
_
= (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 + 1
2
_
,
28. x
n
=
n

k=0
_
n
k
__
x +k
n
_
, 29.
_
n
m
_
=
m

k=0
_
n + 1
k
_
(m+ 1 k)
n
(1)
k
, 30. m!
_
n
m
_
=
n

k=0
_
n
k
__
k
n m
_
,
31.
_
n
m
_
=
n

k=0
_
n
k
__
n k
m
_
(1)
nkm
k!, 32.
__
n
0
__
= 1, 33.
__
n
n
__
= 0 for n = 0,
34.
__
n
k
__
= (k + 1)
__
n 1
k
__
+ (2n 1 k)
__
n 1
k 1
__
, 35.
n

k=0
__
n
k
__
=
(2n)
n
2
n
,
36.
_
x
x n
_
=
n

k=0
__
n
k
___
x +n 1 k
2n
_
, 37.
_
n + 1
m+ 1
_
=

k
_
n
k
__
k
m
_
=
n

k=0
_
k
m
_
(m+ 1)
nk
,
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
c c
,,

ii==
cc
ii
==
, c , c = 1 = 1

nn

ii=1 =1
iH iH iH iH iH
n n( (
+ 1) + 1)HH
nn
HHH
nn

__
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
__
==
nn!!
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
((nn kk)! )!kk!!
4. 4.
__
nn
kk
__
==
nn
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
kk
__
nn
66
__
nn
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
mm
__ __
8. 8.
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
1st order Eulerian numbers: 1st order Eulerian numbers:
. . . . . .
nn
on on
kk asce ts. asce ts.
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
2nd order Eulerian n mbers. 2nd order Eulerian n mbers.
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Catalan Numbers: Binary Catalan Numbers: Binary
trees with trees with nn + 1 vertices. + 1 vertices.
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
15. 15.
1) 1)
__
nn 11
kk
__
++
__
__
==
__
nn
nn
__
= 1 = 1
__
1 if 1 if
0 otherwise 0 otherwise
Theoretical Computer Science Cheat Sheet
Identities Cont. Trees
38.
_
n + 1
m+ 1
_
=

k
_
n
k
__
k
m
_
=
n

k=0
_
k
m
_
n
nk
= n!
n

k=0
1
k!
_
k
m
_
, 39.
_
x
x n
_
=
n

k=0
__
n
k
___
x +k
2n
_
,
40.
_
n
m
_
=

k
_
n
k
__
k + 1
m+ 1
_
(1)
nk
, 41.
_
n
m
_
=

k
_
n + 1
k + 1
__
k
m
_
(1)
mk
,
42.
_
m+n + 1
m
_
=
m

k=0
k
_
n +k
k
_
, 43.
_
m+n + 1
m
_
=
m

k=0
k(n +k)
_
n +k
k
_
,
44.
_
n
m
_
=

k
_
n + 1
k + 1
__
k
m
_
(1)
mk
, 45. (n m)!
_
n
m
_
=

k
_
n + 1
k + 1
__
k
m
_
(1)
mk
, for n m,
46.
_
n
n m
_
=

k
_
mn
m+k
__
m+n
n +k
__
m+k
k
_
, 47.
_
n
n m
_
=

k
_
mn
m+k
__
m+n
n +k
__
m+k
k
_
,
48.
_
n
+m
__
+m

_
=

k
_
k

__
n k
m
__
n
k
_
, 49.
_
n
+m
__
+m

_
=

k
_
k

__
n k
m
__
n
k
_
.
Every tree with n
vertices has n 1
edges.
Kraft inequal-
ity: If the depths
of the leaves of
a bi ry tree are
d
1
. . , d
n
:
n

i=1
2
di
1,
and equality holds
only if every in-
ternal node has 2
sons.
Recurrences
Master method:
T(n) = aT(n/b) +f(n), a 1, b > 1
If > 0 such that f(n) = O(n
log
b
a
)
then
T(n) = (n
log
b
a
).
If f(n) = (n
log
b
a
) then
T(n) = (n
log
b
a
log
2
n).
If > 0 such that f(n) = (n
log
b
a+
),
and c < 1 such that af(n/b) cf(n)
for large n, then
T(n) = (f(n)).
Substitution (example): Consider the
following recurrence
T
i+1
= 2
2
i
T
2
i
, T
1
= 2.
Note that T
i
is always a power of two.
Let t
i
= log
2
T
i
. Then we have
t
i+1
= 2
i
+ 2t
i
, t
1
= 1
Let u
i
= t
i
/2
i
. Dividing both s des 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 nd
u
i+1
=
2
+u u
1
=
1
2
,
which is simply u
i
= i/2. So we nd
that T
i
has the closed form T
i
= 2
i2
i1
.
Summing factors (example): Consider
the following recurrence
T(n) = 3T(n/2) +n, T(1) = 1.
Rewrite so that all terms involving T
are on the left side
T(n) 3T(n/2) = n.
Now expand the recurrence, and choose
a factor which makes the left side tele-
scope
1
_
T(n) 3T(n/2) = n
_
3
_
T(n/2) 3T(n/4) = n/2
_
.
.
.
.
.
.
.
.
.
3
log
2
n1
_
T(2) 3T(1 = 2
_
Let m = log
2
n. Summing the left side
we get T(n) 3 T(1) T(n) 3
m
=
T(n) n
k
where k = log
2
3 1.58496.
Summing the right side we get
m

=0
n
2
3
i
= n
m1

i=0
_
3
2
_
i
.
Let c =
3
2
Then we have
n
m1

i=0
c
i
= n
_
c
m
1
c 1
_
= 2n(c
log
2
n
1)
= 2n(c
(k1) log
c
n
1)
= 2n
k
2n,
and so T(n) = 3n
k
2n. Full history re-
currences can often be changed to limited
history ones (example): Consider
T
i
= 1 +
i1

j=0
T
j
, T
0
= 1.
Note that
T
i+1
= 1 +
i

j=0
T
j
.
Subtracting we nd
T
i+1
T
i
= 1 +
i

j=0
T
j
1
i1

j=0
T
j
= T
i
.
And so T
i+1
= 2T
i
= 2
i+1
.
Generating functions:
1. Multiply both sides of the equa-
tion by x
i
.
2. Sum both sides over all i for
which 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 coecient of x
i
in G(x) is g
i
.
Example:
g
i+1
= 2g
i
+ 1, g
0
= 0.
Multiply and sum:

i0
g
i+1
x
i
=

i0
2g
i
x
i
+

i0
x
i
.
We choose G(x) =

i0
x
i
g
i
. Rewrite
in terms of G(x):
G(x) g
0
x
= 2G(x) +

i0
x
i
.
Simplify:
G(x)
x
= 2G(x) +
1
1 x
.
Solve for G(x):
G(x) =
x
(1 x)(1 2x)
.
Expand this using partial fractions:
G(x) = x
_
2
1 2x

1
1 x
_
= x
_
_
2

i0
2
i
x
i

i0
x
i
_
_
=

i0
(2
i+1
1)x
i+1
.
So g
i
= 2
i
1.
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
k k
kk
__
, ,
__ __
kk
mm
__ __
nn
kk
__
..
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
a bi ry tree are a bi ry tree are
d d
11
. . , d . . , d
nn
::
nn

ii=1 =1
22
ddii
and equality holds and equality holds
only if every in- only if every in-
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
is always a power of two. is always a power of two.
= 1 = 1
. Dividing both s des of . Dividing both s des of
the previous equation by 2 the previous equation by 2
ii+1 +1
we get we get
22
ii
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
ii+1 +1
++
tt
ii
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
ii
Substituting we nd Substituting we nd
+1 +1
==
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
++uu uu
which is simply which is simply uu
ii
has the closed form has the closed form
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
4) = 4) = n/ n/22
__
TT(1 = 2 (1 = 2
__
. Summing the left side . Summing the left side
33 TT(1) (1) TT
where where kk = log = log
Summing the right side we get Summing the right side we get
mm

=0 =0
nn
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
33
ii
Let Let cc ==
33
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
Then we have Then we have
nn
mm
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Generating functions: Generating functions:
1. Multiply both sides of the equa- 1. Multiply both sides of the equa-
Theoretical Computer Science Cheat Sheet
3.14159, e 2.71828, 0.57721, =
1+

5
2
1.61803,

=
1

5
2
.61803
i 2
i
p
i
General Probability
1 2 2 Bernoulli Numbers (B
i
= 0, odd i = 1):
B
0
= 1, B
1
=
1
2
, B
2
=
1
6
, B
4
=
1
30
,
B
6
=
1
42
, B
8
=
1
30
, B
10
=
5
66
.
log
b
x =
log
a
x
log
a
b
,
b

b
2
4ac
2a
.
Eulers number e:
e = 1 +
1
2
+
1
6
+
1
24
+
1
120
+
lim
n
_
1 +
x
n
_
n
= e
x
.
_
1 +
1
n
_
n
< e <
_
1 +
1
n
_
n+1
.
_
1 +
1
n
_
n
= e
e
2n
+
11e
24n
2
O
_
1
n
3
_
.
Harmonic numbers:
1,
3
2
,
11
6
,
25
12
,
137
60
,
49
20
,
363
140
,
761
280
,
7129
2520
, . . .
ln n < H
n
< ln n + 1,
H
n
= ln n + +O
_
1
n
_
.
Factorial, Stirlings approximation
1, 2, 6, 24, 120, 720, 5040, 40 20, 362880, . . .
n! =

2n
_
n
e
_
n
_
1 +
_
1
n
__
.
Ackermann s fun tion and inverse:
a( , 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] =
_
b
a
p(x) dx,
then p is the probability density function of
X. If
Pr[X < a] = P(a),
then P is the distribu ion fun tion of X. If
P and p both exist then
P(a) =
_
a

p(x) dx.
Expectation: If X is discrete
E[g(X)]

x
g(x) Pr[X = x].
I X continuous then
E[g(X)] =
_

g(x)p(x) dx =
_

g(x) dP(x).
Variance, standard deviation:
VAR[X] = E[X
2
] E[X]
2
,
=
_
VAR[X].
For events A and B:
Pr[A B] = Pr[A] + Pr[B] Pr[A B]
Pr[A B] = Pr[A] Pr[B],
i A and B are independent.
Pr[A|B] =
Pr[A B]
Pr[B]
For random variables X and Y :
E[X Y ] = E[X] E[Y ],
if X and Y are independent.
E[X +Y ] = E[X] + E[Y ],
E[cX] = c E[X].
Bayes theorem:
Pr[A
i
|B] =
Pr[B|A
i
] Pr[A
i
]

n
j=1
Pr[A
j
] Pr[B|A
j
]
.
Inclusion-exclusion:
Pr
_
n

i=1
X
i
_
=
n

i=1
Pr[X
i
] +
n

k=2
(1)
k+1

ii<<i
k
Pr
_
k

j=1
X
ij
_
.
Moment inequalities:
Pr
_
|X| E[X]

,
Pr
_

X E[X]

2
.
Geometric distribution:
Pr[X = k] = pq
k1
, q = 1 p,
E[X] =

k=1
kpq
k1
=
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] =
_
n
k
_
p
k
q
nk
, q = 1 p,
E[X] =
n

k=1
k
_
n
k
_
p
k
q
nk
= np.
Poisson distribution:
Pr[X = k] =
e

k
k!
, E[X] = .
Normal (Gaussian) distribution:
p(x) =
1

2
e
(x)
2
/2
2
, E[X] = .
The coupon collector: We are given a
random coupon each day, and there are n
dierent types of coupons. The distribu-
tion of coupons is uniform. The expected
number of days to pass before we to col-
lect all n types is
nH
n
.
29 536,870,912 109
30 1,073,741,824 113
31 2,147,483,648 27
32 4,294,967 296 131
Pasca s Triangle
1
1 1
1 2 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
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
is the probability density function of is the probability density function of
] = ] = P P((aa)),,
is the distribu ion fun tion of is the distribu ion fun tion of
both exist then both exist then
PP((aa) = ) =
__
aa

___
pp( (
Expectation: If Expectation: If XX
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
, . . . , . . .
__
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
nn
__
..
Factorial, Stirlings approximation Factorial, Stirlings approximation
1, 2, 6, 24, 120, 720, 5040, 40 20, 362880, 1, 2, 6, 24, 120, 720, 5040, 40 20, 362880,
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22n n
__
nn
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
ee
__
nn
__
1 + 1 +
Ackermann s fun tion and inverse: Ackermann s fun tion and inverse:
aa(( , j , j) = ) =
__
__
___
__
___22
jj
aa((ii
aa
((ii) = min ) = min
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
is discrete is discrete
EE[ [gg((X X)] )]

II XX continuous then continuous then
E E[[gg((XX)] = )] =
Variance, standard deviation: Variance, standard deviation:
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
107 107
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Binomial distribution: Binomial distribution:
Pr[ Pr[
109 109
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
113 113
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
2,147,483,648 2,147,483,648
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
27 27
4,294,967 296 4,294,967 296
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
131 131
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Pasca s Triangle Pasca s Triangle
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11
1 1 1 1
1 2 1 1 2 1
Theoretical Computer Science Cheat Sheet
Trigonometry Matrices More Trig.
A
c

B
a
b
C
(0,-1)
(0,1)
(-1,0) (1,0)
(cos , sin )
Pythagorean theorem:
C
2
= A
2
+B
2
.
Denitions:
sin a = A/C, cos a = B/C,
csc a = C/A, sec a = C/B,
tan a =
sin a
cos a
=
A
B
, cot a =
cos a
sin a
=
B
A
.
1
2
AB,
AB
A+B +C
.
Identities:
sin x =
1
csc x
, cos x =
1
sec x
,
tan x =
1
cot x
, sin
2
x + cos
2
x = 1,
1 + tan
2
x = sec
2
x, 1 + cot
2
x = csc
2
x,
sin x = cos
_

2
x
_
, sin x = sin( x),
cos x = cos( x), tan x = cot
_

2
x
_
,
cot x = cot( x), csc x = cot
x
2
cot x
sin(x y) = sin xcos y cos xsin y,
cos(x y) = cos xcos y sin xsin y,
tan(x y) =
tan x tan y
1 tan xtan y
,
cot(x y) =
cot xcot y 1
cot x cot y
,
sin 2x = 2 sin xcos x, sin 2x =
2 tan x
1 + tan
2
x
,
cos 2x = cos
2
x sin
2
x, cos 2x = 2 cos
2
x 1,
cos 2x = 1 2 s n
2
x, cos 2x =
1 tan
2
x
1 + tan
2
x
,
tan 2x =
2 tan x
1 tan
2
x
, cot 2x =
cot
2
x 1
2 cot x
,
sin(x +y) sin(x y) = sin
2
x sin
2
y,
cos(x +y) cos(x y) = cos
2
x sin
2
y.
Eulers equation:
e
ix
= cos x +i sin x, e
i
= 1.
Multiplication:
C = A B, c
i,j
=
n

k=1
a
i,k
b
k,j
.
Determinants: det A = 0 i A is non-singular.
det A B = det A det B,
det A =

i=1
sign()a
i,(i)
.
2 2 and 3 3 determinant:

a b
c d

a b c
d e f
g h i

= g

b c
e f

a c
d f

+i

a b
d e

=
aei +bfg +cdh
ceg fha ibd.
Permanents:
permA =

i=1
a
,(i)
.
A
a
c
h
b
B
C
Law of cosines:
c
2
=
2
b
2
2ab cos C.
A e
A =
1
2
hc,
=
1
2
ab sin C,
=
c
2
sin Asin B
2 sin C
.
Herons formula:
A =

s s
a
s
b
s
c
,
s =
1
2
(a +b +c),
s
a
= s a,
s
b
= s b,
s
c
= s c.
More identities:
sin
x
2
=
_
1 cos x
2
,
cos
x
2
=
_
1 + cos x
2
,
tan
x
2
=
_
1 cos x
1 + cos x
,
=
1 cos x
sin x
,
=
sin x
1 + cos x
,
cot
x
2
=
_
1 + cos x
1 cos x
,
=
1 + cos x
sin x
,
=
sin x
1 cos x
,
sin x =
e
ix
e
ix
2i
,
cos x =
e
ix
+e
ix
2
,
tan x = i
e
ix
e
ix
e
ix
+e
ix
,
= i
e
2ix
1
e
2ix
+ 1
,
sin x =
sinh ix
i
,
cos x = cosh ix,
tan x =
tanh ix
i
.
Hyp rbolic Functions
Denitions:
sinh x =
e e
x
2
cosh x =
e
x
+e
x
2
,
tanh x =
x
e
x
e
x
+e
x
, csch x =
1
sinh x
,
sec x =
1
cosh x
, coth x =
1
tanh x
.
dentities:
cosh
2
x sinh
2
x = 1, tanh
2
x + sech
2
x = 1,
coth
2
x csch
2
x = 1, sinh(x) = sinh x,
cosh(x) = cosh x, tanh(x) = tanh x,
sinh(x +y) = sinh xcosh y + cosh xsinh y,
cosh(x +y) = cosh xcosh y + sinh xsinh y,
sinh 2x = 2 sinh xcosh x,
cosh 2x = cosh
2
x + sinh
2
x,
cosh x + sinh x = e
x
, cosh x sinh x = e
x
,
(cosh x + sinh x)
n
= cosh nx + sinh nx, n Z,
2 sinh
2 x
2
= cosh x 1, 2 cosh
2 x
2
= cosh x + 1.
sin cos tan
0 0 1 0

6
1
2

3
2

3
3

2
2

2
2
1

3
2
1
2

2
1 0
. . . in mathematics
you dont under-
stand things, you
just get used to
them.
J. von Neumann v2.02 c 1994 by Steve Seiden
sseiden@acm.org
http://www.csc.lsu.edu/~seiden
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m

+ +i i

a b a b
d e d e

+ +cdh cdh
fha fha ibd. ibd.
==

nn

ii=1 =1
aa
, ,
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
,,
cot cot xx
y, y,
yy
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
cot cot yy
,,
cos cos x, x, sin 2 sin 2
xx sin sin
22
x, x,
= 1 = 1 2 s n 2 s n
22
x, x,
2 tan 2 tanw
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
==
22
bb
A e A e
AA ==
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
hc, hc,
= =
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Hyp rbolic Functions Hyp rbolic Functions
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
==
ee ee
xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
tanh tanh xx ==
xx
ee
xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
ee
xx
++
sec sec xx ==
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dentities: dentities:
cosh cosh
Theoretical Computer Science Cheat Sheet
Number Theory Graph Theory
The Chinese remainder theorem: There ex-
ists a number C such that:
C r
1
mod m
1
.
.
.
.
.
.
.
.
.
C r
n
mod m
n
if m
i
and m
j
are relatively prime for i = j.
Eulers function: (x) is the number of
positive integers less than x relatively
prime to x. If

n
i=1
p
ei
i
is the prime fac-
torization of x then
(x) =
n

i=1
p
ei1
i
(p
i
1).
Eulers theorem: If a and b are relatively
prime then
1 a
(b)
mod b.
Fermats theorem:
1 a
p1
mod p.
The Euclidean algorithm: if a > b are in-
tegers then
gcd(a, b) = gcd(a mod b, b).
If

n
i=1
p
ei
i
is the prime factorization of x
then
S(x) =

d|x
d =
n

i=1
p
ei+1
i
1
p
i
1
.
Perfect Numbers: x is an even perfect num-
ber i x = 2
n1
(2
n
1) and 2
n
1 is prime.
Wilsons theorem: n is a prime i
(n 1)! 1 mod n.
Mobius inversion:
(i) =
_

_
1 if i = 1.
0 if i is not squ re-free.
(1)
r
if i is th product f
r distin t prim s.
If
G(a) =

d|a
F(d),
then
F(a) =

d|a
(d)G
_
a
d
_
.
Prime numbers:
p
n
= nln n +nln ln n n +n
ln ln n
ln n
+O
_
n
ln n
_
,
(n) =
n
ln n
+
n
(ln n)
2
+
2!n
(ln n)
3
+O
_
n
(ln n)
4
_
.
Denitions:
Loop An edge connecting a ver-
tex to itself.
Directed Each edge has a direction.
Simple Graph with no loops or
multi-edges.
Walk A sequence v
0
e
1
v
1
. . . e

.
Trail A walk with distinct edges.
Path A trail with distinct
vertices.
Connected A graph where there exists
a path between any two
vertices.
Component A maximal connected
subgraph.
Tree A connected acyclic graph.
Free tree A tree with no root.
DAG Directed acyclic graph.
Eulerian Graph with a tra l visiting
each edge exactly once.
Hamiltonian Graph with a cy le visiting
each vertex exact y once.
Cut A set of edg s whose re-
m l in reases the num-
ber of omponents.
Cut-set A minimal cut.
Cut edge A size 1 cut.
k-Connec ed A graph connected with
the removal of any k 1
vertices.
k T ugh S V, S = we have
k c(GS) |S|.
k-Regular A graph where all vertices
have degree k.
k-Factor A k-regular spanning
subgraph.
Matching A set of edges, no two of
Clique A set of vertices, all of
Ind. set A set of vertices, none of
Vertex cover A set of vertices which
cover all edges.
Planar graph A graph which can be em-
beded in the plane.
Plane graph An embedding of a planar
graph.

vV
deg(v) = 2m.
If G is planar then n m+f = 2, so
f 2n 4, m 3n 6.
Any planar graph has a vertex with de-
gree 5.
Notation:
E(G) Edge set
V (G) Vertex set
c(G) Number of components
G[S] Induced subgraph
deg(v) Degree of v
(G) Maximum degree
(G) Minimum degr e
(G) Chromatic number

E
(G) Edge hroma ic number
G
c
Complement graph
K
n
Comp ete graph
K
1,n2
Complete bipartite graph
r k, ) Ramsey number
Geometry
Pr jective coordinates: triples
(x, y, z), not all x, y and z zero.
(x, y, z) = (cx, cy, cz) c = 0.
Cartesian Projective
(x, y) (x, y, 1)
y = mx +b (m, 1, b)
x = c (1, 0, c)
Distance formula, L
p
and L

metric:
_
(x
1
x
0
)
2
+ (y
1
y
0
)
2
,
_
|x
1
x
0
|
p
+|y
1
y
0
|
p

1/p
,
lim
p
_
|x
1
x
0
|
p
+|y
1
y
0
|
p

1/p
.
Area of triangle (x
0
, y
0
), (x
1
, y
1
)
and (x
2
, y
2
):
1
2
abs

x
1
x
0
y
1
y
0
x
2
x
0
y
2
y
0

.
Angle formed by three points:

(0, 0) (x
1
, y
1
)
(x
2
, y
2
)

1
cos =
(x
1
, y
1
) (x
2
, y
2
)

2
.
Line through two points (x
0
, y
0
)
and (x
1
, y
1
):

x y 1
x
0
y
0
1
x
1
y
1
1

= 0.
Area of circle, volume of sphere:
A = r
2
, V =
4
3
r
3
.
If I have seen farther than others,
it is because I have stood on the
shoulders of giants.
Issac Newton
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
A connected acyclic graph. A connected acyclic graph.
Directed acyclic graph. Directed acyclic graph.
Graph with a tra l visiting Graph with a tra l visiting
each edge exactly once. each edge exactly once.
Graph with a cy le visiting Graph with a cy le visiting
each vertex exact y once. each vertex exact y once.
A set of edg s whose re- A set of edg s whose re-
m l in reases the num- m l in reases the num-
ber of omponents. ber of omponents.
A minimal cut. A minimal cut.
Cut edge Cut edge A size 1 cut. A size 1 cut.
k-Connec ed k-Connec ed A graph connected with A graph connected with
the removal of any the removal of any
k T ugh k T ugh
k-Regular k-Regular
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
) Maximum degree ) Maximum degree
) Minimum degr e ) Minimum degr e
) Chromatic number ) Chromatic number
) Edge hroma ic number ) Edge hroma ic number
Complement graph Complement graph
Comp ete graph Comp ete graph
KKKKK
11,n ,n22
Complete bipartite graph Complete bipartite graph
rr k, k, ) Ramsey number ) Ramsey number
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
1 is prime. 1 is prime.
is not squ re-free. is not squ re-free.
is th product f is th product f
distin t prim s. distin t prim s.
aa) = ) =

dd||aa
FF((dd))
FF((aa) = ) =

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Pr jective coordinates: triples Pr jective coordinates: triples
((x, y, z x, y, z
Theoretical Computer Science Cheat Sheet
Calculus
Wallis identity:
= 2
2 2 4 4 6 6
1 3 3 5 5 7
Brounckers continued fraction expansion:

4
= 1 +
1
2
2 +
3
2
2+
5
2
2+
7
2
2+
Gregrorys series:

4
= 1
1
3
+
1
5

1
7
+
1
9

Newtons series:

6
=
1
2
+
1
2 3 2
3
+
1 3
2 4 5 2
5
+
Sharps series:

6
=
1

3
_
1
1
3
1
3
+
1
3
2
5

1
3
3
7
+
_
Eulers series:

2
6
=
1
1
2
+
1
2
2
+
1
3
2
+
1
4
2
+
1
5
2
+

2
8
=
1
1
2
+
1
3
2
+
1
5
2
+
1
7
2
+
1
9
2
+

2
12
=
1
1
2

1
2
2
+
1
3
2

1
4
2
+
1
5
2

Derivatives:
1.
d(cu)
dx
= c
du
dx
, 2.
d(u +v)
dx
=
du
dx
+
dv
dx
, 3.
d(uv)
dx
= u
dv
dx
+v
du
dx
,
4.
d(u
n
)
dx
= nu
n1
du
dx
, 5.
d(u/v)
dx
=
v
_
du
dx
_
u
_
dv
dx
_
v
2
, 6.
d(e
cu
)
dx
= ce
cu
du
dx
,
7.
d(c
u
)
dx
= (ln c)c
u
du
dx
, 8.
d(ln u)
dx
=
1
u
du
dx
,
9.
d(sin u)
dx
= cos u
du
dx
, 10.
d cos u)
dx
= sin u
du
dx
,
11.
d(tan u)
dx
= sec
2
u
du
dx
, 12.
d(cot u)
dx
= csc
2
u
du
dx
,
13.
d(sec u)
dx
= tan u sec u
du
dx
, 14.
d csc u)
dx
= cot u csc u
du
dx
,
15.
d(arcsin u)
dx
=
1

1 u
2
du
dx
, 16.
d(arccos u)
dx
=
1

1 u
2
du
dx
,
17.
d(arctan u)
dx
=
1
1 +u
2
du
dx
, 18.
d(arccot u)
dx
=
1
1 +u
2
du
dx
,
19.
d(arcsec u)
dx
=
1
u

1 u
2
du
dx
, 20.
d(arccsc u)
dx
=
1
u

1 u
2
du
dx
,
21.
d(sinh u)
dx
= c sh u
du
dx
, 22.
d(cosh u)
dx
= sinh u
du
dx
,
23.
d(tanh u)
dx
= s ch
2
u
du
dx
, 24.
d(coth u)
dx
= csch
2
u
du
dx
,
25.
d(sec u)
dx
= sech u tanh u
du
dx
, 26.
d(csch u)
dx
= csch u coth u
du
dx
,
27
d(arcsinh u)
dx
=
1

1 +u
2
du
dx
, 28.
d(arccosh u)
dx
=
1

u
2
1
du
dx
,
9.
d(arctanh u)
dx
=
1
1 u
2
du
dx
, 30.
d(arccoth u)
dx
=
1
u
2
1
du
dx
,
31.
d(arcsech u)
dx
=
1
u

1 u
2
du
dx
, 32.
d(arccsch u)
dx
=
1
|u|

1 +u
2
du
dx
.
Integrals:
1.
_
cudx = c
_
udx, 2.
_
(u +v) dx =
_
udx +
_
v dx,
3.
_
x
n
dx =
1
n + 1
x
n+1
, n = 1, 4.
_
1
x
dx = ln x, 5.
_
e
x
dx = e
x
,
6.
_
dx
1 +x
2
= arctan x, 7.
_
u
dv
dx
dx = uv
_
v
du
dx
dx,
8.
_
sin xdx = cos x, 9.
_
cos xdx = sin x,
10.
_
tan xdx = ln | cos x|, 11.
_
cot xdx = ln | cos x|,
12.
_
sec xdx = ln | sec x + tan x|, 13.
_
csc xdx = ln | csc x + cot x|,
14.
_
arcsin
x
a
dx = arcsin
x
a
+
_
a
2
x
2
, a > 0,
Partial Fractions
Let N(x) and D(x) be polynomial func-
tions of x. We can break down
N(x)/D(x) using partial fraction expan-
sion. First, if the degree of N is greater
than or equal to the degree of D, divide
N by D, obtaining
N(x)
D(x)
= Q(x) +
N

(x)
D(x)
,
where the degree of N

## is less than that of

D. Second, factor D(x). Use the f llow-
ing rules: For a non-repeated facto :
N(x)
(x a)D(x)
=
A
x a
+
N

(x)
D(x)
,
where
A =
_
N(x)
D(x)
_
x=a
.
For a repea ed factor:
N(x)
(x a)
m
D(x)
=
m1

k=0
A
k
(x a)
mk
+
N

(x)
D(x)
,
where
A
k
=
1
k!
_
d
k
dx
k
_
N(x)
D(x)
__
x=a
.
The reasonable man adapts himself to the
world; the unreasonable persists in trying
to adapt the world to himself. Therefore
all progress depends on the unreasonable.
George Bernard Shaw
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
8. 8.
dd(ln (ln
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
10. 10.
d d cos cos uu))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
==
12. 12.
d d(cot (cot
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
14. 14.
d d csc csc
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
16. 16.
dx dx
,,
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11 uu
22
du du
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
,,
= c sh = c sh uu
du du
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
,,
(tanh (tanh uu))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
= s ch = s ch
22
uu
du du
25. 25.
dd(sec (sec uu))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
==
27 27
dd(arcsinh (arcsinh
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
9. 9.
dd
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
is less than that of is less than that of
). Use the f llow- ). Use the f llow-
ing rules: For a non-repeated facto : ing rules: For a non-repeated facto :
AA
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
xx aa
++
NN

((xx))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
DD((xx))
AA ==
__
NN((xx))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
DD((xx))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
__
For a repea ed factor: For a repea ed factor:
==
mm
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Theoretical Computer Science Cheat Sheet
Calculus Cont.
15.
_
arccos
x
a
dx = arccos
x
a

_
a
2
x
2
, a > 0, 16.
_
arctan
x
a
dx = xarctan
x
a

a
2
ln(a
2
+x
2
), a > 0,
17.
_
sin
2
(ax)dx =
1
2a
_
ax sin(ax) cos(ax)
_
, 18.
_
cos
2
(ax)dx =
1
2a
_
ax + sin(ax) cos(ax)
_
,
19.
_
sec
2
xdx = tan x, 20.
_
csc
2
xdx = cot x,
21.
_
sin
n
xdx =
sin
n1
xcos x
n
+
n 1
n
_
sin
n2
xdx, 22.
_
cos
n
xdx =
cos
n1
xsin x
n
+
n 1
n
_
cos
2
xdx,
23.
_
tan
n
xdx =
tan
n1
x
n 1

_
tan
n2
xdx, n = 1, 24.
_
cot
n
xdx =
cot
n1
x
n 1

_
ot
n 2
xdx, n = 1,
25.
_
sec
n
xdx =
tan xsec
n1
x
n 1
+
n 2
n 1
_
sec
n2
xdx, n = 1,
26.
_
csc
n
xdx =
cot xcsc
n1
x
n 1
+
n 2
n 1
_
csc
n2
xdx, n = 1, 27.
_
sinh xdx = cosh x, 28.
_
cosh xdx = sinh x,
29.
_
tanh xdx = ln | cosh x|, 30.
_
coth xdx = ln | sinh x|, 31.
_
sech xdx = arct n sinh x, 32.
_
csch xdx = ln

tanh
x
2

,
33.
_
sinh
2
xdx =
1
4
sinh(2x)
1
2
x, 34.
_
cosh
2
xdx =
1
4
sinh(2x) +
1
2
x 35.
_
sech
2
xdx = tanh x,
36.
_
arcsinh
x
a
dx = xarcsinh
x
a

_
x
2
+a
2
, a > 0, 37
_
arctanh
x
a
dx = xarctanh
x
a
+
a
2
ln |a
2
x
2
|,
38.
_
arccosh
x
a
dx =
_
_
_
xarccosh
x
a

_
x
2
+a
2
, if arccosh
x
a
> 0 nd > 0,
xarccosh
x
a
+
_
x
2
+a
2
, if arcc h
x
a
< 0 and a > 0,
39.
_
dx

a
2
+x
2
= ln
_
x +
_
a
2
+x
2
_
, a > 0,
40.
_
dx
a
2
+x
2
=
1
a
arctan
x
a
, a > 0, 41.
_
_
a
2
x
2
dx =
x
2
_
a
2
x
2
+
a
2
2
arcsin
x
a
, a > 0,
42.
_
(a
2
x
2
)
3/2
dx =
x
8
(5a
2
2x
2
)
_
2
x
2
+
3a
4
8
arcsin
x
a
, a > 0,
43.
_
dx

a
2
x
2
= arcsin
x
a
, a > 0, 44.
_
dx
a
2
x
2
=
1
2a
ln

a +x
a x

, 45.
_
dx
(a
2
x
2
)
3/2
=
x
a
2

a
2
x
2
,
46.
_
_
a
2
x
2
dx =
x
2
_
a
2
x
2

a
2
2
ln

x +
_
a
2
x
2

, 47.
_
dx

x
2
a
2
= ln

x +
_
x
2
a
2

, a > 0,
48.
_
dx
ax
2
+bx
=
1
ln

x
a +bx

, 49.
_
x

a +bxdx =
2(3bx 2a)(a +bx)
3/2
15b
2
,
50.
_

a + x
x
dx = 2

a +bx +a
_
1
x

a +bx
dx, 51.
_
x

a +bx
dx =
1

2
ln

a +bx

a +bx +

, a > 0,
52.
_

a
2
x
2
x
dx =
_
a
2
x
2
a ln

a +

a
2
x
2
x

, 53.
_
x
_
a
2
x
2
dx =
1
3
(a
2
x
2
)
3/2
,
54.
_
x
2
_
a
2
x
2
dx =
x
8
(2x
2
a
2
)
_
a
2
x
2
+
a
4
8
arcsin
x
a
, a > 0, 55.
_
dx

a
2
x
2
=
1
a
ln

a +

a
2
x
2
x

,
56.
_
xdx

a
2
x
2
=
_
a
2
x
2
, 57.
_
x
2
dx

a
2
x
2
=
x
2
_
a
2
x
2
+
a
2
2
arcsin
x
a,
a > 0,
58.
_

a
2
+x
2
x
dx =
_
a
2
+x
2
a ln

a +

a
2
+x
2
x

, 59.
_

x
2
a
2
x
dx =
_
x
2
a
2
a arccos
a
|x|
, a > 0,
60.
_
x
_
x
2
a
2
dx =
1
3
(x
2
a
2
)
3/2
, 61.
_
dx
x

x
2
+a
2
=
1
a
ln

x
a +

a
2
+x
2

,
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
nn
__
cos cos

_ _
ot ot
nn 22
xdx, n xdx, n
= cosh = cosh x, x, 28. 28.
= arct n sinh = arct n sinh x, x,
sinh(2 sinh(2xx) + ) +
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
xx
37 37
__
xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
aa
>> 0 nd 0 nd >>
if arcc h if arcc h
xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
aa
<< 0 and 0 and
))
__
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
xx
22
++
33aa
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
, a > , a > 00,,
22
__
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
aa
22
xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22

aa
22
bx bx
==
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
ln ln

xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
aa ++bx bx

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
++ xx
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
xx
dx dx = 2 = 2

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
xx
22
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
dx dx
Theoretical Computer Science Cheat Sheet
Calculus Cont. Finite Calculus
62.
_
dx
x

x
2
a
2
=
1
a
arccos
a
|x|
, a > 0, 63.
_
dx
x
2

x
2
a
2
=

x
2
a
2
a
2
x
,
64.
_
xdx

x
2
a
2
=
_
x
2
a
2
, 65.
_

x
2
a
2
x
4
dx =
(x
2
+a
2
)
3/2
3a
2
x
3
,
66.
_
dx
ax
2
+bx +c
=
_

_
1

b
2
4ac
ln

2ax +b

b
2
4ac
2ax +b +

b
2
4ac

, if b
2
> 4ac,
2

4ac b
2
arctan
2ax +b

4ac b
2
, if b
2
< 4ac,
67.
_
dx

ax
2
+bx +c
=
_

_
1

a
ln

2ax +b + 2

a
_
ax
2
+bx +c

, if a > 0,
1

a
arcsin
2ax b

b
2
4ac
, if a < 0,
68.
_
_
ax
2
+bx +c dx =
2ax +b
4a
_
ax
2
+bx +c +
4ax b
2
8a
_
dx

ax
2
+bx +c
,
69.
_
xdx

ax
2
+bx +c
=

ax
2
+bx +c
a

b
2a
_
dx

ax
2
+bx +c
,
70.
_
dx
x

ax
2
+bx +c
=
_

_
1

c
ln

ax
2
+bx +c +bx + 2c
x

, i c > 0
1

c
arcsin
bx + 2c
|x|

b
2
4ac
, if c < 0,
71.
_
x
3
_
x
2
+a
2
dx = (
1
3
x
2

2
15
a
2
)(x
2
+a
2
)
3/2
,
72.
_
x
n
sin(ax) dx =
1
a
x
n
cos(ax) +
n
a
_
x
n1
os(ax) dx,
73.
_
x
n
cos(ax) dx =
1
a
x
n
sin(ax)
n
a
_
x
1
sin ax) dx,
74.
_
x
n
e
ax
dx =
x
n
e
ax
a

n
a
_
x
n1
e
ax
dx,
75.
_
x
n
ln(ax) dx = x
n+1
_
ln ax)
n + 1

1
(n + 1)
2
_
,
76.
_
x
n
(ln ax)
m
dx =
x
n+1
n + 1
(ln ax)
m

m
n + 1
_
x
n
(ln ax)
m1
dx.
Dierence, shift operators:
f(x) = f(x + 1) f(x),
Ef(x) = f(x + 1).
Fundamental Theorem:
f(x) = F(x)

## f(x)x = F(x) +C.

b

a
f(x)x =
b1

i=a
f(i)
Dierences:
(cu) = cu, (u v) = u + v,
(uv) = uv + Evu,
(x
n
) = nx
n1
(H
x
) = x
1
(2
x
) = 2
x
,
(c ) = ( 1)c
x
,
_
x
m
_
=
_
x
m1
_
.
Sums:

cux = c

ux,

(u +v) x =

ux +

v x,

uv x = uv

Evux,

x
n
x =
x
n+1
m+1
,

x
1
x = H
x
,

c
x
x =
c
x
c1
,
_
x
m
_
x =
_
x
m+1
_
.
Falling Factorial Powers:
x
n
= x(x 1) (x n + 1), n > 0,
x
0
= 1,
x
n
=
1
(x + 1) (x +|n|)
, n < 0,
x
n+m
= x
m
(x m)
n
.
Rising Factorial Powers:
x
n
= x(x + 1) (x +n 1), n > 0,
x
0
= 1,
x
n
=
1
(x 1) (x |n|)
, n < 0,
x
n+m
= x
m
(x +m)
n
.
Conversion:
x
n
= (1)
n
(x)
n
= (x n + 1)
n
= 1/(x + 1)
n
,
x
n
= (1)
n
(x)
n
= (x +n 1)
n
= 1/(x 1)
n
,
x
n
=
n

k=1
_
n
k
_
x
k
=
n

k=1
_
n
k
_
(1)
nk
x
k
,
x
n
=
n

k=1
_
n
k
_
(1)
nk
x
k
,
x
n
=
n

k=1
_
n
k
_
x
k
.
x
1
= x
1
= x
1
x
2
= x
2
+x
1
= x
2
x
1
x
3
= x
3
+ 3x
2
+x
1
= x
3
3x
2
+x
1
x
4
= x
4
+ 6x
3
+ 7x
2
+x
1
= x
4
6x
3
+ 7x
2
x
1
x
5
= x
5
+ 15x
4
+ 25x
3
+ 10x
2
+x
1
= x
5
15x
4
+ 25x
3
10x
2
+x
1
x
1
= x
1
x
1
= x
1
x
2
= x
2
+x
1
x
2
= x
2
x
1
x
3
= x
3
+ 3x
2
+ 2x
1
x
3
= x
3
3x
2
+ 2x
1
x
4
= x
4
+ 6x
3
+ 11x
2
+ 6x
1
x
4
= x
4
6x
3
+ 11x
2
6x
1
x
5
= x
5
+ 10x
4
+ 35x
3
+ 50x
2
+ 24x
1
x
5
= x
5
10x
4
+ 35x
3
50x
2
+ 24x
1
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m

ii c > c > 00
if if c < c <
11
os( os(ax ax)) dx, dx,
__
xx
11
sin sin ax ax))
__
nn11
ee
ax ax
dx, dx,
__
ln ln ax ax))
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
nn + 1 + 1

11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
((
dx dx ==
xx
nn+1 +1
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
nn + 1 + 1
(ln (ln ax ax
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11

ii==aa
ff((ii))
u, u, ( (u u vv) = ) =
uuvv ++ EEv vu, u,
) = ) = nx nx
nn
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11
( (HH
xx
HHH ) = ) = x x
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
( (c c
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
) = ( ) = (
Sums: Sums:

cux cux

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
xx
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
xx
22
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
xx
33
Theoretical Computer Science Cheat Sheet
Series
Taylors series:
f(x) = f(a) + (x a)f

(a) +
(x a)
2
2
f

(a) + =

i=0
(x a)
i
i!
f
(i)
(a).
Expansions:
1
1 x
= 1 +x +x
2
+x
3
+x
4
+ =

i=0
x
i
,
1
1 cx
= 1 +cx +c
2
x
2
+c
3
x
3
+ =

i=0
c
i
x
i
,
1
1 x
n
= 1 +x
n
+x
2n
+x
3n
+ =

i=0
x
ni
,
x
(1 x)
2
= x + 2x
2
+ 3x
3
+ 4x
4
+ =

i=0
ix
i
,
x
k
d
n
dx
n
_
1
1 x
_
= x + 2
n
x
2
+ 3
n
x
3
+ 4
n
x
4
+ =

i=0
i
n
x
i
,
e
x
= 1 +x +
1
2
x
2
+
1
6
x
3
+ =

i=0
x
i
i!
,
ln(1 +x) = x
1
2
x
2
+
1
3
x
3

1
4
x
4
=

i=1
(1)
i+
x
i
i
ln
1
1 x
= x +
1
2
x
2
+
1
3
x
3
+
1
4
x
4
+ =

i 1
x
i
i
sin x = x
1
3!
x
3
+
1
5!
x
5

1
7!
x
7
+ =

i=0
(1)
i
x
2i+1
(2i + 1)!
,
cos x = 1
1
2!
x
2
+
1
4!
x
4
6!
x
6
+ =

i=0
(1)
i
x
2i
(2i)!
,
tan
1
x = x
1
3
x
3
+
1
5
x
5

7
7
+ =

i=0
(1)
i
x
2i+1
(2i + 1)
,
(1 +x)
n
= 1 +nx +
n(n1)
2
x
2
+ =

i=0
_
n
i
_
x
i
,
1
(1 x)
n+1
= 1 + (n + 1)x +
_
n+2
2
_
x
2
+ =

i=0
_
i +n
i
_
x
i
,
x
e
x
1
= 1
1
2
x +
1
12
x
2

1
720
x
4
+ =

i=0
B
i
x
i
i!
,
1
2x
(1

1 4x) = 1 +x + 2x
2
+ 5x
3
+ =

i=0
1
i + 1
_
2i
i
_
x
i
,
1

1 4x
= 1 +x + 2x
2
+ 6x
3
+ =

i=0
_
2i
i
_
x
i
,
1

1 4x
_
1

1 4x
2x
_
n
= 1 + (2 +n)x +
_
4+n
2
_
x
2
+ =

i=0
_
2i +n
i
_
x
i
,
1
1 x
ln
1
1 x
= x +
3
2
x
2
+
11
6
x
3
+
25
12
x
4
+ =

i=1
H
i
x
i
,
1
2
_
ln
1
1 x
_
2
=
1
2
x
2
+
3
4
x
3
+
11
24
x
4
+ =

i=2
H
i1
x
i
i
,
x
1 x x
2
= x +x
2
+ 2x
3
+ 3x
4
+ =

i=0
F
i
x
i
,
F
n
x
1 (F
n1
+F
n+1
)x (1)
n
x
2
= F
n
x +F
2n
x
2
+F
3n
x
3
+ =

i=0
F
ni
x
i
.
Ordinary power series:
A(x) =

i=0
a
i
x
i
.
Exponential power series:
A(x) =

i=0
a
i
x
i
i!
.
Dirichlet power s ies:
A(x)

=1
i
i
x
.
Binomia theor m:
(x +y)
n
=
n

k=0
_
n
k
_
x
nk
y
k
.
Dierence of like powers:
x
n
y
n
= (x y)
n1

k=0
x
n1k
y
k
.
For ordinary power series:
A(x) +B(x) =

i=0
(a
i
+b
i
)x
i
,
x
k
A(x) =

i=k
a
ik
x
i
,
A(x)

k1
i=0
a
i
x
i
x
k
=

i=0
a
i+k
x
i
,
A(cx) =

i=0
c
i
a
i
x
i
,
A

(x) =

i=0
(i + 1)a
i+1
x
i
,
xA

(x) =

i=1
ia
i
x
i
,
_
A(x) dx =

i=1
a
i1
i
x
i
,
A(x) +A(x)
2
=

i=0
a
2i
x
2i
,
A(x) A(x)
2
=

i=0
a
2i+1
x
2i+1
.
Summation: If b
i
=

i
j=0
a
i
then
B(x) =
1
1 x
A(x).
Convolution:
A(x)B(x) =

i=0
_
_
i

j=0
a
j
b
ij
_
_
x
i
.
all the rest is the work of man.
Leopold Kronecker

ii=0 =0
aa
ii
ii
Dirichlet power s ies: Dirichlet power s ies:
AA
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m

=1 =1
((1) 1)
ii++
xx
ii
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
ii
==

ii 11
xx
ii
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
ii
++ ==

ii=0 =0
((
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
6! 6!
xx
66
++
++
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
55
xx
55

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
77
77
++
= 1 + = 1 +nx nx ++
nn((nn1) 1)
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
22
= 1 + ( = 1 + (nn + 1) + 1)
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
= 1 = 1
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11 44xx) = 1 + ) = 1 +
11
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
11 44xx
__
11

w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
((x x))

=1 =1
ii
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Binomia theor m: Binomia theor m:
((x x ++yy) )
nn
==
Dierence of like powers: Dierence of like powers:
x x
Theoretical Computer Science Cheat Sheet
Series Eschers Knot
Expansions:
1
(1 x)
n+1
ln
1
1 x
=

i=0
(H
n+i
H
n
)
_
n +i
i
_
x
i
,
_
1
x
_
n
=

i=0
_
i
n
_
x
i
,
x
n
=

i=0
_
n
i
_
x
i
, (e
x
1)
n
=

i=0
_
i
n
_
n!x
i
i!
,
_
ln
1
1 x
_
n
=

i=0
_
i
n
_
n!x
i
i!
, xcot x =

i=0
(4)
i
B
2i
x
2i
(2i)!
,
tan x =

i=1
(1)
i1
2
2i
(2
2i
1)B
2i
x
2i1
(2i)!
, (x) =

i=1
1
i
x
,
1
(x)
=

i=1
(i)
i
x
,
(x 1)
(x)
=

i=1
(i)
i
x
,
Stieltjes Integrat on
(x) =

p
1
1 p
x
,

2
(x) =

i=1
d(i)
x
i
where d(n) =

d|n
1,
(x)(x 1) =

i=1
S(i)
x
i
where S(n) =

d|n
d,
(2n) =
2
2n1
|B
2n
|
(2n)!

2n
, n N,
x
sin x
=

i=0
(1)
i1
(4
i
2)B
2i
x
2i
(2i)!
,
_
1

1 4x
2x
_
n
=

i=0
n(2i +n 1)!
i!(n +i)!
x
i
,
e
x
sin x =

i=1
2
i/2
sin
i
4
i!
x
i
,

1 x
x
=

i=0
(4i)!
16
i

2(2i)!(2i + 1)!
x ,
_
arcsin x
x
_
2
=

i=0
4
i
i
2
(i + 1)(2i + 1)!
x
2i
.
If G is continuous in the interval [a b] and F is nondecreasing then
_
b
G(x) dF(x)
exists. If a b c then
_
c
a
G(x) dF(x) =
_
b
a
G(x) dF(x) +
_
c
b
G(x) dF(x).
If the i egral involved exist
_
b
a
_
G(x) +H(x)
_
dF(x) =
_
b
a
G(x) dF(x) +
_
b
a
H(x) dF(x),
_
b
a
G(x) d
_
F(x) +H(x)
_
=
_
b
a
G(x) dF(x) +
_
b
a
G(x) dH(x),
_
b
a
c G(x) dF(x) =
_
b
a
G(x) d
_
c F(x)
_
= c
_
b
a
G(x) dF(x),
_
b
a
G(x) dF(x) = G(b)F(b) G(a)F(a)
_
b
a
F(x) dG(x).
If the integrals involved exist, and F possesses a derivative F

at every
point in [a, b] then
_
b
a
G(x) dF(x) =
_
b
a
G(x)F

(x) dx.
Cram rs R
00 47 18 76 29 93 85 34 61 52
86 11 57 28 70 39 94 45 02 63
95 80 22 67 38 71 49 56 13 04
59 96 81 33 07 48 72 60 24 15
73 69 90 82 44 17 58 01 35 26
68 74 09 91 83 55 27 12 46 30
37 08 75 19 92 84 66 23 50 41
14 25 36 40 51 62 03 77 88 99
21 32 43 54 65 06 10 89 97 78
42 53 64 05 16 20 31 98 79 87
Fibonacci Numbers
If we have equations:
a
1,1
x
1
+a
2
x
2
+ +a
1,n
x
n
= b
1
a
2,1
x
1
+a
2,2
x
2
+ +a
2,n
x
n
= b
2
.
.
.
.
.
.
.
.
.
a
n,1
x
1
+a
n,2
x
2
+ +a
n,n
x
n
= b
n
Let A = (a
i,j
) and B be the column matrix (b
i
). Then
there is a unique solution i det A = 0. Let A
i
be A
with column i replaced by B. Then
x
i
=
det A
i
det A
.
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, . . .
Denitions:
F
i
= F
i1
+F
i2
, F
0
= F
1
= 1,
F
i
= (1)
i1
F
i
,
F
i
=
1

5
_

i
_
,
Cassinis identity: for i > 0:
F
i+1
F
i1
F
2
i
= (1)
i
.
F
n+k
= F
k
F
n+1
+F
k1
F
n
,
F
2n
= F
n
F
n+1
+F
n1
F
n
.
Calculation by matrices:
_
F
n2
F
n1
F
n1
F
n
_
=
_
0 1
1 1
_
n
.
The Fibonacci number system:
Every integer n has a unique
representation
n = F
k1
+F
k2
+ +F
km
,
where k
i
k
i+1
+ 2 for all i,
1 i < m and k
m
2.
Improvement makes strait roads, but the crooked
William Blake (The Marriage of Heaven and Hell)
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Stieltjes Integrat on Stieltjes Integrat on
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
ii)! )!
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
2(2 2(2ii)!(2 )!(2ii + 1)! + 1)!
xx
=0 =0
44
ii
ii
22
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
((ii + 1)(2 + 1)(2ii + 1)! + 1)!
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
is continuous in the interval [ is continuous in the interval [a b a b] and ] and
__
bb
___
GG( (
bb cc then then
__
aa
___
GG((xx)) dF dF((xx) = ) =
If the i egral involved exist If the i egral involved exist
__
bb
aa
___
__
GG((
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
xx) + ) +
__
bb
GG
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
Cram rs R Cram rs R
w
w
w
.
e
x
a
m
r
a
c
e
.
c
o
m
If we have equations: If we have equations:
++aa
22
xx
22
++
,,11
xx
11
++aa
22,,22
xx
22
++
..
..
..
11
xx
11
++