in Algorithms edited by
17,462 views
47 votes
47 votes

The recurrence equation
$ T(1) = 1$
$T(n) = 2T(n-1) + n, n \geq 2$

evaluates to

  1. $2^{n+1} - n - 2$
  2. $2^n - n$
  3. $2^{n+1} - 2n - 2$
  4. $2^n + n $
in Algorithms edited by
17.5k views

3 Comments

Initial equation should be T(0)=1 not T(1) =1.
0
0
what role does the condition given play that n>=2 ?
0
0

@Arjunsir @GO Classes does this recurrence fail the regularity condition? 

0
0

7 Answers

64 votes
64 votes
Best answer
$T(n) = 2T(n-1) +n, n \geqslant 2 , T(1) = 1$

$  T(n)    = n + 2(n-1) + 2^2 (n-2) + \dots + 2^{(n-1)}(n -(n-1))$

           $=n( 1 + 2 + \dots + 2^{n-1}) - (1.2 + 2.2^{2} +3.2^{3}+\dots+ (n-1).2^{n-1})$

           $=n(2^n-1) -(n.2^n-2^{n+1}+2)$

           $=2^{n+1}-n -2$

Correct Answer: $A$
edited by
by

4 Comments

any one can tell me what is time complexity exist it  i.e. O(?)
0
0

any one can tell me what is time complexity exist it  i.e. O(?)

it is O(2^n). 

0
0

@shankargadri yes we can do like that , it’s time saver !!

0
0
105 votes
105 votes
T(1) = 1

T(2) = 4

T(3) = 11

T(4) = 26

T(5) = 57

T(6) = 120

T(7) = 247

So, $$T(n) = 2^{n+1} - n - 2$$
by

10 Comments

nice trick :)
4
4
excellent trick bro
1
1
Smart method
2
2
is it required that we go till 7 value i put n=2 and get 4 then check ans which gave me 4 by putting n=2 only A option satisfied it..
2
2

@Arjun

sir by applying muster theorem or subtract and conquer master theorem

ans comes out to be proportional to n*(2^n) .

Why it's far different from actual answer ?  Do muster theorem has any condition where it fails ?

Plz help.

2
2

EXCELLENT !!

Does this technique works for every recurrence relation ?

1
1
Yes, if options are given
1
1

@ same doubt do you got any answer?

0
0
Yeah , mine is same doubt, if you got any answer plz let me know.
0
0
very nice trick sir...
0
0
29 votes
29 votes
Given that T(1) =1 //OMG here itself Option C & D fails now check A & B

T(2)=2T(1)+n=2+2=4 //Option B evaluates to 2 so it is wrong

Hence option A is ans.

2 Comments

Nice reasoning for option C and D! Found useful!
1
1
Quickest way to solve this problem.
0
0
12 votes
12 votes

solution .

4 Comments

this is what i was looking for ,, thanx buddy :)
1
1
@varun singh

you have written

T(n-k) = 2T(n-(k-1)) + (n-k)

so  for k=2

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

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

so it should be

T(n-k) = 2T(n-(k+1)) + (n-k)

please look into it and if i am wrong please do correct me.
2
2
Yes @pramodborana112 u are right ,  it should be T(n-k) = 2T(n-(k+1)) + (n-k), but everything else are correct.
1
1
I think  there would be change in arithmetric geometric expression  then as k =n-2 then in that case  how would we solve
0
0
Answer:

Related questions