Professional Documents
Culture Documents
Jaehyun Park
CS 97SI
Stanford University
Algebra
Number Theory
Combinatorics
Geometry
Algebra 2
Sum of Powers
n
1
k2 =
X
n(n + 1)(2n + 1)
k=1
6
2
1
X 2
k3 =
X
k = n(n + 1)
2
Algebra 3
Fast Exponentiation
Recursive computation of an :
1 n=0
a
n=1
an =
(an/2 )2 n is even
a(a(n1)/2 )2
n is odd
Algebra 4
Implementation (recursive)
Algebra 5
Implementation (non-recursive)
Algebra 6
Linear Algebra
Algebra 7
Outline
Algebra
Number Theory
Combinatorics
Geometry
Number Theory 8
Greatest Common Divisor (GCD)
Number Theory 9
Euclidean Algorithm
Number Theory 11
Congruence & Modulo Operation
Number Theory 12
Multiplicative Inverse
Number Theory 13
Extended Euclidean Algorithm
Number Theory 14
Chinese Remainder Theorem
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
Appears everywhere in combinatorics
Combinatorics 17
Computing Binomial Coefficients
Combinatorics 18
Fibonacci Sequence
Definition:
F0 = 0, F1 = 1
Fn = Fn1 + Fn2 , where n 2
Appears in many different contexts
Combinatorics 19
Closed Form
Fn = (1/ 5)(n n )
= (1 + 5)/2
= (1 5)/2
Bad because and 5 are irrational
Cannot compute the exact value of Fn for large n
There is a more stable way to compute Fn
... and any other recurrence of a similar form
Combinatorics 20
Better Closed Form
Combinatorics 21
Outline
Algebra
Number Theory
Combinatorics
Geometry
Geometry 22
Geometry
Geometry 23
When Solving Geometry Problems
Geometry 24
2D Vector Operations
Geometry 25
Line-Line Intersection
Memorize this!
Edge case: ae = bd
The lines coincide or are parallel
Geometry 26
Circumcircle of a Triangle
Geometry 27
Area of a Triangle
Geometry 28
Area of a Simple Polygon
Geometry 29
Conclusion
Geometry 30