SlideShare a Scribd company logo
1 of 16
CS341
Algorithms Analysis and
Design
Section 7
Solving Recurrences
Three methods are used in “solving” recurrences
•The Substitution Method
•The Recursion Tree Method
•The Master Method
2
Substitution Method
Substitution method has two steps
• Guess the form of the solution
• Use induction to prove that the solution is correct
The substitution method can be used to establish an
upper bound on difficult recurrences.
Its use is based on the strength of the guess
• applied in cases when it’s easy to guess the form of
answer
3
Substitution Method (1)
4
Substitution Method (1)
5
Substitution Method (2)
6
Substitution Method (2)
7
Substitution Method (2)
8
Midterm Exam
9
Question One: Multiple Choice
• 1- Algorithm analysis is determining the amount of ______ resources necessary to
execute it.
a) one b) two c) three d) four
• 2- Algorithm ______ means how does the input/output relation match algorithm
requirement?
a) clarity b) optimality c) simplicity d) correctness
• 3- ______ essential approaches are used to analyze the algorithm.
a) Five b) Four c) Three d) Two
• 4- The ______ order of growth rate means that when N doubles, runtime increases
fourfold.
a) 2N b) N² c) N2 d) 2N
• 5- The insertion and removal in the ______ has an O(1) in the best, average, and
worst cases.
a) tree b) stack c) graph d) queue
10
Question Two: True or False.
• 1- Many problems are in a complexity class for which no
practical algorithms are known.
• 2- The semantics of an algorithm is its actual
representation (body).
• 3- The efficiency of algorithm determines its complexity.
• 4- Analyzing the average case of an algorithm is the most
difficult in practice.
• 5- An algorithm is a procedure that maps one or more
input(s) to one correct output.
11
Question Two: True or False.
• 6- The approach to analyzing algorithms must be
independent of four influences.
• 7- Being “O(n3)” is a running time, or a function which
gives the running time of algorithm.
• 8- f(n) ∈ O(g(n)) ≡ g(n) ∈ Ω(f(n))
• 9- Asymptotic growth rate is not always useful for analysis
on fixed-size inputs.
• 10- The bubble, insertion, merge and selection algorithms
are incremental comparison sort.
12
Question Three: Essay Question
1- Consider the following algorithm:
• n = read input from user
• pos = 0
• neg = 0
• i = 0
• while i < n
• number = read input from user
• if (number > 0)
• pos = pos + 1
• else if (number < 0)
• neg = neg + 1
• i = i + 1
• write pos to user
• write neg to user
13
Question Three: Essay Question
1- Consider the following algorithm:
• n = read input from user 1
• pos = 0 1
• neg = 0 1
• i = 0 1
• while i < n 1
• number = read input from user 1
• if (number > 0) 1
• pos = pos + 1
• else if (number < 0) OR
• neg = neg + 1 1
• i = i + 1 1
• write pos to user 1
• write neg to user 1
14
n
Question Three: Essay Question
• A. What is the computation time, T(n), in terms of the input size n?
• 5n+6
• B. What is the tight upper bound?
• O(n)
• C. Give an input sequence that satisfies the best case.
• All positives (number>0)
• D. Give an input sequence that satisfies the average case.
• Positives, Zero and Negatives
• E. Give an input sequence that satisfies the worst case.
• All negatives (number<0)
15
16
Thank You

More Related Content

Similar to CS341 Algorithms Analysis and Design-Sec7.pptx

Similar to CS341 Algorithms Analysis and Design-Sec7.pptx (20)

Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
 
Ml ppt at
Ml ppt atMl ppt at
Ml ppt at
 
Big Data Challenges and Solutions
Big Data Challenges and SolutionsBig Data Challenges and Solutions
Big Data Challenges and Solutions
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
 
chapter 1
chapter 1chapter 1
chapter 1
 
ISSTA'16 Summer School: Intro to Statistics
ISSTA'16 Summer School: Intro to StatisticsISSTA'16 Summer School: Intro to Statistics
ISSTA'16 Summer School: Intro to Statistics
 
First session _Cracking the coding interview.pptx
First session _Cracking the coding interview.pptxFirst session _Cracking the coding interview.pptx
First session _Cracking the coding interview.pptx
 
Lecture1
Lecture1Lecture1
Lecture1
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & SearchingHub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Genetic programming
Genetic programmingGenetic programming
Genetic programming
 
daa unit 1.pptx
daa unit 1.pptxdaa unit 1.pptx
daa unit 1.pptx
 
Analysis.ppt
Analysis.pptAnalysis.ppt
Analysis.ppt
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 

More from hussein zayed

Random Variables and Distributions
Random Variables and DistributionsRandom Variables and Distributions
Random Variables and Distributionshussein zayed
 
substring & subSquence & find problem solving
substring & subSquence & find problem solving substring & subSquence & find problem solving
substring & subSquence & find problem solving hussein zayed
 
Inheritance & polymorphism java oop
Inheritance & polymorphism java oopInheritance & polymorphism java oop
Inheritance & polymorphism java oophussein zayed
 
File Transport Protocol
File Transport ProtocolFile Transport Protocol
File Transport Protocolhussein zayed
 

More from hussein zayed (6)

Random Variables and Distributions
Random Variables and DistributionsRandom Variables and Distributions
Random Variables and Distributions
 
Product owner
Product ownerProduct owner
Product owner
 
substring & subSquence & find problem solving
substring & subSquence & find problem solving substring & subSquence & find problem solving
substring & subSquence & find problem solving
 
Inheritance & polymorphism java oop
Inheritance & polymorphism java oopInheritance & polymorphism java oop
Inheritance & polymorphism java oop
 
File Transport Protocol
File Transport ProtocolFile Transport Protocol
File Transport Protocol
 
Java fx
Java fxJava fx
Java fx
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 

Recently uploaded (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

CS341 Algorithms Analysis and Design-Sec7.pptx

  • 2. Solving Recurrences Three methods are used in “solving” recurrences •The Substitution Method •The Recursion Tree Method •The Master Method 2
  • 3. Substitution Method Substitution method has two steps • Guess the form of the solution • Use induction to prove that the solution is correct The substitution method can be used to establish an upper bound on difficult recurrences. Its use is based on the strength of the guess • applied in cases when it’s easy to guess the form of answer 3
  • 10. Question One: Multiple Choice • 1- Algorithm analysis is determining the amount of ______ resources necessary to execute it. a) one b) two c) three d) four • 2- Algorithm ______ means how does the input/output relation match algorithm requirement? a) clarity b) optimality c) simplicity d) correctness • 3- ______ essential approaches are used to analyze the algorithm. a) Five b) Four c) Three d) Two • 4- The ______ order of growth rate means that when N doubles, runtime increases fourfold. a) 2N b) N² c) N2 d) 2N • 5- The insertion and removal in the ______ has an O(1) in the best, average, and worst cases. a) tree b) stack c) graph d) queue 10
  • 11. Question Two: True or False. • 1- Many problems are in a complexity class for which no practical algorithms are known. • 2- The semantics of an algorithm is its actual representation (body). • 3- The efficiency of algorithm determines its complexity. • 4- Analyzing the average case of an algorithm is the most difficult in practice. • 5- An algorithm is a procedure that maps one or more input(s) to one correct output. 11
  • 12. Question Two: True or False. • 6- The approach to analyzing algorithms must be independent of four influences. • 7- Being “O(n3)” is a running time, or a function which gives the running time of algorithm. • 8- f(n) ∈ O(g(n)) ≡ g(n) ∈ Ω(f(n)) • 9- Asymptotic growth rate is not always useful for analysis on fixed-size inputs. • 10- The bubble, insertion, merge and selection algorithms are incremental comparison sort. 12
  • 13. Question Three: Essay Question 1- Consider the following algorithm: • n = read input from user • pos = 0 • neg = 0 • i = 0 • while i < n • number = read input from user • if (number > 0) • pos = pos + 1 • else if (number < 0) • neg = neg + 1 • i = i + 1 • write pos to user • write neg to user 13
  • 14. Question Three: Essay Question 1- Consider the following algorithm: • n = read input from user 1 • pos = 0 1 • neg = 0 1 • i = 0 1 • while i < n 1 • number = read input from user 1 • if (number > 0) 1 • pos = pos + 1 • else if (number < 0) OR • neg = neg + 1 1 • i = i + 1 1 • write pos to user 1 • write neg to user 1 14 n
  • 15. Question Three: Essay Question • A. What is the computation time, T(n), in terms of the input size n? • 5n+6 • B. What is the tight upper bound? • O(n) • C. Give an input sequence that satisfies the best case. • All positives (number>0) • D. Give an input sequence that satisfies the average case. • Positives, Zero and Negatives • E. Give an input sequence that satisfies the worst case. • All negatives (number<0) 15

Editor's Notes

  1. 1-c 2-d 3-d 4-b 5-b
  2. 1-T 2-F 3-F 4-T 5-T
  3. 6-T 7-F 8-T 9-T 10-F