Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE-CS-2004 | Question 90

  • Difficulty Level : Medium
  • Last Updated : 28 Jul, 2021

The recurrence equation

T(1) = 1
T(n) = 2T(n - 1) + n, n ≥ 2 

evaluates to

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

a. 2n + 1– n – 2
b. 2n – n
c. 2n + 1 – 2n – 2
d. 2n + n

(A) a
(B) b
(C) c
(D) d


Answer: (A)

Explanation: If draw recursion tree, we can notice that total work done is,
T(n) = n + 2(n-1) + 4(n-2) + 8(n-3) + 2n-1 * (n – n + 1)
T(n) = n + 2(n-1) + 4(n-2) + 8(n-3) + 2n-1 * 1



To solve this series, let us use our school trick, we multiply T(n) with 2 and subtract after shifting terms.

2*T(n) =     2n + 4(n-1) + 8(n-2) + 16(n-3) + 2n 
  T(n) = n + 2(n-1) + 4(n-2) + 8(n-3) + 2n-1 * 1

We get

2T(n) - T(n) =  -n + 2 + 4 + 8 + ..... 2n
T(n) = -n + 2n+1 - 2 [Applying GP sum formula for 2, 4, ...]
     = 2n+1 - 2 - n
Alternate Way to solve is to use hit and try method.
Given T(n) = 2T(n-1) + n and T(1) = 1

For n = 2, T(2) = 2T(2-1) + 2 
                = 2T(1) + 2 
                = 2.1 + 2 = 4

Now when you will put n = 2 in all options, 
only 1st option 2^(n+1) - n - 2 satisfies it. 


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!