【问题标题】:Solving a Recurrence relation without iteration无需迭代即可求解递归关系
【发布时间】:2016-10-13 07:56:28
【问题描述】:

我该如何解决这个问题?

T(n) = T(n/4) + T(3n/4) + cn

Ans 是 \theta(nLogn)

如何使用主定理或任何其他有效方法来实现这个答案?

【问题讨论】:

  • 是的,有。生成函数。对于Stack Overflow 来说它太宽泛了。在维基百科上谷歌它。它对该主题进行了很好的介绍。
  • 我们可以在这里使用主定理吗?
  • @RohitRoy 不行,这里不能使用主定理,这里最好使用递归树。

标签: recursion time-complexity recurrence big-theta


【解决方案1】:

给定递归的递归树将如下所示:

                                Size                        Cost

                                 n                           n
                               /   \
                             n/4   3n/4                      n
                           /   \     /    \
                        n/16  3n/16 3n/16  9n/16             n

                        and so on till size of input becomes 1

从根到叶的最长简单路径是 n-> 3n/4 -> (3/4) ^2 n .. 直到 1

 Therefore  let us assume the height of tree = k

            ((3/4) ^ k )*n = 1 meaning  k = log to the base 4/3 of n

 In worst case we expect that every level gives a cost of  n and hence 

        Total Cost = n * (log to the base 4/3 of n)

 However we must keep one thing in mind that ,our tree is not complete and therefore

 some levels near the bottom would be partially complete.

 But in asymptotic analysis we ignore such intricate details.

 Hence in worst Case Cost = n * (log to the base 4/3 of n)

          which  is O( n * log n )

现在,让我们使用替换方法验证这一点:

 T(n) =  O( n * log n)  iff T(n) < = dnlog(n) for some d>0

 Assuming this to be true:

 T(n) = T(n/4) + T(3n/4) + n

      <= d(n/4)log(n/4) + d(3n/4)log(3n/4) + n

       = d*n/4(log n  - log 4 )  + d*3n/4(log n  - log 4/3) + n

       = dnlog n  - d(n/4)log 4 - d(3n/4)log 4/3  + n

       = dnlog n  - dn( 1/4(log 4)  -  3/4(log 4/3)) + n

       <= dnlog n

       as long as d >=  1/( 1/4(log 4)  -  3/4(log 4/3) )

【讨论】:

  • 很好的解释,但是为什么我们不能在这里使用 master 呢?在最坏的时间复杂度的情况下,该方程可以重写为 T(n) = 2T(3n/4) + cn。然后我们可以使用master
  • @MohitKumar 您将如何将给定的重复转换为三种情况中的任何一种?这就是为什么。
  • 可能不是这样
猜你喜欢
  • 2015-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-18
  • 2021-08-08
  • 1970-01-01
  • 2011-11-08
  • 1970-01-01
相关资源
最近更新 更多