SlideShare a Scribd company logo
CSE 215: Algorithms

      Introduction
   Proof By Induction
   Asymptotic notation
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
The Course

• Instructor: Sukarna Barua
     Lecturer, Dept. of CSE, BUET
     Mail me @ sukarna_barua@yahoo.com
     Office: Room No. 209, Dept. of CSE, BUET
     Call me @ 01674 069126 (in emergency cases,
      usually you should mail me)
The Course

• Grading policy:
     Class Test: 20%
     Mid: 30%
     Final: 40%
     Participation: 10%
The Course

• Prerequisites:
   Basic Programming Skills
   Basic Mathematics Skills
   Knowledge of programming (C/Java/Anyother)
    and Data Structure is required
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
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
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
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)
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
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.
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
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
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
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
     oy=m*x+b
     o c = 5 / 9 * (t - 32 )
     o z = f(x) + g(y)
• We can be more exact if need be
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
The End

More Related Content

PPTX
Teknik Simulasi
PPTX
Artificial Neural Networks
PPTX
Calculus Lecture 1
PPT
Lecture1-Architecture
PPTX
Edu presentation1
PPTX
Lec02 03 rasterization
PPTX
Lecture 14 data structures and algorithms
PDF
Combinatorial optimization CO-1
Teknik Simulasi
Artificial Neural Networks
Calculus Lecture 1
Lecture1-Architecture
Edu presentation1
Lec02 03 rasterization
Lecture 14 data structures and algorithms
Combinatorial optimization CO-1

What's hot (19)

PPTX
Spline interpolation numerical methods presentation
PPTX
Algorithm big o
PDF
Static-talk
PPT
Modules 17 12_2020
PPTX
PPTX
Lecture three
PPTX
Lecture one
PDF
Section9 stochastic
PDF
Topological Sort
PPT
V -linear_programming
PPT
11 initial value problems system
PPT
multi threaded and distributed algorithms
PPTX
Analysis of algorithn class 2
PPTX
Lecture two
PDF
3 handouts section2-2
PPT
Matlab Nn Intro
PPTX
Csci101 lect03 algorithms_i
PPTX
All pair shortest path
PPT
Analysis of Algorithm
Spline interpolation numerical methods presentation
Algorithm big o
Static-talk
Modules 17 12_2020
Lecture three
Lecture one
Section9 stochastic
Topological Sort
V -linear_programming
11 initial value problems system
multi threaded and distributed algorithms
Analysis of algorithn class 2
Lecture two
3 handouts section2-2
Matlab Nn Intro
Csci101 lect03 algorithms_i
All pair shortest path
Analysis of Algorithm
Ad

Viewers also liked (12)

PPT
02 asymp
PPT
asymptotic notations i
PDF
CS Fundamentals: Scalability and Memory
PDF
Lec2 Algorth
PPT
how to calclute time complexity of algortihm
PPTX
Asymptotic notations
PPT
Asymptotic notations
PPTX
Asymptotic Notation and Data Structures
PPT
Complexity of Algorithm
DOC
Time and space complexity
PPTX
Asymptotic Notation
02 asymp
asymptotic notations i
CS Fundamentals: Scalability and Memory
Lec2 Algorth
how to calclute time complexity of algortihm
Asymptotic notations
Asymptotic notations
Asymptotic Notation and Data Structures
Complexity of Algorithm
Time and space complexity
Asymptotic Notation
Ad

Similar to Lecture1 (20)

PPT
lecture1.ppt
PPT
lecture1.ppt
PPT
lecture1.ppt
PDF
Dynamic Programming From CS 6515(Fibonacci, LIS, LCS))
PPT
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
PPT
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
PPT
data unit notes from department of computer science
PPT
Asymptotic analysis
PPTX
Introduction to Algorithms and Asymptotic Notation
PPTX
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
PPT
AsymptoticAnalysis.ppt
PPTX
Presentation_23953_Content_Document_20240906040454PM.pptx
PPTX
1_Asymptotic_Notation_pptx.pptx
PPT
AsymptoticAnalysis-goal of analysis of algorithms
PPTX
Data structures notes for college students btech.pptx
PDF
Unit-1 DAA_Notes.pdf
PDF
Unit 1_final DESIGN AND ANALYSIS OF ALGORITHM.pdf
PDF
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
PPT
Time complexity.ppt
PPT
Time complexity.pptr56435 erfgegr t 45t 35
lecture1.ppt
lecture1.ppt
lecture1.ppt
Dynamic Programming From CS 6515(Fibonacci, LIS, LCS))
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
data unit notes from department of computer science
Asymptotic analysis
Introduction to Algorithms and Asymptotic Notation
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
AsymptoticAnalysis.ppt
Presentation_23953_Content_Document_20240906040454PM.pptx
1_Asymptotic_Notation_pptx.pptx
AsymptoticAnalysis-goal of analysis of algorithms
Data structures notes for college students btech.pptx
Unit-1 DAA_Notes.pdf
Unit 1_final DESIGN AND ANALYSIS OF ALGORITHM.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
Time complexity.ppt
Time complexity.pptr56435 erfgegr t 45t 35

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Lesson notes of climatology university.
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
master seminar digital applications in india
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Microbial diseases, their pathogenesis and prophylaxis
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pre independence Education in Inndia.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
VCE English Exam - Section C Student Revision Booklet
102 student loan defaulters named and shamed – Is someone you know on the list?
Lesson notes of climatology university.
O7-L3 Supply Chain Operations - ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
master seminar digital applications in india
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Lecture1

  • 1. CSE 215: Algorithms Introduction Proof By Induction Asymptotic notation
  • 2. 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. The Course • Instructor: Sukarna Barua  Lecturer, Dept. of CSE, BUET  Mail me @ sukarna_barua@yahoo.com  Office: Room No. 209, Dept. of CSE, BUET  Call me @ 01674 069126 (in emergency cases, usually you should mail me)
  • 4. The Course • Grading policy:  Class Test: 20%  Mid: 30%  Final: 40%  Participation: 10%
  • 5. The Course • Prerequisites:  Basic Programming Skills  Basic Mathematics Skills  Knowledge of programming (C/Java/Anyother) and Data Structure is required
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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)
  • 10. 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
  • 11. 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.
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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 oy=m*x+b o c = 5 / 9 * (t - 32 ) o z = f(x) + g(y) • We can be more exact if need be
  • 16. 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