2

While solving Recurrences of type $T\left ( n \right ) = a\cdot T(\frac{n}{b})+c$ using the recursion tree method, number of levels in the recursion tree is equal to $\log_{b}n$ when $b$ is a constant.
But when $b$ is dependent on $n$, can we say that number of levels are still $\log_{b}n$?
For example, in
$T\left ( n \right ) = a\cdot T\left ( \frac{n}{\sqrt{n}} \right )+c$

Can we say that number of levels in the recursion tree are equal to $\log_{\sqrt{n}}n = 2$?
I guess this is wrong but I am unable to reason it properly, please explain me the reason "why this is wrong?"(If it really is).

Raphael
  • 73,212
  • 30
  • 182
  • 400
Romy
  • 407
  • 5
  • 11

1 Answers1

1

If $b$ is not a constant, then no, you can't say the number of levels is still $\log_b n$.

In your example, we have $T(n) = a T(\sqrt{n}) + c$ (since $n/\sqrt{n} = \sqrt{n}$). There are more than 2 levels in the recursion tree. In fact, there are $\lg \lg n$ levels in the recursion tree. So, no, you can't just compute $\lg_{\sqrt{n}} n = 2$ and conclude that there are 2 levels in the recursion tree -- that gives the wrong answer.

(Why $\lg n$? Suppose $n=2^k$. Then each level halves $k$, so we do a total of $\lg k$ levels we get down to a constant. Since $k = \lg n$, we get a total of $\lg k = \lg \lg n$ levels.)

The Master theorem gives a formula for solving this kind of recurrence, but it's only valid when $b$ is a constant.

D.W.
  • 167,959
  • 22
  • 232
  • 500