Consider the following recurrence relation for a function T(n):T(n) = 3T(n/2) + nUse the recursion tree method to determine the time complexity of T(n)
Question
Consider the following recurrence relation for a function T(n):
Use the recursion tree method to determine the time complexity of T(n).
Solution
Sure, let's solve this step by step:
-
First, let's draw the recursion tree for the given recurrence relation T(n) = 3T(n/2) + n. The root of the tree is T(n) and it has 3 children T(n/2), T(n/2), and T(n/2). Each of these children will have their own children and so on.
-
The cost at the root of the tree is n. The cost at the next level is 3*(n/2) because there are 3 nodes each with cost n/2. The cost at the third level is 3^2*(n/4) because there are 3^2 nodes each with cost n/4. This pattern continues for all levels of the tree.
-
The height of the tree is log base 2 of n because each level we are dividing n by 2.
-
The total cost of the tree is the sum of the costs at all levels. This is n + 3*(n/2) + 3^2*(n/4) + ... + 3^(log base 2 of n)(n/n) = n(1 + 3/2 + (3/2)^2 + ... + (3/2)^(log base 2 of n)).
-
The sum inside the parentheses is a geometric series with ratio 3/2 and log base 2 of n terms. The sum of a geometric series is (1 - r^k)/(1 - r) where r is the ratio and k is the number of terms. Substituting r = 3/2 and k = log base 2 of n we get (1 - (3/2)^(log base 2 of n))/(1 - 3/2).
-
Simplifying the above expression we get (2^n - 3^n)/(-1/2) = 23^n - 22^n.
-
Therefore, the time complexity of T(n) is O(3^n) because the term 3^n dominates 2^n for large n.
Similar Questions
Consider the following recurrence relation: T(n)=3T(n/3)+n2/3,T(1)=1,T(0)=0 What is the complexity of T(n)? Options : Θ(n) Θ(nlogn) Θ(n^2/3) Θ(n^1.5)
Explain master theorem and solve the recurrence T(n)=9T(n/3)+n with master method.
What is the space complexity of the recursive implementation used to find the nth fibonacci term? O(1)O(n) O(n2) O(n3)
Which of the given options provides the increasing order of complexity of functions f1, f2, f3 and f4:f1(n) = 2^nf2(n) = n^(3/2)f3(n) = nLognf4(n) = n^(Logn)
Consider this recurrence relation: T(1) = 1 T(n) = 2 T(n/3) + 2n + 1 for n>1 The Master Theorem says that T(n)∈ Θ()?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.