在没有迭代的情况下求解递归关系(Solving a Recurrence relation without iteration)

编程入门 行业动态 更新时间:2024-10-24 18:17:16
在没有迭代的情况下求解递归关系(Solving a Recurrence relation without iteration)

我该如何解决这个问题?

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

Ans是\ theta(nLogn)

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

How do I Solve this ?

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

Ans is \theta(nLogn)

How this answer can be achieved using master theorem or any other effecient method?

最满意答案

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

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) )

The recursion tree for the given recursion will look like this:

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

The longes simple path from root to a leaf would be n-> 3n/4 -> (3/4) ^2 n .. till 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 )

Now, let us verify this using substitution method:

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) )

更多推荐

本文发布于:2023-08-05 07:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   情况下   迭代   关系   relation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!