Professional Documents
Culture Documents
Jaehyun Park
CS 97SI
Stanford University
Outline
Algebra
Number Theory
Combinatorics
Geometry
Algebra
Sum of Powers
n
X
k2 =
k=1
k3 =
1
n(n + 1)(2n + 1)
6
X 2
Memorize above!
Algebra
2
1
n(n + 1)
2
Fast Exponentiation
Recursive computation of an :
an =
Algebra
(an/2 )2
a(a(n1)/2 )2
n=0
n=1
n is even
n is odd
Implementation (recursive)
Algebra
Implementation (non-recursive)
Algebra
Linear Algebra
Invert a matrix
Algebra
Outline
Algebra
Number Theory
Combinatorics
Geometry
Number Theory
gcd(a, b) = gcd(a, b a)
gcd(a, 0) = a
gcd(a, b) is the smallest positive number in {ax + by | x, y Z}
Number Theory
Euclidean Algorithm
= gcd(255, 102)
= gcd(51, 0)
= 51
Number Theory
10
Implementation
Number Theory
11
Number Theory
12
Multiplicative Inverse
Number Theory
13
Exercise: implementation!
Number Theory
14
Number Theory
15
Outline
Algebra
Number Theory
Combinatorics
Geometry
Combinatorics
16
Binomial Coefficients
n
is the number of ways to choose k objects out of n
k
distinguishable objects
same as the coefficient of xk y nk in the expansion of
(x + y)n
Hence the name binomial coefficients
Combinatorics
17
n
k
n(n 1) (n k + 1)
k!
Combinatorics
18
Fibonacci Sequence
Definition:
F0 = 0, F1 = 1
Fn = Fn1 + Fn2 , where n 2
Combinatorics
19
Closed Form
Fn = (1/ 5)(n n )
= (1 + 5)/2
= (1 5)/2
5 are irrational
Combinatorics
20
"
Fn+1
Fn
"
1 1
1 0
#"
Fn
Fn1
"
1 1
1 0
#n "
F1
F0
Combinatorics
21
Outline
Algebra
Number Theory
Combinatorics
Geometry
Geometry
22
Geometry
Geometry
23
No hacks!
In most cases, randomization, probabilistic methods, small
perturbations wont help
Geometry
24
2D Vector Operations
Counterclockwise rotation by :
"
cos sin
sin cos
x2 + y 2
#"
x
y
Geometry
25
Line-Line Intersection
a b
d e
#"
x
y
"
c
f
a b
d e
#1
1
=
ae bd
"
e b
d a
Memorize this!
Edge case: ae = bd
The lines coincide or are parallel
Geometry
26
Circumcircle of a Triangle
Geometry
27
Area of a Triangle
Cross product:
x
(x1 , y1 ) (x2 , y2 ) = 1
y1
x2
y2
= x1 y2 x2 y1
Geometry
28
Geometry
29
Conclusion
Geometry
30