SlideShare a Scribd company logo
ADT(Algorithm Design Technique Backtracking algorithm).ppt
General Concepts
 Algorithm strategy
 Approach to solving a problem
 May combine several approaches
 Algorithm structure
 Iterative  execute action in loop
 Recursive  reapply action to subproblem(s)
 Problem type
 Satisfying  find any satisfactory solution
 Optimization  find best solutions (vs. cost
metric)
Some Algorithm Strategies
 Recursive algorithms
 Backtracking algorithms
 Divide and conquer algorithms
 Dynamic programming algorithms
 Greedy algorithms
Recursive Algorithm
 Based on reapplying algorithm to subproblem
 Approach
1. Solves base case(s) directly
2. Recurs with a simpler subproblem
3. May need to convert solution(s) to subproblems
Recursive Algorithm –
Examples
 To count elements in list
 If list is empty, return 0
 Else skip 1st
element and recur on remainder of list
 Add 1 to result
 To find element in list
 If list is empty, return false
 Else if first element in list is given value, return
true
 Else skip 1st
element and recur on remainder of list
Backtracking Algorithm
 Based on depth-first recursive search
 Approach
1. Tests whether solution has been found
2. If found solution, return it
3. Else for each choice that can be made
a) Make that choice
b) Recur
c) If recursion returns a solution, return it
4. If no choices remain, return failure
 Some times called “search tree”
 Basically it is exhaustive search using divide and conquer.
 Sometimes the best algorithm for a problem is to try all possibilities.
 This is always slow.
 Backtracking speeds the exhaustive search by pruning.
Backtracking Algorithm Application
 Application to:
 The knapsack problem
 The Hamiltonian cycle problem
 The travelling salesperson problem
 The eight queen problem
Eight Queen Problem
Backtracking Algorithm – Example
 Find path through maze
 Start at beginning of maze
 If at exit, return true
 Else for each step from current location
 Recursively find path
 Return with first successful step
 Return false if all steps fail
Backtracking Algorithm – Example
 Color a map with no more than four colors
 If all countries have been colored return success
 Else for each color c of four colors and country n
 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
 Return failure
Divide and Conquer
 Based on dividing problem into subproblems
 Approach
1. Divide problem into smaller subproblems
Subproblems must be of same type
Subproblems do not need to overlap
2. Solve each subproblem recursively
3. Combine solutions to solve original problem
 Usually contains two or more recursive calls
Divide and Conquer – Examples
 Quicksort
 Partition array into two parts around pivot
 Recursively quicksort each part of array
 Concatenate solutions
Average Case Analysis of Quick Sort
Divide and Conquer – Examples
Average Case Analysis of Quick Sort
Divide and Conquer – Examples
Divide and Conquer – Examples
Divide and Conquer – Examples
 Mergesort
 Partition array into two parts
 Recursively mergesort each half
 Merge two sorted arrays into single sorted array
Dynamic Programming Algorithm
 Based on remembering past results
 Approach
1.Divide problem into smaller subproblems
Subproblems must be of same type
Subproblems must overlap
2.Solve each subproblem recursively
May simply look up solution
3.Combine solutions into to solve original problem
4.Store solution to problem
 Generally applied to optimization problems
Fibonacci Algorithm
 Fibonacci numbers
 fibonacci(0) = 1
 fibonacci(1) = 1
 fibonacci(n) = fibonacci(n-1) +
fibonacci(n-2)
 Recursive algorithm to calculate
fibonacci(n)
 If n is 0 or 1, return 1
 Else compute fibonacci(n-1) and
fibonacci(n-2)
 Return their sum
 Simple algorithm  exponential time
O(2n
)
BY USING DP
Dynamic programming version of fibonacci(n)
If n is 0 or 1, return 1
Else solve fibonacci(n-1) and fibonacci(n-2)
Look up value if previously computed
Else recursively compute
Find their sum and store
Return result
Dynamic programming algorithm  O(n) time
Since solving fibonacci(n-2) is just looking up value
Dynamic Programming – Example
 Combinations
 Knapsack problem
 Matrix product
 Dijkstra Algorithm
 Floyds Algorithm
Greedy Algorithm
 Based on trying best current (local) choice
 Approach
 At each step of algorithm
 Choose best local solution
 Avoid backtracking, exponential time O(2n
)
 Hope local optimum lead to global optimum
Greedy Algorithm – Example
Kruskal’s Minimal Spanning Tree
Algorithm
sort edges by weight (from least to most)
tree = 
for each edge (X,Y) in order
if it does not create a cycle
add (X,Y) to tree
stop when tree has N–1 edgesPicks best
local solution
at each step
ADT(Algorithm Design Technique Backtracking algorithm).ppt
Ad

More Related Content

Similar to ADT(Algorithm Design Technique Backtracking algorithm).ppt (20)

Types of algorithms
Types of algorithmsTypes of algorithms
Types of algorithms
Amelita Martinez
 
32 algorithm-types
32 algorithm-types32 algorithm-types
32 algorithm-types
ashish bansal
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
B.Kirron Reddi
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
sansaristic
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic Programming
Im Rafid
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
Ashwin Shiv
 
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
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
Deepak John
 
Backtracking
Backtracking  Backtracking
Backtracking
Vikas Sharma
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
jayavignesh86
 
DAA-Module-5.pptx
DAA-Module-5.pptxDAA-Module-5.pptx
DAA-Module-5.pptx
smithashetty24
 
Brute Force and Divide & Conquer Technique
Brute Force and Divide & Conquer TechniqueBrute Force and Divide & Conquer Technique
Brute Force and Divide & Conquer Technique
ssusered62011
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Yıldırım Tam
 
TRAVELING SALESMAN PROBLEM, Divide and Conquer
TRAVELING SALESMAN PROBLEM, Divide and ConquerTRAVELING SALESMAN PROBLEM, Divide and Conquer
TRAVELING SALESMAN PROBLEM, Divide and Conquer
DrSMeenakshiSundaram1
 
Algorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programmingAlgorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programming
Xochitl Watts
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
B.Kirron Reddi
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
Ada notes
Ada notesAda notes
Ada notes
VIKAS SINGH BHADOURIA
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic Programming
Im Rafid
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
Ashwin Shiv
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
Low Ying Hao
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
Deepak John
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
jayavignesh86
 
Brute Force and Divide & Conquer Technique
Brute Force and Divide & Conquer TechniqueBrute Force and Divide & Conquer Technique
Brute Force and Divide & Conquer Technique
ssusered62011
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
TRAVELING SALESMAN PROBLEM, Divide and Conquer
TRAVELING SALESMAN PROBLEM, Divide and ConquerTRAVELING SALESMAN PROBLEM, Divide and Conquer
TRAVELING SALESMAN PROBLEM, Divide and Conquer
DrSMeenakshiSundaram1
 
Algorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programmingAlgorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programming
Xochitl Watts
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 

Recently uploaded (20)

Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Ad

ADT(Algorithm Design Technique Backtracking algorithm).ppt

  • 2. General Concepts  Algorithm strategy  Approach to solving a problem  May combine several approaches  Algorithm structure  Iterative  execute action in loop  Recursive  reapply action to subproblem(s)  Problem type  Satisfying  find any satisfactory solution  Optimization  find best solutions (vs. cost metric)
  • 3. Some Algorithm Strategies  Recursive algorithms  Backtracking algorithms  Divide and conquer algorithms  Dynamic programming algorithms  Greedy algorithms
  • 4. Recursive Algorithm  Based on reapplying algorithm to subproblem  Approach 1. Solves base case(s) directly 2. Recurs with a simpler subproblem 3. May need to convert solution(s) to subproblems
  • 5. Recursive Algorithm – Examples  To count elements in list  If list is empty, return 0  Else skip 1st element and recur on remainder of list  Add 1 to result  To find element in list  If list is empty, return false  Else if first element in list is given value, return true  Else skip 1st element and recur on remainder of list
  • 6. Backtracking Algorithm  Based on depth-first recursive search  Approach 1. Tests whether solution has been found 2. If found solution, return it 3. Else for each choice that can be made a) Make that choice b) Recur c) If recursion returns a solution, return it 4. If no choices remain, return failure  Some times called “search tree”  Basically it is exhaustive search using divide and conquer.  Sometimes the best algorithm for a problem is to try all possibilities.  This is always slow.  Backtracking speeds the exhaustive search by pruning.
  • 7. Backtracking Algorithm Application  Application to:  The knapsack problem  The Hamiltonian cycle problem  The travelling salesperson problem  The eight queen problem Eight Queen Problem
  • 8. Backtracking Algorithm – Example  Find path through maze  Start at beginning of maze  If at exit, return true  Else for each step from current location  Recursively find path  Return with first successful step  Return false if all steps fail
  • 9. Backtracking Algorithm – Example  Color a map with no more than four colors  If all countries have been colored return success  Else for each color c of four colors and country n  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  Return failure
  • 10. Divide and Conquer  Based on dividing problem into subproblems  Approach 1. Divide problem into smaller subproblems Subproblems must be of same type Subproblems do not need to overlap 2. Solve each subproblem recursively 3. Combine solutions to solve original problem  Usually contains two or more recursive calls
  • 11. Divide and Conquer – Examples  Quicksort  Partition array into two parts around pivot  Recursively quicksort each part of array  Concatenate solutions Average Case Analysis of Quick Sort
  • 12. Divide and Conquer – Examples Average Case Analysis of Quick Sort
  • 13. Divide and Conquer – Examples
  • 14. Divide and Conquer – Examples
  • 15. Divide and Conquer – Examples  Mergesort  Partition array into two parts  Recursively mergesort each half  Merge two sorted arrays into single sorted array
  • 16. Dynamic Programming Algorithm  Based on remembering past results  Approach 1.Divide problem into smaller subproblems Subproblems must be of same type Subproblems must overlap 2.Solve each subproblem recursively May simply look up solution 3.Combine solutions into to solve original problem 4.Store solution to problem  Generally applied to optimization problems
  • 17. Fibonacci Algorithm  Fibonacci numbers  fibonacci(0) = 1  fibonacci(1) = 1  fibonacci(n) = fibonacci(n-1) + fibonacci(n-2)  Recursive algorithm to calculate fibonacci(n)  If n is 0 or 1, return 1  Else compute fibonacci(n-1) and fibonacci(n-2)  Return their sum  Simple algorithm  exponential time O(2n ) BY USING DP Dynamic programming version of fibonacci(n) If n is 0 or 1, return 1 Else solve fibonacci(n-1) and fibonacci(n-2) Look up value if previously computed Else recursively compute Find their sum and store Return result Dynamic programming algorithm  O(n) time Since solving fibonacci(n-2) is just looking up value
  • 18. Dynamic Programming – Example  Combinations  Knapsack problem  Matrix product  Dijkstra Algorithm  Floyds Algorithm
  • 19. Greedy Algorithm  Based on trying best current (local) choice  Approach  At each step of algorithm  Choose best local solution  Avoid backtracking, exponential time O(2n )  Hope local optimum lead to global optimum
  • 20. Greedy Algorithm – Example Kruskal’s Minimal Spanning Tree Algorithm sort edges by weight (from least to most) tree =  for each edge (X,Y) in order if it does not create a cycle add (X,Y) to tree stop when tree has N–1 edgesPicks best local solution at each step