Algorithm Design and Analysis Course Review notes 2-- recursive relationship
Recursive relationship
Recurrence relation describes the function of a natural number
for some n> 0 is a function of the value, a value smaller than n by the function represented
Why should analyze recursive relationship?
Many algorithms, in particular, recursive algorithm, the time cost function can be used to describe a recursive relationship
Solution
- Replacement Act (Substitution)
- Recursive tree (Recursion Tree)
- Iterative method (Iteration)
- Master mode (Master Theorem)
Replacement
- I guess (experience, replacing the argument, by loosening tight)
- Verify conjecture for n = Correctness
- For the guess verification n> Correctness
example:T(n) = 2T(
n/2
) + n-
guess: T (n) = Θ (
is assumed to when n≥2
n/2
established,
namely T (
n/2
)≤c
n/2
lg(
n/2
)
T(n)= 2T(
n/2
) + n
≤2(c
n/2
lg(
n/2
)) + n-
≤cnlg (n-/ 2) + n-
= cnlgn-n-cnlg2 +
= cnlgn-CN + n-
≤cnlgn for c> 1
examples:
T(n) = 2T(n/2) +Θ(n) → T(n) = Θ(n lg n)
T(n) = 2T(
n/2
) + n → T (n) = Θ (n lg n)
T (n) = 2T (
n/2
+ 17) + n → T (n)
Recursive tree
Iterative method
- Expansion
- Algebraic operations
- Summing
example:
Main way
example:
a=9
b=3
f(n)=n
=
= Θ (N2)f
(N) = o (
) n-=
[epsilon] =. 1, a first satisfies the formula
Therefore, T (n) = Θ (
)
T(n)=Θ(
)
Key:
- Replacement Act (Substitution)
- Recursive tree (Recursion Tree)
- Iterative method (Iteration)
- Master mode (Master Theorem)
Reference: classroom teachers Professor Khoo Teck red courseware