15
David Luebke 1 08/25/22 CS 332: Algorithms Introduction Proof By Induction

David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

Embed Size (px)

Citation preview

Page 1: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 1 04/19/23

CS 332: Algorithms

Introduction

Proof By Induction

Page 2: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 2 04/19/23

The Course

Purpose: a rigorous introduction to the design and analysis of algorithms Not a lab or programming course Not a math course, either

Textbook: Introduction to Algorithms, Cormen, Leiserson, and Rivest (CLR) The “Big White Book” An excellent reference you should own

Page 3: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 3 04/19/23

The Course

Instructor: David Luebke [email protected] Office: Olsson 219

TA: Emily Evans Grader: Wei Lin Zhong

Page 4: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 4 04/19/23

The Course

Grading policy (overrides web page): Homework: 40% Midterm: 20% Final: 35% Participation: 5%

Page 5: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 5 04/19/23

The Course

Prerequisites: CS 302 w/ grade of C- or better CS 216 w/ grade of C- or better These are strictly enforced!

Who’s not registered? Write down: Your name, year, and major (inc. Echols/Rodman) Any special reason why you should be let into the

course instead of others

Page 6: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 6 04/19/23

The Course

Format Two lectures/week Homework every week

Problem sets Very occasional programming assignments

Two tests (tentative)

Page 7: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 7 04/19/23

Review: Induction

Suppose S(k) is true for fixed constant k

Often k = 0 S(n) S(n+1) for all n >= k

Then S(n) is true for all n >= k

Page 8: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 8 04/19/23

Proof By Induction

Claim:S(n) is true for all n >= k Basis:

Show formula is true when n = k Inductive hypothesis:

Assume formula is true for an arbitrary n Step:

Show that formula is then true for n+1

Page 9: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 9 04/19/23

Induction Example: Gaussian Closed Form

Prove 1 + 2 + 3 + … + n = n(n+1) / 2 Basis:

If n = 0, then 0 = 0(0+1) / 2 Inductive hypothesis:

Assume 1 + 2 + 3 + … + n = n(n+1) / 2 Step (show true for n+1):

1 + 2 + … + n + n+1 = (1 + 2 + …+ n) + (n+1)

= n(n+1)/2 + n+1 = [n(n+1) + 2(n+1)]/2

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

Page 10: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 10 04/19/23

Induction Example:Geometric Closed Form

Prove a0 + a1 + … + an = (an+1 - 1)/(a - 1) for all a != 1 Basis: show that a0 = (a0+1 - 1)/(a - 1)

a0 = 1 = (a1 - 1)/(a - 1) Inductive hypothesis:

Assume a0 + a1 + … + an = (an+1 - 1)/(a - 1) Step (show true for n+1):

a0 + a1 + … + an+1 = a0 + a1 + … + an + an+1

= (an+1 - 1)/(a - 1) + an+1 = (an+1+1 - 1)/(a - 1)

Page 11: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 11 04/19/23

Induction

We’ve been using weak induction Strong induction also holds

Basis: show S(0) Hypothesis: assume S(k) holds for arbitrary k <= n Step: Show S(n+1) follows

Page 12: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 12 04/19/23

Induction

Another variation: Basis: show S(0), S(1) Hypothesis: assume S(n) and S(n+1) are true Step: show S(n+2) follows

Convenient to prove that the ith Fibonacci number Fi is given by:

5

ˆ ii

iF

Page 13: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 13 04/19/23

Inductive Proof?

Claim: All pens are black

Basis: Suppose the number of pens is 0, trivially all the

pens are black Hypothesis:

Assume if there are n pens, they are all black

Page 14: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 14 04/19/23

Inductive Proof?

Step: Given n+1 pens, remove one pen, the remaining n pens

are black by the inductive hypothesis Call this set of n pens T1

Replace the first pen and remove another, the remaining n pens are black by inductive hypothesis

Call this set of n pens T2

The union of T1 and T2 is the original set of n+1 pens. Both subsets are black, so entire set is black.

What is wrong here?

Page 15: David Luebke 1 9/11/2015 CS 332: Algorithms Introduction Proof By Induction

David Luebke 15 04/19/23

Up Next

In this course, we care most about asymptotic performance How does the algorithm behave as the problem size gets

very large? Running time Memory/storage requirements Bandwidth/power requirements/logic gates/etc.

Coming up: Asymptotic performance of two search algorithms, A formal introduction to asymptotic notation Solving recurrences