SlideShare a Scribd company logo
Types of Algorithms
Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together This classification scheme is neither exhaustive nor disjoint The purpose is not to be able to classify an algorithm as one type or another, but to highlight the various ways in which a problem can be attacked
A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide and conquer algorithms Dynamic programming algorithms Greedy algorithms Branch and bound algorithms Brute force algorithms Randomized algorithms
Simple recursive algorithms I A simple  recursive algorithm : Solves the base cases directly Recurs with a simpler subproblem Does some extra work to convert the solution to the simpler subproblem into a solution to the given problem I call these “simple” because several of the other algorithm types are inherently recursive
Example recursive algorithms To count the number of elements in a list: If the list is empty, return zero; otherwise, Step past the first element, and count the remaining elements in the list Add one to the result To test if a value occurs in a list: If the list is empty, return false; otherwise, If the first thing in the list is the given value, return true; otherwise Step past the first element, and test whether the value occurs in the remainder of the list
Backtracking algorithms Backtracking algorithms  are based on a depth-first recursive search A backtracking algorithm: Tests to see if a solution has been found, and if so, returns it; otherwise For each choice that can be made at this point, Make that choice Recur If the recursion returns a solution, return it If no choices remain, return failure
Example backtracking algorithm To color a map with no more than four colors: color(Country n) If all countries have been colored (n > number of countries) return success; otherwise, For each color c of four colors, If country n is not adjacent to a country that has been colored c Color country n with color c recursivly color country n+1 If successful, return success Return failure (if loop exits)
Divide and Conquer A  divide and conquer algorithm  consists of two parts: Divide the problem into smaller subproblems of the same type, and solve these subproblems recursively Combine the solutions to the subproblems into a solution to the original problem Traditionally, an algorithm is only called divide and conquer if it contains two or more recursive calls
Examples Quicksort: Partition the array into two parts, and quicksort each of the parts No additional work is required to combine the two sorted parts Mergesort: Cut the array in half, and mergesort each half Combine the two sorted arrays into a single sorted array by merging them
Binary tree lookup Here’s how to look up something in a sorted binary tree: Compare the key to the value in the root If the two values are equal, report success If the key is less, search the left subtree If the key is greater, search the right subtree This is  not  a divide and conquer algorithm because, although there are two recursive calls, only one is used at each level of the recursion
Fibonacci numbers To find the n th  Fibonacci number: If n is zero or one, return one; otherwise, Compute  fibonacci(n-1)  and  fibonacci(n-2) Return the sum of these two numbers This is an expensive algorithm It requires  O(fibonacci(n))  time This is equivalent to exponential time, that is,  O(2 n )
Dynamic programming algorithms A  dynamic programming algorithm  remembers past results and uses them to find new results Dynamic programming is generally used for optimization problems Multiple solutions exist, need to find the “best” one Requires “optimal substructure” and “overlapping subproblems” Optimal substructure : Optimal solution contains optimal solutions to subproblems Overlapping subproblems : Solutions to subproblems can be stored and reused in a bottom-up fashion This differs from Divide and Conquer, where subproblems generally need not overlap
Fibonacci numbers again To find the n th  Fibonacci number: If n is zero or one, return one; otherwise, Compute,  or look up in a table,   fibonacci(n-1)  and  fibonacci(n-2) Find the sum of these two numbers Store the result in a table and return it Since finding the n th  Fibonacci number involves finding all smaller Fibonacci numbers, the second recursive call has little work to do The table may be preserved and used again later
Greedy algorithms An  optimization problem  is one in which you want to find, not just  a  solution, but the  best  solution A “greedy algorithm” sometimes works well for optimization problems A  greedy algorithm  works in phases: At each phase: You take the best you can get right now, without regard for future consequences You hope that by choosing a  local  optimum at each step, you will end up at a  global  optimum
Example: Counting money Suppose you want to count out a certain amount of money, using the fewest possible bills and coins A greedy algorithm would do this would be: At each step, take the largest possible bill or coin that does not overshoot Example: To make $6.39, you can choose: a $5 bill a $1 bill, to make $6 a 25¢ coin, to make $6.25 A 10¢ coin, to make $6.35 four 1¢ coins, to make $6.39 For US money, the greedy algorithm always gives the optimum solution
A failure of the greedy algorithm In some (fictional) monetary system, “krons” come in  1  kron,  7  kron, and  10  kron coins Using a greedy algorithm to count out 15 krons, you would get A 10 kron piece Five 1 kron pieces, for a total of 15 krons This requires six coins A better solution would be to use two 7 kron pieces and one 1 kron piece This only requires three coins The greedy algorithm results in a solution, but not in an optimal solution
Branch and bound algorithms Branch and bound algorithms  are generally used for optimization problems As the algorithm progresses, a tree of subproblems is formed The original problem is considered the “root problem” A method is used to construct an upper and lower bound for a given problem At each node, apply the bounding methods If the bounds match, it is deemed a feasible solution to that particular subproblem If bounds do  not  match, partition the problem represented by that node, and make the two subproblems into children nodes Continue, using the best known feasible solution to trim sections of the tree, until all nodes have been solved or trimmed
Example branch and bound algorithm Travelling salesman problem: A salesman has to visit each of n cities (at least) once each, and wants to minimize total distance travelled Consider the root problem to be the problem of finding the shortest route through a set of cities visiting each city once Split the node into two child problems: Shortest route visiting city  A  first Shortest route  not  visiting city  A  first Continue subdividing similarly as the tree grows
Brute force algorithm A  brute force algorithm  simply tries  all  possibilities until a satisfactory solution is found Such an algorithm can be: Optimizing : Find the  best  solution. This may require finding all solutions, or if a value for the best solution is known, it may stop when any best solution is found Example: Finding the best path for a travelling salesman Satisficing : Stop as soon as a solution is found that is  good enough Example: Finding a travelling salesman path that is within 10% of optimal
Improving brute force algorithms Often, brute force algorithms require exponential time Various  heuristics  and  optimizations  can be used Heuristic : A “rule of thumb” that helps you decide which possibilities to look at first Optimization : In this case, a way to eliminate certain possibilites without fully exploring them
Randomized algorithms A  randomized algorithm  uses a random number at least once during the computation to make a decision Example: In Quicksort, using a random number to choose a pivot Example: Trying to factor a large prime by choosing random numbers as possible divisors
The End
Ad

More Related Content

What's hot (20)

03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
Lincoln School
 
Algorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisAlgorithms : Introduction and Analysis
Algorithms : Introduction and Analysis
Dhrumil Patel
 
Algorithm paradigms
Algorithm paradigmsAlgorithm paradigms
Algorithm paradigms
suresh5c2
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
Vinay Kumar C
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Lecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of AlgorithmsLecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of Algorithms
Rajesh K Shukla
 
EE235 Final Exam 2011
EE235 Final Exam 2011EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Aad introduction
Aad introductionAad introduction
Aad introduction
Mr SMAK
 
Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
MD.ASHIQUZZAMAN KHONDAKER
 
Csallner algorithms1
Csallner algorithms1Csallner algorithms1
Csallner algorithms1
seshagiri rao
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
Information Technology Center
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized Algorithms
KM Bappi
 
Problem solving
Problem solvingProblem solving
Problem solving
hamza239523
 
Daa presentation 97
Daa presentation 97Daa presentation 97
Daa presentation 97
Garima Verma
 
Lecture 1-cs648
Lecture 1-cs648Lecture 1-cs648
Lecture 1-cs648
Anshul Yadav
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
TayyabSattar5
 
How to study the theory of control
How to study the theory of controlHow to study the theory of control
How to study the theory of control
Ismail Mohamed
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
Anshul Yadav
 
Ways to evaluate a machine learning model’s performance
Ways to evaluate a machine learning model’s performanceWays to evaluate a machine learning model’s performance
Ways to evaluate a machine learning model’s performance
Mala Deep Upadhaya
 
Algorithm
AlgorithmAlgorithm
Algorithm
IHTISHAM UL HAQ
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
Lincoln School
 
Algorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisAlgorithms : Introduction and Analysis
Algorithms : Introduction and Analysis
Dhrumil Patel
 
Algorithm paradigms
Algorithm paradigmsAlgorithm paradigms
Algorithm paradigms
suresh5c2
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Lecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of AlgorithmsLecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of Algorithms
Rajesh K Shukla
 
EE235 Final Exam 2011
EE235 Final Exam 2011EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Aad introduction
Aad introductionAad introduction
Aad introduction
Mr SMAK
 
Csallner algorithms1
Csallner algorithms1Csallner algorithms1
Csallner algorithms1
seshagiri rao
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized Algorithms
KM Bappi
 
Daa presentation 97
Daa presentation 97Daa presentation 97
Daa presentation 97
Garima Verma
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
TayyabSattar5
 
How to study the theory of control
How to study the theory of controlHow to study the theory of control
How to study the theory of control
Ismail Mohamed
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
Anshul Yadav
 
Ways to evaluate a machine learning model’s performance
Ways to evaluate a machine learning model’s performanceWays to evaluate a machine learning model’s performance
Ways to evaluate a machine learning model’s performance
Mala Deep Upadhaya
 

Viewers also liked (20)

Daa
DaaDaa
Daa
Prabhat Agrawal
 
Chap08alg
Chap08algChap08alg
Chap08alg
Munkhchimeg
 
#1 designandanalysis of algo
#1 designandanalysis of algo#1 designandanalysis of algo
#1 designandanalysis of algo
Brijida Charizma Ardoña-Navarro
 
Slide1
Slide1Slide1
Slide1
Thiti Sununta
 
power efficient rake receiver for interference reduction in
power efficient rake receiver for  interference reduction inpower efficient rake receiver for  interference reduction in
power efficient rake receiver for interference reduction in
AKASH VIJAYAN
 
Signal modelling
Signal modellingSignal modelling
Signal modelling
Debangi_G
 
Ajal sree buddha
Ajal sree buddhaAjal sree buddha
Ajal sree buddha
AJAL A J
 
RADIATION & PROPAGATION - diversity
RADIATION & PROPAGATION - diversityRADIATION & PROPAGATION - diversity
RADIATION & PROPAGATION - diversity
AJAL A J
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
jayavignesh86
 
What Is Interleaving
What Is InterleavingWhat Is Interleaving
What Is Interleaving
pacproinc
 
Rake
RakeRake
Rake
AJAL A J
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Diversity techniques presentation material
Diversity techniques presentation materialDiversity techniques presentation material
Diversity techniques presentation material
Nini Lashari
 
rake reciever ppt
rake reciever pptrake reciever ppt
rake reciever ppt
Divya Shukla
 
Energy efficient communication techniques for wireless micro sensor networks
Energy efficient communication techniques for wireless micro sensor networksEnergy efficient communication techniques for wireless micro sensor networks
Energy efficient communication techniques for wireless micro sensor networks
Pushpita Biswas
 
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursiveC  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
rokiah64
 
Adaptive equalization
Adaptive equalizationAdaptive equalization
Adaptive equalization
Kamal Bhatt
 
Channel equalization
Channel equalizationChannel equalization
Channel equalization
Munnangi Anirudh
 
Matched filter
Matched filterMatched filter
Matched filter
srkrishna341
 
Diversity Techniques in Wireless Communication
Diversity Techniques in Wireless CommunicationDiversity Techniques in Wireless Communication
Diversity Techniques in Wireless Communication
Sahar Foroughi
 
power efficient rake receiver for interference reduction in
power efficient rake receiver for  interference reduction inpower efficient rake receiver for  interference reduction in
power efficient rake receiver for interference reduction in
AKASH VIJAYAN
 
Signal modelling
Signal modellingSignal modelling
Signal modelling
Debangi_G
 
Ajal sree buddha
Ajal sree buddhaAjal sree buddha
Ajal sree buddha
AJAL A J
 
RADIATION & PROPAGATION - diversity
RADIATION & PROPAGATION - diversityRADIATION & PROPAGATION - diversity
RADIATION & PROPAGATION - diversity
AJAL A J
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
jayavignesh86
 
What Is Interleaving
What Is InterleavingWhat Is Interleaving
What Is Interleaving
pacproinc
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Diversity techniques presentation material
Diversity techniques presentation materialDiversity techniques presentation material
Diversity techniques presentation material
Nini Lashari
 
Energy efficient communication techniques for wireless micro sensor networks
Energy efficient communication techniques for wireless micro sensor networksEnergy efficient communication techniques for wireless micro sensor networks
Energy efficient communication techniques for wireless micro sensor networks
Pushpita Biswas
 
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursiveC  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
rokiah64
 
Adaptive equalization
Adaptive equalizationAdaptive equalization
Adaptive equalization
Kamal Bhatt
 
Diversity Techniques in Wireless Communication
Diversity Techniques in Wireless CommunicationDiversity Techniques in Wireless Communication
Diversity Techniques in Wireless Communication
Sahar Foroughi
 
Ad

Similar to 35 algorithm-types (20)

35-algorithm-types.ppt
35-algorithm-types.ppt35-algorithm-types.ppt
35-algorithm-types.ppt
HarikumarRajandran1
 
algorithm-types.ppt
algorithm-types.pptalgorithm-types.ppt
algorithm-types.ppt
TusharSharma759024
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
EducationalJunction
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
ashish bansal
 
Algorithm types
Algorithm typesAlgorithm types
Algorithm types
JavariaIbrahim
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
ADT(Algorithm Design Technique Backtracking algorithm).ppt
ADT(Algorithm Design Technique Backtracking algorithm).pptADT(Algorithm Design Technique Backtracking algorithm).ppt
ADT(Algorithm Design Technique Backtracking algorithm).ppt
AnchalaSharma4
 
Algorithm designs and its technique.ppt
Algorithm designs and  its technique.pptAlgorithm designs and  its technique.ppt
Algorithm designs and its technique.ppt
AnchalaSharma4
 
algo classification.pptx
algo classification.pptxalgo classification.pptx
algo classification.pptx
ShivaniSharma335055
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdfLec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
MAJDABDALLAH3
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Disign and Analysis for algorithm in computer science and technology
Disign and Analysis for algorithm in computer science and technologyDisign and Analysis for algorithm in computer science and technology
Disign and Analysis for algorithm in computer science and technology
ritikkumarchaudhury7
 
Greedy algorithm for design and analysis
Greedy algorithm for design and analysisGreedy algorithm for design and analysis
Greedy algorithm for design and analysis
JavedKhan524377
 
algorithms-1 master in computer application
algorithms-1 master in computer applicationalgorithms-1 master in computer application
algorithms-1 master in computer application
hydratedpriyanshuvlo
 
analysis of algorithms and asymptotic complexity
analysis of algorithms and asymptotic complexityanalysis of algorithms and asymptotic complexity
analysis of algorithms and asymptotic complexity
anurag721001
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Backtracking
Backtracking  Backtracking
Backtracking
Vikas Sharma
 
Greedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.pptGreedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.ppt
SeethaDinesh
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
ADT(Algorithm Design Technique Backtracking algorithm).ppt
ADT(Algorithm Design Technique Backtracking algorithm).pptADT(Algorithm Design Technique Backtracking algorithm).ppt
ADT(Algorithm Design Technique Backtracking algorithm).ppt
AnchalaSharma4
 
Algorithm designs and its technique.ppt
Algorithm designs and  its technique.pptAlgorithm designs and  its technique.ppt
Algorithm designs and its technique.ppt
AnchalaSharma4
 
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdfLec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
MAJDABDALLAH3
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Disign and Analysis for algorithm in computer science and technology
Disign and Analysis for algorithm in computer science and technologyDisign and Analysis for algorithm in computer science and technology
Disign and Analysis for algorithm in computer science and technology
ritikkumarchaudhury7
 
Greedy algorithm for design and analysis
Greedy algorithm for design and analysisGreedy algorithm for design and analysis
Greedy algorithm for design and analysis
JavedKhan524377
 
algorithms-1 master in computer application
algorithms-1 master in computer applicationalgorithms-1 master in computer application
algorithms-1 master in computer application
hydratedpriyanshuvlo
 
analysis of algorithms and asymptotic complexity
analysis of algorithms and asymptotic complexityanalysis of algorithms and asymptotic complexity
analysis of algorithms and asymptotic complexity
anurag721001
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Greedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.pptGreedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.ppt
SeethaDinesh
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Ad

Recently uploaded (20)

Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 

35 algorithm-types

  • 2. Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together This classification scheme is neither exhaustive nor disjoint The purpose is not to be able to classify an algorithm as one type or another, but to highlight the various ways in which a problem can be attacked
  • 3. A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide and conquer algorithms Dynamic programming algorithms Greedy algorithms Branch and bound algorithms Brute force algorithms Randomized algorithms
  • 4. Simple recursive algorithms I A simple recursive algorithm : Solves the base cases directly Recurs with a simpler subproblem Does some extra work to convert the solution to the simpler subproblem into a solution to the given problem I call these “simple” because several of the other algorithm types are inherently recursive
  • 5. Example recursive algorithms To count the number of elements in a list: If the list is empty, return zero; otherwise, Step past the first element, and count the remaining elements in the list Add one to the result To test if a value occurs in a list: If the list is empty, return false; otherwise, If the first thing in the list is the given value, return true; otherwise Step past the first element, and test whether the value occurs in the remainder of the list
  • 6. Backtracking algorithms Backtracking algorithms are based on a depth-first recursive search A backtracking algorithm: Tests to see if a solution has been found, and if so, returns it; otherwise For each choice that can be made at this point, Make that choice Recur If the recursion returns a solution, return it If no choices remain, return failure
  • 7. Example backtracking algorithm To color a map with no more than four colors: color(Country n) If all countries have been colored (n > number of countries) return success; otherwise, For each color c of four colors, If country n is not adjacent to a country that has been colored c Color country n with color c recursivly color country n+1 If successful, return success Return failure (if loop exits)
  • 8. Divide and Conquer A divide and conquer algorithm consists of two parts: Divide the problem into smaller subproblems of the same type, and solve these subproblems recursively Combine the solutions to the subproblems into a solution to the original problem Traditionally, an algorithm is only called divide and conquer if it contains two or more recursive calls
  • 9. Examples Quicksort: Partition the array into two parts, and quicksort each of the parts No additional work is required to combine the two sorted parts Mergesort: Cut the array in half, and mergesort each half Combine the two sorted arrays into a single sorted array by merging them
  • 10. Binary tree lookup Here’s how to look up something in a sorted binary tree: Compare the key to the value in the root If the two values are equal, report success If the key is less, search the left subtree If the key is greater, search the right subtree This is not a divide and conquer algorithm because, although there are two recursive calls, only one is used at each level of the recursion
  • 11. Fibonacci numbers To find the n th Fibonacci number: If n is zero or one, return one; otherwise, Compute fibonacci(n-1) and fibonacci(n-2) Return the sum of these two numbers This is an expensive algorithm It requires O(fibonacci(n)) time This is equivalent to exponential time, that is, O(2 n )
  • 12. Dynamic programming algorithms A dynamic programming algorithm remembers past results and uses them to find new results Dynamic programming is generally used for optimization problems Multiple solutions exist, need to find the “best” one Requires “optimal substructure” and “overlapping subproblems” Optimal substructure : Optimal solution contains optimal solutions to subproblems Overlapping subproblems : Solutions to subproblems can be stored and reused in a bottom-up fashion This differs from Divide and Conquer, where subproblems generally need not overlap
  • 13. Fibonacci numbers again To find the n th Fibonacci number: If n is zero or one, return one; otherwise, Compute, or look up in a table, fibonacci(n-1) and fibonacci(n-2) Find the sum of these two numbers Store the result in a table and return it Since finding the n th Fibonacci number involves finding all smaller Fibonacci numbers, the second recursive call has little work to do The table may be preserved and used again later
  • 14. Greedy algorithms An optimization problem is one in which you want to find, not just a solution, but the best solution A “greedy algorithm” sometimes works well for optimization problems A greedy algorithm works in phases: At each phase: You take the best you can get right now, without regard for future consequences You hope that by choosing a local optimum at each step, you will end up at a global optimum
  • 15. Example: Counting money Suppose you want to count out a certain amount of money, using the fewest possible bills and coins A greedy algorithm would do this would be: At each step, take the largest possible bill or coin that does not overshoot Example: To make $6.39, you can choose: a $5 bill a $1 bill, to make $6 a 25¢ coin, to make $6.25 A 10¢ coin, to make $6.35 four 1¢ coins, to make $6.39 For US money, the greedy algorithm always gives the optimum solution
  • 16. A failure of the greedy algorithm In some (fictional) monetary system, “krons” come in 1 kron, 7 kron, and 10 kron coins Using a greedy algorithm to count out 15 krons, you would get A 10 kron piece Five 1 kron pieces, for a total of 15 krons This requires six coins A better solution would be to use two 7 kron pieces and one 1 kron piece This only requires three coins The greedy algorithm results in a solution, but not in an optimal solution
  • 17. Branch and bound algorithms Branch and bound algorithms are generally used for optimization problems As the algorithm progresses, a tree of subproblems is formed The original problem is considered the “root problem” A method is used to construct an upper and lower bound for a given problem At each node, apply the bounding methods If the bounds match, it is deemed a feasible solution to that particular subproblem If bounds do not match, partition the problem represented by that node, and make the two subproblems into children nodes Continue, using the best known feasible solution to trim sections of the tree, until all nodes have been solved or trimmed
  • 18. Example branch and bound algorithm Travelling salesman problem: A salesman has to visit each of n cities (at least) once each, and wants to minimize total distance travelled Consider the root problem to be the problem of finding the shortest route through a set of cities visiting each city once Split the node into two child problems: Shortest route visiting city A first Shortest route not visiting city A first Continue subdividing similarly as the tree grows
  • 19. Brute force algorithm A brute force algorithm simply tries all possibilities until a satisfactory solution is found Such an algorithm can be: Optimizing : Find the best solution. This may require finding all solutions, or if a value for the best solution is known, it may stop when any best solution is found Example: Finding the best path for a travelling salesman Satisficing : Stop as soon as a solution is found that is good enough Example: Finding a travelling salesman path that is within 10% of optimal
  • 20. Improving brute force algorithms Often, brute force algorithms require exponential time Various heuristics and optimizations can be used Heuristic : A “rule of thumb” that helps you decide which possibilities to look at first Optimization : In this case, a way to eliminate certain possibilites without fully exploring them
  • 21. Randomized algorithms A randomized algorithm uses a random number at least once during the computation to make a decision Example: In Quicksort, using a random number to choose a pivot Example: Trying to factor a large prime by choosing random numbers as possible divisors

Editor's Notes