SlideShare a Scribd company logo
David Luebke 1 11/6/2023
CS 332: Algorithms
Introduction
Proof By Induction
Asymptotic notation
David Luebke 2 11/6/2023
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, Rivest, Stein
 The “Big White Book”
 Second edition: now “Smaller Green Book”
 An excellent reference you should own
David Luebke 3 11/6/2023
The Course
• Instructor: David Luebke
 luebke@cs.virginia.edu
 Office: Olsson 219
 Office hours: 2-3 Monday, 10-11 Thursday
• TA: Pavel Sorokin
 Office hours and location TBA
David Luebke 4 11/6/2023
The Course
• Grading policy:
 Homework: 30%
 Exam 1: 15%
 Exam 2: 15%
 Final: 35%
 Participation: 5%
David Luebke 5 11/6/2023
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 6 11/6/2023
The Course
• Format
 Three lectures/week
 Homework most weeks
o Problem sets
o Maybe occasional programming assignments
 Two tests + final exam
David Luebke 7 11/6/2023
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 8 11/6/2023
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
David Luebke 9 11/6/2023
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 10 11/6/2023
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:
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 11 11/6/2023
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 12 11/6/2023
Asymptotic Performance
• In this course, we care most about asymptotic
performance
 How does the algorithm behave as the problem
size gets very large?
o Running time
o Memory/storage requirements
o Bandwidth/power requirements/logic gates/etc.
David Luebke 13 11/6/2023
Asymptotic Notation
• By now you should have an intuitive feel for
asymptotic (big-O) notation:
 What does O(n) running time mean? O(n2)?
O(n lg n)?
 How does asymptotic running time relate to
asymptotic memory usage?
• Our first task is to define this notation more
formally and completely
David Luebke 14 11/6/2023
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 15 11/6/2023
Input Size
• Time and space complexity
 This is generally a function of the input size
o E.g., sorting, multiplication
 How we characterize input size depends:
o Sorting: number of input items
o Multiplication: total number of bits
o Graph algorithms: number of nodes & edges
o Etc
David Luebke 16 11/6/2023
Running Time
• Number of primitive steps that are executed
 Except for time of executing a function call most
statements roughly require the same amount of
time
o y = m * x + b
o c = 5 / 9 * (t - 32 )
o z = f(x) + g(y)
• We can be more exact if need be
David Luebke 17 11/6/2023
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 18 11/6/2023
The End

More Related Content

PPT
lecture1.ppt
PPT
Lecture1-Architecture
PPT
Lecture1
PDF
Dynamic Programming From CS 6515(Fibonacci, LIS, LCS))
PPT
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
PPT
data unit notes from department of computer science
PPT
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
PPTX
Introduction to Algorithms and Asymptotic Notation
lecture1.ppt
Lecture1-Architecture
Lecture1
Dynamic Programming From CS 6515(Fibonacci, LIS, LCS))
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
data unit notes from department of computer science
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
Introduction to Algorithms and Asymptotic Notation

Similar to lecture1.ppt (20)

PPTX
1_Asymptotic_Notation_pptx.pptx
PPT
AsymptoticAnalysis.ppt
PDF
Unit 1_final DESIGN AND ANALYSIS OF ALGORITHM.pdf
PPTX
Data structures notes for college students btech.pptx
PPTX
Unit 1.pptx
PPT
AsymptoticAnalysis-goal of analysis of algorithms
PPT
Asymptotic analysis
PDF
BCS401 ADA First IA Test Question Bank.pdf
PPTX
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
PDF
Asymptotic Notation
PPT
algorithms-1 master in computer application
PPT
analysis of algorithms and asymptotic complexity
PPTX
CS 161 Section 1 Slides - Stanford University
PPT
PPTX
DAA-Unit1.pptx
PPTX
CS8451 DAA Unit-I.pptx
PPTX
Presentation_23953_Content_Document_20240906040454PM.pptx
PPTX
Lecture2a algorithm
PDF
Chapter One.pdf
PPTX
asymptotic analysis and insertion sort analysis
1_Asymptotic_Notation_pptx.pptx
AsymptoticAnalysis.ppt
Unit 1_final DESIGN AND ANALYSIS OF ALGORITHM.pdf
Data structures notes for college students btech.pptx
Unit 1.pptx
AsymptoticAnalysis-goal of analysis of algorithms
Asymptotic analysis
BCS401 ADA First IA Test Question Bank.pdf
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
Asymptotic Notation
algorithms-1 master in computer application
analysis of algorithms and asymptotic complexity
CS 161 Section 1 Slides - Stanford University
DAA-Unit1.pptx
CS8451 DAA Unit-I.pptx
Presentation_23953_Content_Document_20240906040454PM.pptx
Lecture2a algorithm
Chapter One.pdf
asymptotic analysis and insertion sort analysis
Ad

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Module 4: Burden of Disease Tutorial Slides S2 2025
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Final Presentation General Medicine 03-08-2024.pptx
Complications of Minimal Access Surgery at WLH
FourierSeries-QuestionsWithAnswers(Part-A).pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
A systematic review of self-coping strategies used by university students to ...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial diseases, their pathogenesis and prophylaxis
Ad

lecture1.ppt

  • 1. David Luebke 1 11/6/2023 CS 332: Algorithms Introduction Proof By Induction Asymptotic notation
  • 2. David Luebke 2 11/6/2023 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, Rivest, Stein  The “Big White Book”  Second edition: now “Smaller Green Book”  An excellent reference you should own
  • 3. David Luebke 3 11/6/2023 The Course • Instructor: David Luebke  luebke@cs.virginia.edu  Office: Olsson 219  Office hours: 2-3 Monday, 10-11 Thursday • TA: Pavel Sorokin  Office hours and location TBA
  • 4. David Luebke 4 11/6/2023 The Course • Grading policy:  Homework: 30%  Exam 1: 15%  Exam 2: 15%  Final: 35%  Participation: 5%
  • 5. David Luebke 5 11/6/2023 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?
  • 6. David Luebke 6 11/6/2023 The Course • Format  Three lectures/week  Homework most weeks o Problem sets o Maybe occasional programming assignments  Two tests + final exam
  • 7. David Luebke 7 11/6/2023 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
  • 8. David Luebke 8 11/6/2023 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
  • 9. David Luebke 9 11/6/2023 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
  • 10. David Luebke 10 11/6/2023 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: 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)
  • 11. David Luebke 11 11/6/2023 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
  • 12. David Luebke 12 11/6/2023 Asymptotic Performance • In this course, we care most about asymptotic performance  How does the algorithm behave as the problem size gets very large? o Running time o Memory/storage requirements o Bandwidth/power requirements/logic gates/etc.
  • 13. David Luebke 13 11/6/2023 Asymptotic Notation • By now you should have an intuitive feel for asymptotic (big-O) notation:  What does O(n) running time mean? O(n2)? O(n lg n)?  How does asymptotic running time relate to asymptotic memory usage? • Our first task is to define this notation more formally and completely
  • 14. David Luebke 14 11/6/2023 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
  • 15. David Luebke 15 11/6/2023 Input Size • Time and space complexity  This is generally a function of the input size o E.g., sorting, multiplication  How we characterize input size depends: o Sorting: number of input items o Multiplication: total number of bits o Graph algorithms: number of nodes & edges o Etc
  • 16. David Luebke 16 11/6/2023 Running Time • Number of primitive steps that are executed  Except for time of executing a function call most statements roughly require the same amount of time o y = m * x + b o c = 5 / 9 * (t - 32 ) o z = f(x) + g(y) • We can be more exact if need be
  • 17. David Luebke 17 11/6/2023 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
  • 18. David Luebke 18 11/6/2023 The End