1

I'm having a real hard time solving recurrences using the substitution method.

Show that: $T(n) = T(n/2) + 1$ is $O(\lg n)$

I thought this to be relatively easy:

We have to show that $T(n) \leq c \lg n$

Substitution gives me:

$\qquad \begin{align} T(n) &\leq c \lg(n/2) + 1 \\ &= c \lg n - c \lg 2 + 1 \\ &= c \lg n - c + 1 \\ &\leq c \lg n \end{align}$

for every c.

I was under the impression this was it, but when I was looking for an answer, I came around a much more elaborate answer on the web, given involving subtracting a constant. I don't get why that's needed, I thought I had shown what was needed.

Any help would be greatly appreciate, starting Monday I'm enrolled in an algorithms class and I don't want to get behind!

We are using the CLRS book (surprise) and though I appreciate the amount of information in it, I'd rather have some more resources. I've really enjoyed a datastructures class and I really think I can enjoy this as well, but more resources would be very much appreciated.

Raphael
  • 72,336
  • 29
  • 179
  • 389
Oxymoron
  • 213
  • 1
  • 2
  • 4
  • 1
    We have a reference question with ample material about solving recurrences, in particular this answer. – Raphael Jan 30 '13 at 20:54
  • Your substitution proves nothing. You use the claim to derive the claim -- that's not very helpful. – Raphael Jan 30 '13 at 20:56
  • 1
    @Raphael This is proof by induction. – Yuval Filmus Jan 31 '13 at 00:27
  • 1
    Your solution looks fine, though you'd better write it as an induction, i.e $T(n) = T(n/2) + 1 \leq c\lg(n/2) + 1$ and so on. You also need to take care of the base case, and notice that you get a condition on $c$ (not all $c$ work). – Yuval Filmus Jan 31 '13 at 00:28
  • 1
    @YuvalFilmus No, it's not. What is written there could be used as the inductive step, true. Given the level of the question, I would not assume that Oxymoron knows what happens there; the question even says "substitution method". – Raphael Jan 31 '13 at 09:34
  • Another classical method for this proof is to consider $T'(k):=T(2^k)$ and show that it's $O(k)$, then revert to $T$. – Khaur Jan 31 '13 at 10:09
  • All right, the master method will follow in the next part, but up until then im stuck with induction and subtitution. I thought I had shown here that when I substitute the guess into the recurrence, it 'seems to work out'. But apparantly I'm still missing some stuff.I guess this has to do with establishing bounds. But how do I choose a lowest bound? For example if I would say T(0) I just get 1, since 0/2 = 0. Is this my base for the induction? – Oxymoron Jan 31 '13 at 18:50

2 Answers2

1

Luckily i had 2 day ago the algorithm exam and so i was able to solve your question :-) When solving recurrences try first to use the Master method, if you can't succeed than try other methods.

enter image description here

A.B.
  • 441
  • 1
  • 6
  • 17