The Substitution Method for Solving Recurrences

 

The Substitution Method for Solving Recurrences

Introduction

Many algorithms, especially Divide and Conquer algorithms, produce recurrence relations.

To determine the running time of these algorithms, we must solve the recurrence.

The Substitution Method is the most general of these methods because it can be applied to a wide variety of recurrences. However, unlike the Master Method, it requires us to first guess the form of the solution.


Why is it Called the Substitution Method?

The name comes from the key step in the proof.

Suppose the recurrence is

T(n)=2T(n/2)+nT(n)=2T(n/2)+n

Assume that

T(n)≤cnlog⁡nT(n)\le cn\log n

for smaller values of nn.

Then we substitute this assumed bound into the recurrence:

T(n)≤2(cn2log⁡n2)+nT(n) \le 2\left(c\frac n2\log\frac n2\right)+n

Since we substitute the guessed solution into the recurrence, the technique is called the Substitution Method.


3. Steps in the Substitution Method

The substitution method consists of two steps:

Step 1

Guess the form of the solution using symbolic constants.


Step 2

Use mathematical induction to prove that the guess is correct and determine suitable values of the constants.


4. General Procedure

Suppose we have the recurrence

T(n)=2T(n/2)+nT(n)=2T(n/2)+n

The procedure is

Step 1

Guess

T(n)=O(nlog⁡n)T(n)=O(n\log n)

Step 2

Assume

T(k)≤cklog⁡kT(k)\le ck\log k

for all

k<nk<n

This is the induction hypothesis.


Step 3

Substitute the induction hypothesis into the recurrence.


Step 4

Simplify the expression.


Step 5

Choose suitable constants so that the inequality holds.


Step 6

Verify the base case.


5. Example 

Consider the recurrence

T(n)=2T(⌊n/2⌋)+Θ(n)\boxed{ T(n)=2T(\lfloor n/2\rfloor)+\Theta(n) }

This is essentially the Merge Sort recurrence, except that it explicitly uses the floor function to ensure the recurrence is defined for integer values of n.


Step 1: Guess the Solution

Since the recurrence resembles Merge Sort,

we guess

T(n)=O(nlog⁡n)\boxed{ T(n)=O(n\log n) }

Step 2: State the Induction Hypothesis

Instead of writing

T(n)=O(nlog⁡n)T(n)=O(n\log n)

we assume

T(n)≤cnlog⁡n\boxed{ T(n)\le cn\log n }

for some constant

c>0c>0

Notice that it does not use asymptotic notation inside the induction hypothesis. Instead, it uses an explicit constant c.


Step 3: Substitute

Using the induction hypothesis,

T(⌊n/2⌋)≤c⌊n/2⌋log⁡(⌊n/2⌋)T(\lfloor n/2\rfloor) \le c\lfloor n/2\rfloor \log(\lfloor n/2\rfloor)

Substitute into the recurrence:

T(n)≤2c(n2)log⁡(n2)+Θ(n)T(n) \le 2c\left(\frac n2\right) \log\left(\frac n2\right) +\Theta(n)

Step 4: Simplify

Since

log⁡(n2)=log⁡n−log⁡2\log\left(\frac n2\right) = \log n-\log2

and

log⁡2=1\log2=1

we get

T(n)≤cn(log⁡n−1)+Θ(n)T(n) \le cn(\log n-1)+\Theta(n)

or

T(n)=cnlog⁡n−cn+Θ(n)T(n) = cn\log n-cn+\Theta(n)

Step 5: Choose the Constant

The negative term

−cn-cn

must dominate the hidden constant inside

Θ(n)\Theta(n)

Choose

cc

large enough.

Then

T(n)≤cnlog⁡nT(n) \le cn\log n

Thus,

the induction step is complete.


Step 6: Base Case

Note that the base case must also satisfy the induction hypothesis.

Choose

n0=2n_0=2

and select

cc

large enough so that

T(2)≤2clog⁡2T(2)\le2c\log2

and

T(3)≤3clog⁡3T(3)\le3c\log3

Hence,

the induction starts correctly.


Final Result

T(n)=O(nlog⁡n)\boxed{ T(n)=O(n\log n) }

Comments

Popular posts from this blog

Design and Analysis of Algorithms PCCST502 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Algorithms

Criteria for Analyzing Algorithms- Time and Space Complexity