MIT 算法导论(三) Recurrence Solution

There are 3 methods to work out a Recurrence.

 

Substitution method.

Steps:

  • Guess the result.
  • Prove it by induction.

Ex:  T(n) = 4T(n/2) + n

  • [Assume that T(1) = Θ(1)]
  • Guess O(n3) . (Prove O and Ω separately.)
  • Assume that T(k) ≤ ck3 for k < n .
  • Prove T(n) ≤ cn3 by induction.

 

T (n) = 4T (n / 2) + n
  ≤ 4c ( n / 2 ) 3 + n
  = ( c / 2) n 3 + n
  desired – residual
  = cn3 − ((c / 2)n3 − n)
  ≤ cn3
  whenever (c/2)n3 – n ≥ 0, for example,
  if c ≥ 2 and n ≥ 1.
  residual

We first guess the result of a recurrence, and replace T(f(n)) with the result, and then just try to get the result.

 

Recursion-tree method

  • A recursion tree models the costs (time) of a recursive execution of an algorithm.
  • The recursion tree method is good for generating guesses for the substitution method.
  • The recursion-tree method can be unreliable, just like any method that uses ellipses (...).
  • The recursion-tree method promotes intuition, however.

Steps:

  • Expond the recurrence into levels,like a tree.The body of the tree is some kind of f(n) while leaves are constant.
  • Sum every node by level, and sum these level results then we get what we want.

 

Master method:

The master method applies to recurrences of the form

        T(n) = a T(n/b) + f (n) 

where a ≥ 1, b > 1, and f is asymptotically positive.

Three common cases:

1. f (n) = O(n^(logba – ε)) for some constant ε > 0.
Solution: T(n) = Θ(nlogba) .

2. f (n) = Θ(n^(logba) lgkn) for some constant k ≥ 0.
Solution: T(n) = Θ(n^(logba) lgk+1n) .

3. f (n) = Ω(n^(logba + ε)) for some constant ε > 0. and f (n) satisfies the regularity condition that a f (n/b) ≤ c f (n) for some constant c < 1.
Solution: T(n) = Θ( f (n)) .

 

The master method is theory,just use it a lot.

posted on 2012-09-02 19:21 我是正常蛇 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/louis-sherren/archive/2012/09/02/recurrence-solution.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值