Steps:
- Formulate the problem precisely
- Design an algorithm
- Prove the algorithm is correct
- Analyze its runtime
Algothrm design techniques:
Complexity:
- An algorithm is efficient if its running time is a polynomial in the input size T
- The running time is upper bounded by c.Td for some constants c,d>0
- ex: brute force can solve Gale Shapley Algorithm in n!
- 2 main complexities:
Algorithm’s running time:
- To measure a Efficient Algorithm
- f(n) is asymptotically bounded by g(n)
- Propositions:
- if n→∞limg(n)f(n)=c for some constant c>0 then f(n)=Θ(g(n))
- Proof: c−ϵ≤g(n)f(n)≤c+ϵ by definition
- (c−ϵ)g(n)≤f(n)≤(c+ϵ)g(n)
- by definition of Big Theta notation, it is true
- if n→∞limg(n)f(n)=0 then f(n)=O(g(n))
- if n→∞limg(n)f(n)=∞ then f(n)=Ω(g(n))
- To find which notation a function belongs to, do g(n)f(n)
Some classes of function:
- Polynomials:
- f(n)=∑k=0daknk=O(nd),ad>0
- as n→∞limndf(n)=ad>0
- Logarithms:
- loga(n)=Θ(logbn) for every a>1 and b>1
- as n→∞limlogbnlogan=logba1=c
- Logarithms and Polynomials:
- logan=O(nd) for every a>1 and every d>0
- as n→∞limndlogan=0
- Exponentials:
- nd=O(rn) for every r>1 and every d>0
- as n→∞limrnnd=0
- Factorials: