How to solve the recursive complexity T(n) = T(n/4)+T(3n/4)+cn

旧巷老猫 提交于 2019-12-05 22:12:11

Think of it this way: for the first log4 n layers of the recursion tree, the sum of the work across those layers will be cn, because if you sum up the total sizes of all the subproblems, it should total n so the total work is cn. This means that the work done is Ω(n log n).

You can upper-bound the work done by pretending that the sum of the work done in each layer of the tree is O(n) (it actually drops off as you go lower and lower in the tree, so this is an upper bound) and the height is log4/3 n. This gives an upper bound on the work of O(n log n).

Since the work done is Ω(n log n) and O(n log n), the work done is more properly Θ(n log n).

Hope this helps!

Edited: Was missing the OP and answered a wrong solution, below is my refined attempt

Intuitively, You are right.

For a more formal approach, you can proof it mathematically.

The magic trick is here: Akra-Bazzi theorem which is a more general version of master theorem

For the relation T(n) = T(n/4) + T(3n/4) + cn

We got g(n) = cn, k = 2, a1 = a2 = 1, b1 = 1/4, b2 = 3/4

By the theorem, we have to solve p for a1b1^p + a2b2^p = 1 which is obviously p = 1

Then T(n) = O(n^p * (1+integration(1/n dn))) = O(n*(1+log(n))) = O(nlogn)

which match our guess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!