2

I'm reading the book Introduction to Algorithms, Third Edition. In an exercise, we are asked to use inductive reasoning to prove

T(n) = {2 if n = 2, 2T(n/2) + n if n > 2^k for k > 1} = nlgn

Where lg is log base 2. The book provides the solution:

Base Case:
n = 2, T(2) = 2, 2lg(2) = 2

Assumption:
T (n/2) = (n/2)lg(n/2)

Induction:
T (n) = 2T (n/2) + n
= 2(n/2)lg(n/2) + n
= n(lg n − 1) + n
= n lg n − n + n
= n lg n

Could someone explain why the value n/2 is used in the Assumption step? With my understanding of induction, I would have used the value 2^n and then later incremented it to 2^(n+1) in order to cover all possible powers of 2. I want to know why I'm wrong. Furthermore, could someone explain the operations that change 2(n/2)lg(n/2)+n into n(lg n-1) + n? It doesn't adhere to the mathematical conventions that I'm aware of.

joshua
  • 2,371
  • 2
  • 29
  • 58
Mikey G
  • 181
  • 1
  • 9

1 Answers1

1

Coming to some basic maths:

lg(a/b) = lg(a) - lg(b)

This is the reason why:

2(n/2)lg(n/2)+n = n( lg(n) - lg(2)) + n = n( lg(n) - 1) + n

About the assumption of n/2, this assumption is the best assumption because it simplifies the induction step. In the induction step, we reach the result with ease and without any rigorous mathematical explanation.

The book Cormen, which is considered to be the bible of algorithms calls this substitution method of solving recurrences where first we assume the recurrence to be true for a given input and using that assumption we see whether our assumption is fitting the expression for input n.

Sumeet
  • 8,086
  • 3
  • 25
  • 45
  • That makes sense. I originally thought induction was defined by the increment as opposed to the assumption which lead to some confusion. – Mikey G Jul 07 '15 at 04:52
  • Is there a method by which he came to the value n/2 as a simple assumption or is it a matter of experience on his part? – Mikey G Jul 07 '15 at 04:56
  • @user2985955 I myself asked this question to my instructor and he answered, it comes with experience, substitution method is not easy, this is the reason why master's method or tree method is used. – Sumeet Jul 07 '15 at 04:57
  • It actually makes sense in this context I think because you can only substitute if you use n/2 because T(n/2) is the value used in the function and it happens to work out well because it's a textbook problem. – Mikey G Jul 07 '15 at 05:03
  • @user2985955 You are right, it was an easy recursion but if you want some real recursion problems, go for Cormen. – Sumeet Jul 07 '15 at 05:09
  • Can you please take a look https://stackoverflow.com/questions/71178163/clrs-solution-seems-meaningless-as-one-line-make-me-skeptical – Encipher Feb 19 '22 at 00:14