Escolar Documentos
Profissional Documentos
Cultura Documentos
Introduction
Proof By Induction
Asymptotic notation
David Luebke 1
12/08/21
The Course
David Luebke 2
12/08/21
The Course
David Luebke 3
12/08/21
The Course
• Grading policy:
Homework: 30%
Exam 1: 15%
Exam 2: 15%
Final: 35%
Participation: 5%
David Luebke 4
12/08/21
The Course
• Prerequisites:
CS 202 w/ grade of C- or better
CS 216 w/ grade of C- or better
CS 302 recommended but not required
o Who has not taken CS 302?
David Luebke 5
12/08/21
The Course
• Format
Three lectures/week
Homework most weeks
o Problem sets
o Maybe occasional programming assignments
Two tests + final exam
David Luebke 6
12/08/21
Review: Induction
• Suppose
S(k) is true for fixed constant k
o Often k = 0
S(n) S(n+1) for all n >= k
• Then S(n) is true for all n >= k
David Luebke 7
12/08/21
Proof By Induction
David Luebke 8
12/08/21
Induction Example:
Gaussian Closed Form
• Prove 1 + 2 + 3 + … + n = n(n+1) / 2
Basis:
o If n = 0, then 0 = 0(0+1) / 2
Inductive hypothesis:
o 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
12/08/21
Induction Example:
Geometric Closed Form
• Prove a0 + a1 + … + an = (an+1 - 1)/(a - 1) for all
a1
Basis: show that a0 = (a0+1 - 1)/(a - 1)
a0 = 1 = (a1 - 1)/(a - 1)
Inductive hypothesis:
o 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
12/08/21
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
• Another variation:
Basis: show S(0), S(1)
Hypothesis: assume S(n) and S(n+1) are true
Step: show S(n+2) follows
David Luebke 11
12/08/21
Asymptotic Performance
David Luebke 12
12/08/21
Asymptotic Notation
David Luebke 13
12/08/21
Analysis of Algorithms
• Analysis is performed with respect to a computational
model
• We will usually use a generic uniprocessor random-
access machine (RAM)
All memory equally expensive to access
No concurrent operations
All reasonable instructions take unit time
o Except, of course, function calls
Constant word size
o Unless we are explicitly manipulating bits
David Luebke 14
12/08/21
Input Size
David Luebke 15
12/08/21
Running Time
David Luebke 16
12/08/21
Analysis
• Worst case
Provides an upper bound on running time
An absolute guarantee
• Average case
Provides the expected running time
Very useful, but treat with care: what is “average”?
o Random (equally likely) inputs
o Real-life inputs
David Luebke 17
12/08/21
The End
David Luebke 18
12/08/21