Algorithm Design and Analysis Course Review notes 2-- recursive relationship

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

  1. I guess (experience, replacing the argument, by loosening tight)
  2. Verify conjecture for n = n 0 n_0 Correctness
  3. For the guess verification n> n 0 n_0 Correctness

example:T(n) = 2T( \ lfloor n/2 \rfloor ) + n-
guess: T (n) = Θ (
is assumed to when n≥2 \ lfloor n/2 \rfloor established,
namely T ( \ lfloor n/2 \rfloor )≤c \ lfloor n/2 \rfloor lg( \ lfloor n/2 \rfloor )

T(n)= 2T( \ lfloor n/2 \rfloor ) + n
≤2(c \ lfloor n/2 \rfloor lg( \ lfloor n/2 \rfloor )) + 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( \ lfloor n/2 \rfloor ) + n → T (n) = Θ (n lg n)
T (n) = 2T ( \ lfloor n/2 \rfloor + 17) + n → T (n)

Recursive tree

Recursive tree

Iterative method

  1. Expansion
  2. Algebraic operations
  3. Summing

example:
T ( n ) = { c   a T ( n b ) + c n   T(n)=\left\{ \begin{aligned} c n=1\\ aT(\frac nb)+cn n>1 \end{aligned} \right.

T ( n ) = { Θ ( n )   Θ ( n l o g b n )   Θ ( n l o g b a )   T(n)=\left\{ \begin{aligned} Θ(n) a<b\\ Θ(nlog_bn)  a=b\\ Θ(n^{log_ba}) a>b\\ \end{aligned} \right.

Main way

Main way
example:
T ( n ) = 9 T ( n / 3 ) + n T (n) = 9T (n / 3) + n
a=9
b=3
f(n)=n

n l o g b a n ^ {} log_ba = n l o g 3 9 n^{log_39} = Θ (N2)f
(N) = o ( n l o g 3 9 ε n ^ {log_39-e} ) n-=
[epsilon] =. 1, a first satisfies the formula

Therefore, T (n) = Θ ( n l o g b a n ^ {} log_ba )
T(n)=Θ( n 2 n^2 )

Key:

  • Replacement Act (Substitution)
  • Recursive tree (Recursion Tree)
  • Iterative method (Iteration)
  • Master mode (Master Theorem)

Reference: classroom teachers Professor Khoo Teck red courseware

Published 25 original articles · won praise 19 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42605042/article/details/89603933