我该如何解决这个问题?
T(n)= T(n / 4)+ T(3n / 4)+ cn
Ans是\ theta(nLogn)
如何使用主定理或任何其他有效方法来实现这个答案?
答案 0 :(得分:2)
给定递归的递归树将如下所示:
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) )