Defining something (function, algorithm, set, etc.) as a function of itself.
Lame's Theorem
Let a,b∈Z such that a≥b>0. Euclid's algorithm performs O (logb) divisions.
Binary Tree
A binary tree is defined recursively by:
an isolated node r is a binary tree with root r
Let T1 be a binary tree with root r1
Let T2 be a binary tree with root r2
the graph obtained by adding the edges {r,r1} and {r,r2} is a binary tree with root r.
Height h(T) of a binary tree T:
h(T) = 0 if T is an isolated node, else 1+ max(h(T1),h(T2))
Size n(T) of a binary tree T:
n(T) = 0 if T is an isolated node, else 1+n(T1)+n(T2)
n(T)≤2h(T)+1−1
Recursive Algorithms
Divide and Conquer Approach
To solve a problem of size n:
divide the problem in sub problems of size < n.
conquer, solve each sub problem recursively.
combine (merge) the solutions of sub problems to obtain a solution for the original problem.
General structure
For an input x:
def algo(x):
if(x =="sufficiently small"):
// resolve the problem with brute force and resolve the problem
else:
// decompose x into sub problems x1, x2, x3, ... , xL
// do:
y1 =algo(x1)
y2 =algo(x2)
// ...
y3 =algo(xL)
// combine y1, y2, ... yL into a solution y for x
return y
Solving linear recurrence relations
Linear homogenous recurrence
an=c1⋅an−1+c2⋅an−2+...+ck⋅an−k a0=x0 a1=x1
... ak−1=xk−1
where ci∈R(1≤i≤k),ck=0,xi∈R(0≤i≤k)
Theorem For Degree Two
Let c1,c2∈R. Suppose that r2−c1r−c2=0 has two distinct roots r1 and r2. Then an is a solution of an=c1an−1+c2an−2, if and only if an=α1⋅r1n+α2⋅r2n, where α1 and α2 are constants.
Let c1,c2∈R. Suppose that r2−c1r−c2=0 has a single root r0. So an is a solution of an=c1an−1+c2an−2, if and only if an=α1⋅r0n+α2⋅n⋅r0n, where α1 and α2 are constants.
So α1=1
and 6=3+3⋅α2 from which α2=1
Thus, an=3n+n⋅3n=(n+1)⋅3n
Theorem For Any Degree
Let c1,c2∈R. Suppose that r2−c1r−c2−...−ck=0 has two distinct roots r1, r2, ..., rk. Then an is a solution of an=c1an−1+c2an−2+ckan−k, if and only if an=α1⋅r1n+α2⋅r2n+...+αk⋅rkn, where α1, α2, ... , αk are constants.
Example
an=6an−1−11an−2+6an−3 a0=2a1=5a1=15
Characteristic equation: r3−6r2+11r−6=0
There exists a general formula for degree 3, but we will restrict ourselves to ones that factorize easily. 0,±1,±2 will be used as roots to help factorize.
r=1 is a root for the characteristic equation above.
Therefore we can factorize and get
Characteristic equation: (r−1)(r−3)(r−2)
So we get roots: 1, 2, 3
where ci∈R(1≤i≤k),ck=0,F(n) is a function depending only on n.
Theorem
If anp is an arbitrary particular solution of (*) an=c1⋅an−1+c2⋅an−2+...+ck⋅an−k+F(n), then all solutions of (*) are of the form anp+anh, where anh is a solution to the associated homogenous recurrence.
Example
an=3an−1+2n a1=3 anh=α⋅3n is the solution of the homogenous part
Now we need a particular solution for an=3an−1+2n. Since F(n)=2n is linear ... let's try a particular solution of the form anp=c⋅n+d. We must guess!
c⋅n+d=3(c(c⋅(n−1)+d))+2n c⋅n+d=(3c+2)⋅n+(−3c+3d)
So c=3c+2,d=−3c+3d, c=−1 and d=−3/2=−n−3/2+α⋅3n
3=a1=−1−3/2+α⋅3n=3α−5/2 α=11/6
an=−n−3/2+11/6⋅3n
Theorem
Let an=c1an−1+c2an−2+...+ckan−k+F(n), where c1,c2,...,ck∈R with ck=0 and F(n)=(btnt+bt−1nt−1+...+b1n+b0)sn, where b0,b1,...,bt,s∈R with bt=0 and s=0.
Assume that s is not a root of the characteristic equations of the associated linear homogenous recurrence relation. Then there is a particular solution an(p) of the form:
(ptnt+pt−1nt−1+...+p1n+p0)sn
Otherwise, s is a root of the characteristic equation of the associated linear homogeneous recurrence relation. Assume that s is a root with multiplicity m. Then there is a particular solution an(p) of the form:
nm(ptnt+pt−1nt−1+...+p1n+p0)sn
Solving non-linear recurrence relations
Theorem
Let f be a monotonically increasing function such that f(n)=af(n/6)+c, where a≥1,b∈Z(b>1),c>0.
Then f(n)=O(nlogb(a)) if a>1 else Olog(n) if a=1.
Monotonically increasing means its just increasing, just a fancy way of saying it.
Master Theorem
Let f be a monotonically increasing function such that f(n)=af(n/b)+c⋅nd, where a≥1,b∈Z(b>1),c>0,d>0.
Then, f(n)=O(nd) if d>logba else Olog(nd⋅logn) if d=logba else O(nlogb(a)) if d<logba.