1.2 Mathematics Review
Exponents
http://baike.baidu.com/view/5711140.htm
Logarithms
http://en.wikipedia.org/wiki/Logarithm
Series
arithmetic series 等差数列:
Sn=n(a1+an)/2
geometric series 等比数列:
Sn=a1(1-q^n)/(1-q)=(a1-an*q)/(1-q)
http://baike.baidu.com/view/39749.htm
Modular Arithmatic
A is congruent to B modulo N, written A ≡ B (mod N), if N divides A - B.
e.g.
81 ≡ 61 ≡ 1 (mod 10)
The P Word
The two most common ways of proving statements in data structure analysis are proof by induction(归纳) and proof by contradiction(反证).
Induction
1. proving a base case
2. assume k works and prove k + 1 will work
Contradiction
Assuming that the theorem is false and showing that this assumption implies that some known property is false.
1.3 Recursion
A function defined in terms of itself is called recursive.
F(x) = 2F(x-1) + X
C allows functions to be recursive:
int F(int X)
{
// handle base case
if(X == 0)
return 0;
else
return 2*F(x - 1) + X;
}
Recursive calls will keep on being made until a base case is reached.
Fundamental rules of recursion:
1. Base case. You must always have some base cases, which can be solved without recursion.
2. Making progress. For the cases that are to be solved recursively, the recursive call must always be to a case that makes progress toward a base case.
3. Design rule. Assume that all the recursive calls work.
4. Compound interest rule. Never duplicate work by solving the same instance of a problem in separate recursive calls.