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.

  • 1
    $\begingroup$ "what would be the time complexity?" The time complexity of what? $T$ is just a mathematical function: it could be used to measure anything. $\endgroup$ – David Richerby Oct 10 '16 at 17:46
  • $\begingroup$ @DavidRicherby, the time complexity of T. That function can literally apply to any (badly designed) algorithm. $\endgroup$ – user6490375 Oct 10 '16 at 17:53
  • 1
    $\begingroup$ 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.) $\endgroup$ – David Richerby Oct 10 '16 at 17:58
  • $\begingroup$ 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$. $\endgroup$ – 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} $$

  • $\begingroup$ I am sorry, but we have been asked to do this using the recursion tree, as I have pointed out in the question description. $\endgroup$ – user6490375 Oct 10 '16 at 17:35
  • 1
    $\begingroup$ Your question never mentioned that. Also, there's no point in rephrasing this solution in terms of recursion trees; all this would amount to is some artificial rephrasing of the argument. $\endgroup$ – Yuval Filmus Oct 10 '16 at 18:03
  • $\begingroup$ @YuvalFilmus, doesn't the phrase I would have considered cn to be the root and then solved the remainder of the tree mean that I am using a recursion tree? $\endgroup$ – user6490375 Oct 10 '16 at 19:12
  • $\begingroup$ That's a question for your professor. $\endgroup$ – Yuval Filmus Oct 10 '16 at 19:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.