GATE / CS ARCHIVE

SIMILAR QUESTIONS / ALGORITHMS

Unroll a doubling recurrence with a unit decrement

2 questions solved the same way, newest first. Back to Algorithms

How these are solved

Both produce or state T(n)=2T(n-1)+g(n). Unroll the recurrence (equivalently normalize by 2^n) and sum weighted nonrecursive costs.

1 mark · MCQ
Report issue

Solving an exponential recurrence by normalization

Asymptotic Analysis & Recurrences

Question 20, GATE 2025: T(0)=1 and T(n)=2T(n−1)+n·2^n for n>0. Which asymptotic order is correct? A Θ(n²2^n); B Θ(n2^n); C Θ((log n)²2^n); D Θ(4^n).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: Divide out the homogeneous growth factor 2n so that the remaining recurrence becomes a simple cumulative sum.
Define U(n)=T(n)/2n. Dividing the recurrence by 2n gives U(n)=T(n−1)/2n−1+n=U(n−1)+n, with U(0)=1. Repeated substitution yields U(n)=1+1+2+⋯+n=1+n(n+1)/2.
Therefore T(n)=2n[1+n(n+1)/2]. The bracket is a quadratic polynomial with positive leading coefficient, so it is Θ(n²). Multiplication by 2n gives Θ(n²2n), option A.
B overlooks the accumulation of n successive normalized contributions. C grows too slowly by replacing that quadratic sum with logarithms, and D is exponentially larger than the exact solution. A master theorem for T(n/b) is not the natural tool because this recurrence decreases n by one, rather than dividing it.

Original paper, page 20 · Answer key

2 marks · MCQ
Report issue

Cost of duplicated recursive calls

Asymptotic Analysis & Recurrences

Question 83, GATE 2004: For positive integer n, find the time complexity of:
int recursive(int n) {
  if(n==1) return 1;
  else return recursive(n-1)+recursive(n-1);
}
Use the ordinary execution model without memoization; the source prose says “a>0” although the code parameter is n.
Options:
(A) O(n)
(B) O(n log n)
(C) O(n²)
(D) O(2^n)
Question 83, GATE 2004: For positive integer n, find the time complexity of:
int recursive(int n) {
  if(n==1) return 1;
  else return recursive(n-1)+recursive(n-1);
}
Use the ordinary execution model without memoization; the source prose says “a>0” although the code parameter is n.
Options:
(A) O(n)
(B) O(n log n)
(C) O(n²)
(D) O(2^n)
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. For positive integer n, each nonbase invocation makes two independent calls at n−1. With the usual unit-cost model and no memoization, T(n)=2T(n−1)+Θ(1), T(1)=Θ(1).

2. The recursion tree has 2n−1 leaves and 2n−1 total calls, yielding Θ(2n), and hence D. The identical arguments do not make the two evaluations a single call in this abstract execution model; integer overflow and compiler transformations are outside the model.

3. Teaching check: At recursion depth k there are 2k calls, until depth n−1. Adding the geometric series gives 2n−1 calls. The depth is only n, but depth alone is not total work when the recursion branches.

Original paper, page 12