SlideShare a Scribd company logo
Types of Algorithms
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
2
Algorithm classification
 Algorithms that use a similar problem-solving approach
can be grouped together
 We’ll talk about a classification scheme for algorithms
 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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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

recursively color country n+1

If successful, return success

If loop exits, return failure
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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 at least two recursive calls
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
9
Examples
 Quicksort:
 Partition the array into two parts (smaller numbers in one
part, larger numbers in the other part)
 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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
11
Fibonacci numbers
 To find the nth
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(2n
)
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
13
Fibonacci numbers again
 To find the nth
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 nth
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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 Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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 Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
18
Example branch and bound algorithm
 Traveling salesman problem: A salesman has to visit
each of n cities (at least) once each, and wants to
minimize total distance traveled
 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
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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 traveling salesman

Satisficing: Stop as soon as a solution is found that is good enough
 Example: Finding a traveling salesman path that is within 10%
of optimal
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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
possibilities without fully exploring them
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
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 number by choosing
random numbers as possible divisors
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
22
The End
Mohammed Imran Asad
ISIT
asadlabs@yahoo.com
Ad

More Related Content

What's hot (20)

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
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
Lincoln School
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
Vinay Kumar C
 
EE235 Final Exam 2011
EE235 Final Exam 2011EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Csallner algorithms1
Csallner algorithms1Csallner algorithms1
Csallner algorithms1
seshagiri rao
 
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
 
Aad introduction
Aad introductionAad introduction
Aad introduction
Mr SMAK
 
Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
MD.ASHIQUZZAMAN KHONDAKER
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
Information Technology Center
 
Problem solving
Problem solvingProblem solving
Problem solving
hamza239523
 
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
 
Daa presentation 97
Daa presentation 97Daa presentation 97
Daa presentation 97
Garima Verma
 
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 1-cs648
Lecture 1-cs648Lecture 1-cs648
Lecture 1-cs648
Anshul Yadav
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized Algorithms
KM Bappi
 
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
 
STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...
STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...
STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...
Wireilla
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
Anshul Yadav
 
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
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
Lincoln School
 
EE235 Final Exam 2011
EE235 Final Exam 2011EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Csallner algorithms1
Csallner algorithms1Csallner algorithms1
Csallner algorithms1
seshagiri rao
 
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
 
Aad introduction
Aad introductionAad introduction
Aad introduction
Mr SMAK
 
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
 
Daa presentation 97
Daa presentation 97Daa presentation 97
Daa presentation 97
Garima Verma
 
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
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized Algorithms
KM Bappi
 
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
 
STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...
STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...
STATISTICAL ANALYSIS OF FUZZY LINEAR REGRESSION MODEL BASED ON DIFFERENT DIST...
Wireilla
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
Anshul Yadav
 

Similar to 32 algorithm-types (20)

Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
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
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
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
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
Syed Zaid Irshad
 
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
 
Design and Analysis of Algorithms ppt by K. Adi
Design and Analysis of Algorithms ppt by K. AdiDesign and Analysis of Algorithms ppt by K. Adi
Design and Analysis of Algorithms ppt by K. Adi
Prof. Dr. K. Adisesha
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
B.Kirron Reddi
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
Low Ying Hao
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
Dr. SURBHI SAROHA
 
Algorithm - A set of rules for solving operations
Algorithm - A set of rules  for solving operationsAlgorithm - A set of rules  for solving operations
Algorithm - A set of rules for solving operations
Kumari99
 
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
 
algorithms-1 master in computer application
algorithms-1 master in computer applicationalgorithms-1 master in computer application
algorithms-1 master in computer application
hydratedpriyanshuvlo
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
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
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
Syed Zaid Irshad
 
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
 
Design and Analysis of Algorithms ppt by K. Adi
Design and Analysis of Algorithms ppt by K. AdiDesign and Analysis of Algorithms ppt by K. Adi
Design and Analysis of Algorithms ppt by K. Adi
Prof. Dr. K. Adisesha
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
Low Ying Hao
 
Algorithm - A set of rules for solving operations
Algorithm - A set of rules  for solving operationsAlgorithm - A set of rules  for solving operations
Algorithm - A set of rules for solving operations
Kumari99
 
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
 
algorithms-1 master in computer application
algorithms-1 master in computer applicationalgorithms-1 master in computer application
algorithms-1 master in computer application
hydratedpriyanshuvlo
 
Ad

More from ashish bansal (13)

Data struters
Data strutersData struters
Data struters
ashish bansal
 
Cis435 week05
Cis435 week05Cis435 week05
Cis435 week05
ashish bansal
 
Cis435 week04
Cis435 week04Cis435 week04
Cis435 week04
ashish bansal
 
Cis435 week03
Cis435 week03Cis435 week03
Cis435 week03
ashish bansal
 
Cis435 week02
Cis435 week02Cis435 week02
Cis435 week02
ashish bansal
 
Cis435 week01
Cis435 week01Cis435 week01
Cis435 week01
ashish bansal
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
ashish bansal
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
ashish bansal
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
ashish bansal
 
7 stacksqueues
7 stacksqueues7 stacksqueues
7 stacksqueues
ashish bansal
 
5 searching
5 searching5 searching
5 searching
ashish bansal
 
4 recursion
4 recursion4 recursion
4 recursion
ashish bansal
 
Cis435 week06
Cis435 week06Cis435 week06
Cis435 week06
ashish bansal
 
Ad

Recently uploaded (20)

To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
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
 
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
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
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
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
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
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
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
 
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
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
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
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
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
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
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
 
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
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
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
 
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
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
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
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 

32 algorithm-types

  • 2. 2 Algorithm classification  Algorithms that use a similar problem-solving approach can be grouped together  We’ll talk about a classification scheme for algorithms  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 Mohammed Imran Asad ISIT [email protected]
  • 3. 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 Mohammed Imran Asad ISIT [email protected]
  • 4. 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 Mohammed Imran Asad ISIT [email protected]
  • 5. 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 Mohammed Imran Asad ISIT [email protected]
  • 6. 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 Mohammed Imran Asad ISIT [email protected]
  • 7. 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  recursively color country n+1  If successful, return success  If loop exits, return failure Mohammed Imran Asad ISIT [email protected]
  • 8. 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 at least two recursive calls Mohammed Imran Asad ISIT [email protected]
  • 9. 9 Examples  Quicksort:  Partition the array into two parts (smaller numbers in one part, larger numbers in the other part)  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 Mohammed Imran Asad ISIT [email protected]
  • 10. 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 Mohammed Imran Asad ISIT [email protected]
  • 11. 11 Fibonacci numbers  To find the nth 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(2n ) Mohammed Imran Asad ISIT [email protected]
  • 12. 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 Mohammed Imran Asad ISIT [email protected]
  • 13. 13 Fibonacci numbers again  To find the nth 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 nth 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 Mohammed Imran Asad ISIT [email protected]
  • 14. 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 Mohammed Imran Asad ISIT [email protected]
  • 15. 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 Mohammed Imran Asad ISIT [email protected]
  • 16. 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 Mohammed Imran Asad ISIT [email protected]
  • 17. 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 Mohammed Imran Asad ISIT [email protected]
  • 18. 18 Example branch and bound algorithm  Traveling salesman problem: A salesman has to visit each of n cities (at least) once each, and wants to minimize total distance traveled  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 Mohammed Imran Asad ISIT [email protected]
  • 19. 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 traveling salesman  Satisficing: Stop as soon as a solution is found that is good enough  Example: Finding a traveling salesman path that is within 10% of optimal Mohammed Imran Asad ISIT [email protected]
  • 20. 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 possibilities without fully exploring them Mohammed Imran Asad ISIT [email protected]
  • 21. 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 number by choosing random numbers as possible divisors Mohammed Imran Asad ISIT [email protected]

Editor's Notes

  • #9: <number>
  • #10: <number>
  • #11: <number>
  • #15: <number>
  • #16: <number>
  • #17: <number>