12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

44 Chap. 2 Mathematical Preliminariestakes care of the rest.n∑(2i − 1) =i=1[ n−1]∑(2i − 1) + 2n − 1i=1= (n − 1) 2 + 2n − 1= n 2 − 2n + 1 + 2n − 1= n 2 .Thus, by mathematical induction, ∑ ni=1 (2i − 1) = n2 . ✷Example 2.13 This example shows how we can use induction <strong>to</strong> provethat a proposed closed-form solution for a recurrence relation is correct.Theorem 2.4 The recurrence relation T(n) = T(n−1)+1; T(1) = 0has closed-form solution T(n) = n − 1.Proof: To prove the base case, we observe that T(1) = 1 − 1 = 0. Theinduction hypothesis is that T(n − 1) = n − 2. Combining the definitionof the recurrence with the induction hypothesis, we see immediately thatT(n) = T(n − 1) + 1 = n − 2 + 1 = n − 1for n > 1. Thus, we have proved the theorem correct by mathematicalinduction.✷Example 2.14 This example uses induction without involving summationsor other equations. It also illustrates a more flexible use of base cases.Theorem 2.5 2c/ <strong>and</strong> 5c/ stamps can be used <strong>to</strong> form any value (for values≥ 4).Proof: The theorem defines the problem for values ≥ 4 because it does nothold for the values 1 <strong>and</strong> 3. Using 4 as the base case, a value of 4c/ can bemade from two 2c/ stamps. The induction hypothesis is that a value of n − 1can be made from some combination of 2c/ <strong>and</strong> 5c/ stamps. We now use theinduction hypothesis <strong>to</strong> show how <strong>to</strong> get the value n from 2c/ <strong>and</strong> 5c/ stamps.Either the makeup for value n − 1 includes a 5c/ stamp, or it does not. If so,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!