Knowee
Questions
Features
Study Tools

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):

T(n)=3T(n2)+n T(n) = 3T\left(\frac{n}{2}\right) + n

Use the recursion tree method to determine the time complexity of T(n).

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, let's solve this step by step:

  1. 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.

  2. 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.

  3. The height of the tree is log base 2 of n because each level we are dividing n by 2.

  4. 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)).

  5. 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).

  6. Simplifying the above expression we get (2^n - 3^n)/(-1/2) = 23^n - 22^n.

  7. Therefore, the time complexity of T(n) is O(3^n) because the term 3^n dominates 2^n for large n.

This problem has been solved

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)∈ Θ()?

1/2

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.