# Solution to the recurrence T(n) = 2T(n − 3) [duplicate]

We were asked the following question in our exam:

Solve or bound the recurrence T(n) = 2T(n − 3) for n>3 provided T(1) = T(2) = T(3) = 1.

How do I go about solving this type of recurrence? For a normal recurrence of the form T(n) = 2T(n - 3) + cn, I would have considered cn to be the root and then solved the remainder of the tree. However, since the constant term is missing here, it means that the work done in each recursive call is 0. So, what would be the time complexity? Is my understanding incorrect?

Thanks for you help!

P.S.: This is not this, because this one has the constant term missing.

## marked as duplicate by David Richerby, Raphael♦Oct 10 '16 at 18:22

• "what would be the time complexity?" The time complexity of what? $T$ is just a mathematical function: it could be used to measure anything. – David Richerby Oct 10 '16 at 17:46
• @DavidRicherby, the time complexity of T. That function can literally apply to any (badly designed) algorithm. – user6490375 Oct 10 '16 at 17:53
• Functions don't have time complexity; it's the algorithm that has time complexity. (Analogous situation: a house may well be seven metres tall but the number seven does not have a height.) – David Richerby Oct 10 '16 at 17:58
• The contribution to the work at each level of your recursion tree is indeed zero except at the bottom level, where recursion no longer applies. At that level (namely, at the leaves), the contribution of each subproblem is 1 and there are $2^{k-1}$ such leaves, so, as the answer below implies, the total work done is $2^{n/3}-1$. Obviously, the same analysis holds if $n=3k+1$ or $n=3k+2$. – Rick Decker Oct 11 '16 at 0:51

It is easy to see the first nine terms of $\small T(n)$ is:
$$\small \begin{array}{|c|c|c|c|c|c|c|c|c|} \hline \color{red}{T(1)} & \color{blue}{T(2)} & \color{olive}{T(3)} & \color{red}{T(4)} & \color{blue}{T(5)} & \color{olive}{T(6)} & \color{red}{T(7)} & \color{blue}{T(8)} & \color{olive}{T(9)} \\ \hline 1 & 1 & 1 & 2 & 2 & 2 & 4 & 4 & 4 \\ \hline \end{array}$$
Observation: For integer $\small k \geq 0$, $\small T(3k+1) = T(3k+2) = T(3k+3)$. You can prove it by induction, where the base case is $\small T(1) = T(2) = T(3)= 1$.
Given $\small n$, let $\small k$ be the smallest integer with $\small 3k \geq n$. In other words, $\small k = \lceil n / 3\rceil$. By the observation above, $\small T(n) = T(3k)$. Therefore, we have $$\small T(n) = T(3k) = 2\cdot T(3(k-1)) = 2^2\cdot T(3(k-2)) = \cdots = 2^{k-1}T(3) = 2^{k-1} = 2^{\lceil n / 3\rceil - 1}$$