Download presentation source

Download Report

Transcript Download presentation source

CS 332: Algorithms
Introduction
Proof By Induction
David Luebke
1
7/27/2016
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
David Luebke
2
7/27/2016
The Course

Instructor: David Luebke


[email protected]
Office: Olsson 219
TA: Emily Evans
 Grader: Wei Lin Zhong

David Luebke
3
7/27/2016
The Course

Grading policy (overrides web page):




Homework: 40%
Midterm: 20%
Final: 35%
Participation: 5%
David Luebke
4
7/27/2016
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
David Luebke
5
7/27/2016
The Course

Format


Two lectures/week
Homework every week
 Problem
sets
 Very occasional programming assignments

Two tests (tentative)
David Luebke
6
7/27/2016
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
David Luebke
7
7/27/2016
Proof By Induction
Claim:S(n) is true for all n >= k
 Basis:



Inductive hypothesis:


Show formula is true when n = k
Assume formula is true for an arbitrary n
Step:

Show that formula is then true for n+1
David Luebke
8
7/27/2016
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
David Luebke
9
7/27/2016
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)
David Luebke
10
7/27/2016
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
David Luebke
11
7/27/2016
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:
i  ˆ i
Fi 
5
David Luebke
12
7/27/2016
Inductive Proof?

Claim:


Basis:


All pens are black
Suppose the number of pens is 0, trivially all the
pens are black
Hypothesis:

Assume if there are n pens, they are all black
David Luebke
13
7/27/2016
Inductive Proof?

Step:

Given n+1 pens, remove one pen, the remaining n
pens are black by the inductive hypothesis
 Call

Replace the first pen and remove another, the
remaining n pens are black by inductive hypothesis
 Call


this set of n pens T1
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?
David Luebke
14
7/27/2016
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
David Luebke
15
7/27/2016