algorithm - How to solve: T(n) = T(n/2) + T(n/4) + T(n/8) + (n) -
i know how recurrence relations algorithms call once, i'm not sure how calls multiple times in 1 occurrence.
for example:
t(n) = t(n/2) + t(n/4) + t(n/8) + (n)
use recursion tree. see last example of recursion tree @ clrs "intro algorithm".
t(n) = t(n/2) + t(n/4) + t(n/8) + n. root n(cost) & divided 3 recursions. recursion tree looks follows:
t(n) = n = n t(n/2)t(n/4)t(n/8) (n/2) (n/4) (n/8) t(n/4)t(n/8)t(n/16) t(n/8)t(n/16)t(n/32) t(n/16)t(n/32)t(n/64)
n---------------------------------> n (n/2) (n/4) (n/8)--------------> (7/8)n n/4 n/8 n/16 n/8 n/16 n/32 n/16 n/32 n/64)--------> (49/64)n ... longest path: leftmost left branch = n -> n/2 -> n/4 -> ... -> 1
shortest branch: rightmost right branch = n -> n/8 -> n->64 -> ... -> 1
the number of leaves (l): 3^log_8(n) < l < 3^log_2(n) => n^0.5 < l < n^1.585
look @ tree - upto log_8(n) levels tree full, , go down, more & more internal nodes absent. theory can give bound,
t(n) = big-oh (summation j=0 log_2(n)-1 (7/8)^j n) = ... => t(n) = o(n). t(n) = big-omega (summation j=0 log_8(n)-1 (7/8)^j n) = ... => t(n) = big-omega(n).
therefore, t(n) = theta(n).
here points are: t(n/2) path has highest length...
this must not complete ternary tree ... height = log base 2 of n & # of leaves must less n ...
hope, way u can solve prob.
Comments
Post a Comment