SlideShare a Scribd company logo
1 of 21
Algorithm Design and Analysis
Rui Huang
Organization
• Lectures: week 3-15 (12 weeks)
• Time: Tuesday 18:30-21:05
• Venus: 4-409
Reading Materials
• Data Structures and Algorithm Analysis in C++, Fourth Edition, Mark
Allen Weiss, 2013
Contents
• Review (Mathematics & C++) (chap 1)
• Algorithm Analysis (chap 2)
• Lists, Stacks, and Queues (chap 3)
• Trees (chap 4)
• Hashing (chap 5)
• Sorting (chap 7)
• Graph Algorithms (chap 9)
• Algorithm Design Techniques (chap 10) Students’ Presentation
• Optional Topics :Greedy Algorithms, Divide and Conquer,
Randomized Algorithms, Backtracking Algorithms
• Compulsory Topics: Dynamic Programming
• 3 students for each Team. Everyone need to give the presentation.
Chapter 1 Programming: A
General Overview
Goals
• See that how a program performs for reasonably large input is just
as important as its performance on moderate amounts of input.
• Summarize the basic mathematical background needed for the rest
of the book.
• Briefly review recursion.
• Summarize some important features of C++ that are used
throughout the text.
What is this book about
• Problem: Suppose you have a group of N numbers and would like to
determine the kth largest.
• Solution 1:
Read the N numbers into an array, sort the array in decreasing order
by some simple algorithm such as bubble sort, and then return the
element in position k.
• Solution 2:
Read the first k elements into an array, sort the array in decreasing
order. Next, each remaining elements is read one by one. As a new
element arrives, it is ignored if it is smaller than the kth element.
Otherwise, it is placed in its correct spot, bumping the last element.
When the algorithm ends, the kth element is returned.
• Question:
Which is better?
Is either algorithm good enough?
( A simulation using a random file of 30 million elements and k =
15,000,000 will show neither algorithm finishes in a reasonable time;
several days)
What is this book about
• How to estimate the running time of a program for large inputs.
• How to compare the running times of two programs without actually
coding them.
• See some techniques for drastically improving the speed of a
program and for determining program bottlenecks.
Mathematics Review
• Exponents
• Logarithms
• Series
• Modular Arithmetic
• The P Word
Recursion
• We can define a function 𝑓, valid on nonnegative integers, that
satisfies 𝑓(0) = 0 and 𝑓(𝑥) = 2𝑓(𝑥 − 1) + 𝑥2
. A function that
is defined in terms of itself is called recursive.
• C++ implementation?
int f( int x)
{
if( x == 0)
return 0;
else
return 2*f(x-1) + x*x;
}
Two fundamental rules of
Recursion
• Base cases. You must always have some base cases, which can be
solved without recursion.
• Making progress. For the cases that are to be solved recursively, the
recursive call must always be to a case that makes progress toward
a base case.
Bad Case
int bad( int n)
{
if( n == 0)
return 0;
else
return bad( n/3+1)+n-1;
}
• Question: Print out positive number n. e.g. 76234. Assume you have
function printDigit(). This function take one digit and print it out, so
printDigit(4) will output a 4. The recursion function is printOut(in n)
• Prove it.
void printOut( int n)
{
if( n >= 0)
printOut( n/10);
printDigit( n%10);
}
• Proof ( By induction)
• First, if n has one digit, then the program is trivially correct, since it
merely makes a call to printDigit. Assume then that printOut works
for all numbers of k or fewer digits. A number of k+1 digits is
expressed by its first k digits is exactly [n/10], which, by the inductive
hypothesis, is correctly printed, and the last digit is n mode 10, so
the program prints out any (k+1) digit number correctly. Thus, by
induction, all numbers are correctly printed.
C++ Classes

More Related Content

Similar to Algorithm Design and Analysis Techniques

Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsiqbalphy1
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptChapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptTekle12
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptChapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptTekle12
 
Matt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense SlidesMatt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense Slidesmpurkeypile
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................nourhandardeer3
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
Introduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingIntroduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingMvenkatarao
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
Deep learning from scratch
Deep learning from scratch Deep learning from scratch
Deep learning from scratch Eran Shlomo
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 

Similar to Algorithm Design and Analysis Techniques (20)

algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Lecture 1 (bce-7)
Lecture   1 (bce-7)Lecture   1 (bce-7)
Lecture 1 (bce-7)
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptChapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptChapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
 
Chapter two
Chapter twoChapter two
Chapter two
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
Matt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense SlidesMatt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense Slides
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................
 
Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Introduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingIntroduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searching
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Algorithms.
Algorithms. Algorithms.
Algorithms.
 
Deep learning from scratch
Deep learning from scratch Deep learning from scratch
Deep learning from scratch
 
RECURSION.pptx
RECURSION.pptxRECURSION.pptx
RECURSION.pptx
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 

Recently uploaded

Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 

Algorithm Design and Analysis Techniques

  • 1. Algorithm Design and Analysis Rui Huang
  • 2. Organization • Lectures: week 3-15 (12 weeks) • Time: Tuesday 18:30-21:05 • Venus: 4-409
  • 3. Reading Materials • Data Structures and Algorithm Analysis in C++, Fourth Edition, Mark Allen Weiss, 2013
  • 4. Contents • Review (Mathematics & C++) (chap 1) • Algorithm Analysis (chap 2) • Lists, Stacks, and Queues (chap 3) • Trees (chap 4) • Hashing (chap 5) • Sorting (chap 7) • Graph Algorithms (chap 9) • Algorithm Design Techniques (chap 10) Students’ Presentation
  • 5. • Optional Topics :Greedy Algorithms, Divide and Conquer, Randomized Algorithms, Backtracking Algorithms • Compulsory Topics: Dynamic Programming • 3 students for each Team. Everyone need to give the presentation.
  • 6. Chapter 1 Programming: A General Overview
  • 7. Goals • See that how a program performs for reasonably large input is just as important as its performance on moderate amounts of input. • Summarize the basic mathematical background needed for the rest of the book. • Briefly review recursion. • Summarize some important features of C++ that are used throughout the text.
  • 8. What is this book about • Problem: Suppose you have a group of N numbers and would like to determine the kth largest.
  • 9. • Solution 1: Read the N numbers into an array, sort the array in decreasing order by some simple algorithm such as bubble sort, and then return the element in position k.
  • 10. • Solution 2: Read the first k elements into an array, sort the array in decreasing order. Next, each remaining elements is read one by one. As a new element arrives, it is ignored if it is smaller than the kth element. Otherwise, it is placed in its correct spot, bumping the last element. When the algorithm ends, the kth element is returned.
  • 11. • Question: Which is better? Is either algorithm good enough? ( A simulation using a random file of 30 million elements and k = 15,000,000 will show neither algorithm finishes in a reasonable time; several days)
  • 12. What is this book about • How to estimate the running time of a program for large inputs. • How to compare the running times of two programs without actually coding them. • See some techniques for drastically improving the speed of a program and for determining program bottlenecks.
  • 13. Mathematics Review • Exponents • Logarithms • Series • Modular Arithmetic • The P Word
  • 14. Recursion • We can define a function 𝑓, valid on nonnegative integers, that satisfies 𝑓(0) = 0 and 𝑓(𝑥) = 2𝑓(𝑥 − 1) + 𝑥2 . A function that is defined in terms of itself is called recursive. • C++ implementation?
  • 15. int f( int x) { if( x == 0) return 0; else return 2*f(x-1) + x*x; }
  • 16. Two fundamental rules of Recursion • Base cases. You must always have some base cases, which can be solved without recursion. • Making progress. For the cases that are to be solved recursively, the recursive call must always be to a case that makes progress toward a base case.
  • 17. Bad Case int bad( int n) { if( n == 0) return 0; else return bad( n/3+1)+n-1; }
  • 18. • Question: Print out positive number n. e.g. 76234. Assume you have function printDigit(). This function take one digit and print it out, so printDigit(4) will output a 4. The recursion function is printOut(in n) • Prove it.
  • 19. void printOut( int n) { if( n >= 0) printOut( n/10); printDigit( n%10); }
  • 20. • Proof ( By induction) • First, if n has one digit, then the program is trivially correct, since it merely makes a call to printDigit. Assume then that printOut works for all numbers of k or fewer digits. A number of k+1 digits is expressed by its first k digits is exactly [n/10], which, by the inductive hypothesis, is correctly printed, and the last digit is n mode 10, so the program prints out any (k+1) digit number correctly. Thus, by induction, all numbers are correctly printed.