2

Proof of Induction || Iteration method

Hi, I am working on a discrete math problem, and I can't figure out what to do with:

T(n) = 3 + T(n/2), T(0) = 0

I have tried Plug and Chug method and Induction method, but I can't seem to work it out.

My problem is when I try to make a general formula:

T(n) = 3 + T(n/2) => T(n/2) => 3 + T(n^2/2^2)
T(n) = 3 + (3 + T(n^2/2^2))
T(n) = 3 + 3 + T(n^2/2^2) => 3 + T(n^3/2^3)
T(n) = 3 + 3 + (3 + T(n^3/2^3))
T(n) = 3 + 3 + 3 + T(n^3/2^3)

So, g(i) = 3i + T(n^i/2^i)

Since, T(0) = 0. I need to make n^i/2^i equal to 0.

n^i/2^i = 0

and I'm stuck. I've looked at the answer key, and the answer is:

T(n) = 3(⌊log2(n)⌋ + 1)

Can anyone point me to the right direction?

Cyril Cabo
  • 31
  • 4

1 Answers1

0
T(n) = 3 + T(n/2)
T(0) = 0

We can write out some values and guess at a formula:

n    T(n)
0    0
1    3 + T(1/2) = 3 + T(0) = 3 + 0 = 3
2    3 + T(2/2) = 3 + T(1) = 3 + 3 = 6
4    3 + T(4/2) = 3 + T(2) = 3 + 6 = 9
...
2^k  3 + 3log(k)

How did we arrive at this guess? Well, we noted that for every doubling of n, we increased the value of T(n) by three. In order to count the number of doublings, the natural logarithm can be used, since the logarithm gives you the exponent a base must be raised to (and repeated doubling is multiplying by powers of two).

I think your difficulty here - and it is perfectly valid - is that the guess does not work for the initial condition. Indeed, the logarithm of zero isn't even defined. So, what is going on here? Really, the crux of the issue is that when we calculated T(1), we says 1/2 = 0. That is, we implicitly knew to round down. Functions like the logarithm are functions on the real numbers; the rounding is an artifact of our being in a discrete environment. For this reason, the real complete solution to the recurrence relation is actually a piecewise function:

        / 0, if n = 0
T(n) = -
        \ 3*floor(log2(n)) + 3, if n > 0

In a real sense, then, the answer in the key is wrong, or at least, not fully complete. The formula it gives does not work for n = 0.

Patrick87
  • 27,682
  • 3
  • 38
  • 73