1

How can I solve the following recurrence without using the master theorem?

$T(n)= 4T(n/2)-1$ for $n>4$ and $T(n)=5$ for $n\le 4$, $n$ is a power of $2$.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
X97
  • 21
  • 3
  • Am I missing something or this recurrence is invalid. Can a recurrence be decreasing function, this doesn't make any sense to me in asymptotics, but I have to admit I am not very good at it. – kuskmen Mar 28 '19 at 12:28
  • 1
    There is no requirement that the solution of a recurrence be non-decreasing. – Yuval Filmus Mar 28 '19 at 13:25
  • @X97, have you tried computing $T(8), T(16), T(32), T(64), T(128)$, etc? That is the first thing you should have done if you have not done it for quite a few recurrence relations. – John L. Mar 28 '19 at 14:41

3 Answers3

2

The idea is to convert this recurrence to the simpler recurrence $$ S(n) = 4S(n/2). $$ How do we do this? Let $S(n) = T(n) + f(n)$. Since $$ S(n) = T(n) + f(n) = 4T(n/2) - 1 + f(n) = 4S(n/2) - 4f(n/2) - 1 + f(n), $$ we need that $$ f(n) = 4f(n/2) + 1. $$ Luckily, $f(n) = -1/3$ is a solution. So $S(n) = T(n) - 1/3$ satisfies $$ S(n) = 4S(n/2), \qquad S(4) = 14/3. $$ You take it from here.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
2

You can use a change of domain here:

$$T(n) = \begin{cases} 5 & n \leq 4\\ 4T(n/2) - 1 & n > 4\\ \end{cases}$$

Assume $n = 2^{k}$, then let $S(k) = T(2^k)$ and we have:

$$S(k) = \begin{cases} 5 & k \leq 2 \quad \text{because }2^2 = 4\\ 4S(k-1) - 1 & k > 2\\ \end{cases}$$

Now we can turn this into a sum because $k$ is decreasing by 1 each time:

$$\begin{align*} S(k) &= 5 + \sum_{i = 3}^k -1 \cdot 4^{k - i}\\ &= 5 - \sum_{i = 3}^k 4^{k - i}\\ &= 5 - \sum_{i = 0}^{k-3} 4^i\\ &= 5 - (4^{k-2} - 1)/3\\ \end{align*}$$

Now we can plug $n$ back in with $k = \log_2 n$:

$$\begin{align*} T(n) &= S(\log_2 n)\\ &= 5 - (4^{\log_2 n - 2} - 1)/3\\ &= 5 - (4^{\log_2 n}/16 - 1)/3\\ &= 5 - (2^{2\log_2 n}/16 - 1)/3\\ &= 5 - (n^2/16 - 1)/3\\ &= 16/3 - n^2 / 48 \end{align*}$$

No Master Theorem needed. If you wish, you could prove $S(k)$ equals the summation I mention by induction, but it should be obvious.

ryan
  • 4,501
  • 1
  • 15
  • 41
0

Start with T(1) = c, then T(2) = 4c - 1, T(4) = 16c - 5, T(8) = 64c - 21, T(16) = 256c - 85, T(32) = 1024c - 341.

Hopefully you spot that 1 = (4 - 1) / 3, 5 = (16 - 1) / 3, 21 = (64 - 1) / 3, 85 = (256 - 1) / 3, 341 = (1024 - 1) / 3. So we can guess that maybe $T(2^k) = 4^k \cdot c - (4^k - 1) / 3$, and this guess is easily shown to be true by complete induction.

If $n = 2^k$, then $T(n) = n^2 \cdot c - (n^2 - 1) / 3$.

gnasher729
  • 29,996
  • 34
  • 54