350 views

1 Answer

1 1 vote
Time Complexity of $T(n) = 3T(n-1) + n$

The time complexity of the recurrence relation $T(n) = 3T(n-1) + n$ is $\Theta(3^n)$.

1. Expansion The recurrence is expanded repeatedly: * $T(n) = 3T(n-1) + n$

$T(n) = 3[3T(n-2) + (n-1)] + n = 3^2T(n-2) + 3(n-1) + n$

$T(n) = 3^2[3T(n-3) + (n-2)] + 3(n-1) + n = 3^3T(n-3) + 3^2(n-2) + 3(n-1) + n$

2. General Pattern After $k$ steps, the general form is: $$T(n) = 3^k T(n-k) + \sum_{i=0}^{k-1} 3^i (n-i)$$ 3. Solving for the Base Case Assuming a base case $T(0) = c$, we set $k=n$: $$T(n) = 3^n T(0) + \sum_{i=0}^{n-1} 3^i (n-i)$$ 4. Closed-Form Solution Solving the summation gives the exact closed-form solution: $$T(n) = \left(c + \frac{3}{4}\right) \cdot 3^n - \frac{n}{2} - \frac{3}{4}$$ The **dominant term** is proportional to $3^n$, so the final complexity is $\Theta(3^n)$.
• edited by
Position:
Show:

Related questions

0 0 votes
1 1 answer
346
346 views
vishnusainune asked Dec 30, 2025
346 views
A recurrence arises in the problem: Number of ways to tile a 3×n rectangle with 2×1 dominoes (dominoes can be placed vertically or horizontally). Let T(n)​ be this number...
3 3 votes
1 answers 1 answer
656
656 views
himanshu2001 asked Sep 29, 2024
656 views
Can Somebody help me solve these recurrences?What is the method generally employed to solve questions of this type?Taken from https://jeffe.cs.illinois.edu/teaching/algor...
2 2 votes
1 1 answer
610
610 views
jenilS7 asked Mar 18, 2024
610 views
What is the returned value by the given function below.Algo fun(n){ If(x<=2) return 1; Else { Return fun(n1/2) + n; }}Note : Assume that all...
1 1 vote
0 0 answers
1.5k
1.5k views
srestha asked May 19, 2019
1,488 views
Let $A(n)$ denotes the number of $n$ bit binary strings which have no pair of consecutive $1’s.$ what will be recurrence relation for it and what will be it’s Time Comple...