Solving a recurrence: T(n)=3T(n/2)+n

后端 未结 4 1831
星月不相逢
星月不相逢 2021-01-07 05:09

I need to Find the solution of the recurrence for n, a power of two if T(n)=3T(n/2)+n for n>1 and T(n)=1 otherwise.

using substitution of n=2^m,S(

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 05:53

    You can solve this using Masters theorem, but also by opening the recursion tree in the following way:

    • At the root of the recursion tree, you will have a work of n.
    • In the second stage, the tree splits into three parts, and in each part, the work will be n / 2.
    • Keep going until you reach the leaves. The entire work leaf will be: O (1) = O (n / 2 ^ k) when: n = 2 ^ k.
    • Note that at each step m have 3 ^ m splits.
    • Now we'll combine all the steps together, using the geometric progression and logarithms rules. In the end, you will get: T(n) = 3T(n/2)+n = 2n^(log3)-2n the calculation

提交回复
热议问题