Consider the recurrence equation
T(n) = 2T(n-1), if n>0 = 1, otherwise
Then T(n) is (in big O order)
(A) O(n) (B) O(2^n) (C) O(1) (D) O(log n)
My Try:
This has already asked here but there is no explanation. Using Substitution Method: $$T(n) = 2T(n−1)$$ $$= 2(2T(n−2)) = 2^2T(n-2)$$ $$= 2(2^2T(n−2)) = 2^3T(n-3)$$ $$....$$ $$= 2(2^{n-3}T(n−(n-2))) = 2^{n-2}T(n-(n-2))$$ $$= 2(2^{n-2}T(n−(n-1))) = 2^{n-1}T(n-(n-1)) = 2^{n-1}T(1) $$ $$= 2(2^{n-1}T(n−(n))) = 2^{n}T(n-(n)) = 2^{n}T(0) $$ $$T(n) = O(2^n)$$
This was from ISRO 2017 exam and official answer key is $O(1)$.
So, my question is that if there is two function calls with each $(n-1)$ each time, then how it can be $O(1)$?
There is another recurrence relation with little modification:
T(n) = 2T(n-1) - 1, if n>0 = 1, otherwise
AFAIK, it should be $O(2^n)$ again, but someone it explained as:
$$T(0) = 1 $$ $$T(1) = 2T(0)−1 = 1$$ $$T(2) = 2T(1)−1 = 1$$ $$T(3) = 2T(2)−1 = 1$$ $$T(4) = 2T(3)−1 = 1$$ $$...$$ So, $T(n) = 1$, for any value of n i.e. it remains constant. Time Complexity $= O(1)$.
I agreed with calculated values (but it should be $O(2^n)$ similar with this post).
Is there any difference between values and complexity?
If above logic will applied then $T(n) = 2T(n-1)$ will be $O(1)$, also $T(n) = 2T(n/2)$ will be $O(1)$ which is NOT correct, because it should be $O(n)$ according to Master theorem.
Could you please explain it?