in Algorithms recategorized by
2,997 views
3 votes
3 votes

Consider the recurrence equation

$T(n) =\begin{cases}
2T(n-1), & \text{if }n>0 \\
1, & \text{otherwise}
\end{cases}$

Then $T(n)$ is (in $big\, O$ order)

  1. $O(n)$
  2. $O(2^n)$
  3. $O(1)$
  4. $O(\log n)$
in Algorithms recategorized by
by
3.0k views

4 Comments

T(n) = 2T(n-1), T(0) = 1

solving this linear homogenouss equaition we will get, $T(n)=2^{n}$

so it will be $O(2^{n})$
4
4
isro says O(1)
0
0

it should be O(2n) only, if it T(0) = 0, then it would be O(1)

1
1

Surely O(2n)

1
1

2 Answers

9 votes
9 votes
Best answer

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

$T(n)=2[2T(n-2)]=2^{2}T(n-2)$

$T(n)=2^{2}[2T(n-3)]= 2^{3}T(n-3)$

$T(n)=2^{k}T(n-k)$

$n-k=0, \ n=k,\ T(0)=1$

$T(n)=2^{n}$

Hence option B) is correct

selected by

4 Comments

They even didnt change this in the revised key...
0
0
Maybe because nobody submitted any grievance against it.
0
0
I think ISRO is correct. Because the time complexity depends on the workdone. so T(n) = 2T(n - 1) + 0 means with no time it can do that. So directlty we can say that T(n) = 2^n for example T(3) = 8 directly i can say.
0
0

 papujimmy no you are a little wrong that extra amount of work you are mentioning is not done in this recurrence, if it is not done or that work is less as compared to recurrence then that is not considered while calculating complexity.

0
0
1 vote
1 vote
just do  by substitution nd observation for saving tym

T(0)=1 given

T(1)=2 on putting

T(2)=2*2

T(3)=2*2*2

...............T(n)=2*2*2*2.............n tymes=2^n
Answer:

Related questions