2

How do solve the following recurrence?

$$ T(n) = \frac{1}{2} T\left(\frac{n}{2}\right) + \frac{1}{n}. $$

Master's theorem cannot be applied as $a$ is equal to 0.5 which is less than 1. Hence the theorem fails. How do I solve a recurrence when the theorem fails?

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

1 Answers1

1

You can explicitly unroll the recursion: $$ \begin{align*} T(n) &= \frac{1}{n} + \frac{1}{2} T\left(\frac{n}{2}\right) \\ &= \frac{1}{n} + \frac{1}{n} + \frac{1}{4} T\left(\frac{n}{4}\right) \\ &= \cdots \\ &= \frac{m}{n} + \frac{1}{2^m} T \left(\frac{n}{2^m}\right). \end{align*} $$ This easily leads to the solution $$T(n) = \frac{\log_2 n + T(1)}{n},$$ which is valid for powers of 2.

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