SlideShare a Scribd company logo
Backtracking
Chapter 16
2012
Eng.sallysalem@gmail.com
 Backtracking is a systematic way to search for the
solution to a problem.
 solution space .
 This space must include at least one (optimal) solution to
the problem.
Examples
Rat in a Maze
 Consider the 3 × 3 rat-in-a-maze instance given by
the matrix
 Every path from vertex (1,1) to vertex (3,3)
 Green for alive node
 New green node is E-node
 Grey for dies 0 0 0
0 1
0
1
00
1 1 1
00
 The search begins at position (1,1), which is the only
live node at this time. It is also the E-node.
 To avoid going through this position again, we set
maze(1, 1) to 1.
 From this position we can move to either (1,2) or
(2,1).
 the maze has a 0 at each position
 the E-node (1,3), dies and we back up to the most
 recently seen live node, which is (1,2)
Traveling Salesperson
 we are given an n vertex network (either directed or
undirected) and are to find a cycle of minimum cost that
includes all n vertices. Any cycle that includes all n
vertices of a network is called a tour. In the traveling-
salesperson problem, we are to find a least-cost tour.
 1,2,4,3,1 ≡ 2,4,3,1,2 ≡ 4,3,1,2,4 ≡ 3,1,2,4,3
 1,2,4,3,1 reverse 1,3,4,2,1 = 66
 1,3,2,4,1 = 25
 1,4,3,2,1 = 59
Traveling Salesperson
 the path to node L represents the tour 1,2,3,4,1
 the path to node O represents the tour 1,3,4,2,1.
 Every tour in the network is represented by exactly one root-to-leaf
path in the tree.
 the number of leaves in the tree is (n − 1)!.
Cost = 59 Cost = 66 Cost = 25 Cost = 66 Cost = 25 Cost = 65
Traveling Salesperson
 A backtracking algorithm will find a minimum-cost tour by searching
the solution space tree in a depth-first manner, beginning at the root.
 At L the tour1,2,3,4,1 is recorded as the best tour seen so far. Its
cost is 59.
 From L we back- track to the live node F. As F has no unexamined
children, it is killed and we backtrack to node C. C becomes the E-
node, and we move forward to G and then to M. We have now
constructed the tour 1,2,4,3,1 whose cost is 66. Since this tour isn’t
superior to the best tour we have, we discard the new tour and
backtrack to G, then C, and then B
 From B the search moves forward to D and then to H and
 N. The tour 1,3,2,4,1 defined at N has cost 25 and is better than the
previous best tour. We save 1,3,2,4,1 as the best tour seen so far.
From N the search backtracks to H and then to D. At D we can again
move forward. We reach node O.
 Continuing in this way, we search the entire tree; 1,3,2,4,1 is the
least-cost tour.
Applications
Container Loading
 The problem
 We have two ships and n containers. The capacity of
the first ship is c1, and that of the second c2. wi is the
weight of container i, and .
 We wish to determine whether there is a way to load all
n containers.
 Example
 When n = 3, c1 = c2 = 50, and w = [10, 40, 40],
 we can load containers 1 and 2 onto the first ship and
container 3 onto the second ship.
 If the weights are [20, 40, 40], then we cannot load the
containers onto the ships.
Container Loading
 You may verify that the following strategy to load
the two ships succeeds whenever there is a way
to load all n containers:
(1) load the first ship as close to its capacity as
possible (2) put the remaining containers into
the second ship.
Container Loading
 we need to select a subset of containers with total weight
as close to c1 as possible.
 we can use the dynamic-programming solution to
determine the best loading of the first ship.
 The time needed is O(min{c1, 2n}) with the tuple method.
 We can use the backtracking method to develop an
O(2n) algorithm that can outperform the dynamic-
programming algorithm
First Backtracking Solution
 Example
 Suppose that n = 4, w = [8, 6, 2, 3], and c1 = 12.
cw = 0
cw = 8
cw = 14 >
c1
cw = 8
cw =
10
1
cw =
0
cw = 10 xi values are [1, 0, 1, 0]
cw = 8
1
cw = 11 xi values are [1, 0, 0, 1]
First Backtracking Solution
 The solution space will be searched in a depth-
first manner for the best solution.
 If Z is a node on level j +1 of the tree,
then the path from the root to Z defines values
for xi, 1 ≤ i ≤ j.
 Using these values, define cw (current weight) to
be
 If cw > c1 then the subtree with root Z cannot
contain a feasible solution.
 whether cw = c1. If it does, then we can
terminate the search for the subset with the sum
First Backtracking Solution
Second Backtracking Solution
 We can improve the expected performance of function rLoad by not
moving into right subtrees that cannot possibly contain better
solutions than the best found so far.
 n = 4, w = [8, 6, 2, 3], and c1 = 12.
cw = 0
cw = 8
cw = 8
cw =
10
0
cw = 10 xi values are [1, 0, 1, 0]
cw = 8
1
cw = 11 xi values are [1, 0, 0, 1]
remaining=4
And weight=6
Remainging < weight
Second Backtracking Solution
Finding the Best Subset
 To remember this subset, we employ a one-dimensional
array bestLoadingSoFar.
 The array currentLoading is used to record the path
from the search tree root to the current node (i.e., it
saves the xi values on this path)
 The array bestLoadingSoFar records the best solution
found so far. Whenever a leaf with a better value is
reached, bestLoadingSoFar is updated to represent the
path from the root to this leaf.
Finding the Best Subset
Finding the Best Subset
Max Clique
 A subset U of the vertices of an undirected graph G
defines a complete subgraph iff for every u and v in U,
(u, v) is an edge of G.
 The size of a subgraph is the number of vertices in it.
 A complete subgraph is a clique of G iff it is not
contained in a larger complete subgraph of G. A max
clique is a clique of maximum size.
Max Clique
 Example
 max clique
 it is contained in a larger complete subgraph
 1, 2, 5
 1, 4, 5
 2, 3, 5
 Independent set of G (Complement )
 (u, v) is an edge of iff (u, v) is not an
edge of G
 {1,2} defines an empty subgraph
 Notice that if U defines a complete subgraph
of G, then U also defines an emptysubgraph
of G
Max Clique
 Example
 Suppose we have a collection of n animals. We may
define a compatibility graph G that has n vertices. (u, v) is
an edge of G iff animals u and v are compatible.
 A max clique of G defines a largest subset of mutually
compatible animals.
The max-clique problem is to find a max clique of the
graph G.
Similarly,
the max-independent-set problem is to find a max-
independent set of .
Max Clique
 Backtracking solution
 When attempting to move to the left child of a level i
node Z of the space tree, we need to verify that there
is an edge from vertex i every other vertex, j
Empty
4 52 31
1, 51, 2 1, 4 2, 3 2, 5
1, 2, 5
Board Permutation
 Problem Description
Has n circuit boards that are to be placed into slots
in a cage
 Placement of the boards B = {b1, · · ·, bn}
 m Nets on the boards L = {N1, · · ·, Nm}
Board Permutation
 Example
 Let n = 8 and m = 5. Let the boards and nets be as given below.
 B = {b1, b2, b3, b4, b5, b6, b7, b8}
 L = {N1,N2,N3,N4,N5}
 N1 = {b4, b5, b6}
 N2 = {b2, b3}
 N3 = {b1, b3}
 N4 = {b3, b6}
 N5 = {b7, b8}
Board Permutation
 The backtracking algorithm will search a permutation
space for the best board permutation.
 represent the input as an integer array board such
that board[i][j] is 1 iff net Nj includes board bi
 boardsWithNet[j] be the number of boards that
include net Nj .
 boardsInPartialWithNet[j] be the number of boards
in partial[1:i]
Thank you

More Related Content

What's hot

I. Hill climbing algorithm II. Steepest hill climbing algorithm
I. Hill climbing algorithm II. Steepest hill climbing algorithmI. Hill climbing algorithm II. Steepest hill climbing algorithm
I. Hill climbing algorithm II. Steepest hill climbing algorithm
vikas dhakane
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
Hema Kashyap
 
unit 4 ai.pptx
unit 4 ai.pptxunit 4 ai.pptx
unit 4 ai.pptx
ShivaDhfm
 
Informed and Uninformed search Strategies
Informed and Uninformed search StrategiesInformed and Uninformed search Strategies
Informed and Uninformed search Strategies
Amey Kerkar
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
Informed search (heuristics)
Informed search (heuristics)Informed search (heuristics)
Informed search (heuristics)
Bablu Shofi
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
Asst.prof M.Gokilavani
 
Lecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithmLecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithm
Hema Kashyap
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
Dr. C.V. Suresh Babu
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
Amin Omi
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1Kumar
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
 
Resolution method in AI.pptx
Resolution method in AI.pptxResolution method in AI.pptx
Resolution method in AI.pptx
Abdullah251975
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programingrupali_2bonde
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
srilekhagourishetty
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
Sampath Kumar S
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Tic tac toe simple ai game
Tic tac toe simple ai gameTic tac toe simple ai game
Tic tac toe simple ai game
Seevaratnam Kajandan
 

What's hot (20)

Backtracking
BacktrackingBacktracking
Backtracking
 
I. Hill climbing algorithm II. Steepest hill climbing algorithm
I. Hill climbing algorithm II. Steepest hill climbing algorithmI. Hill climbing algorithm II. Steepest hill climbing algorithm
I. Hill climbing algorithm II. Steepest hill climbing algorithm
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
 
unit 4 ai.pptx
unit 4 ai.pptxunit 4 ai.pptx
unit 4 ai.pptx
 
Informed and Uninformed search Strategies
Informed and Uninformed search StrategiesInformed and Uninformed search Strategies
Informed and Uninformed search Strategies
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
Informed search (heuristics)
Informed search (heuristics)Informed search (heuristics)
Informed search (heuristics)
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
 
Lecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithmLecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithm
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Resolution method in AI.pptx
Resolution method in AI.pptxResolution method in AI.pptx
Resolution method in AI.pptx
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Tic tac toe simple ai game
Tic tac toe simple ai gameTic tac toe simple ai game
Tic tac toe simple ai game
 

Similar to Backtracking

Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
Nv Thejaswini
 
Answers withexplanations
Answers withexplanationsAnswers withexplanations
Answers withexplanations
Gopi Saiteja
 
Branch and bound method
Branch and bound methodBranch and bound method
Branch and bound method
VidhyaSenthil
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
B.Kirron Reddi
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
B.Kirron Reddi
 
Stochastic Process Exam Help
Stochastic Process Exam HelpStochastic Process Exam Help
Stochastic Process Exam Help
Statistics Exam Help
 
Unit 3
Unit 3Unit 3
Unit 3
guna287176
 
Data structure notes
Data structure notesData structure notes
Data structure notes
anujab5
 
Stochastic Process Assignment Help
Stochastic Process Assignment HelpStochastic Process Assignment Help
Stochastic Process Assignment Help
Statistics Assignment Help
 
Binomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsBinomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relations
Aqeel Rafique
 
MTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docxMTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docx
gilpinleeanna
 
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdfUnit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
 
designanalysisalgorithm_unit-v-part2.pptx
designanalysisalgorithm_unit-v-part2.pptxdesignanalysisalgorithm_unit-v-part2.pptx
designanalysisalgorithm_unit-v-part2.pptx
arifimad15
 
Design & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment HelpDesign & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment Help
Computer Network Assignment Help
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
Excel Homework Help
 
Conjugate Gradient Methods
Conjugate Gradient MethodsConjugate Gradient Methods
Conjugate Gradient Methods
MTiti1
 
Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
Programming Homework Help
 
Developing Expert Voices
Developing Expert VoicesDeveloping Expert Voices
Developing Expert Voicessuzanne
 

Similar to Backtracking (20)

Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Answers withexplanations
Answers withexplanationsAnswers withexplanations
Answers withexplanations
 
Branch and bound method
Branch and bound methodBranch and bound method
Branch and bound method
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 
Stochastic Process Exam Help
Stochastic Process Exam HelpStochastic Process Exam Help
Stochastic Process Exam Help
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
Data structure notes
Data structure notesData structure notes
Data structure notes
 
Stochastic Process Assignment Help
Stochastic Process Assignment HelpStochastic Process Assignment Help
Stochastic Process Assignment Help
 
Binomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsBinomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relations
 
MTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docxMTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docx
 
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdfUnit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
 
designanalysisalgorithm_unit-v-part2.pptx
designanalysisalgorithm_unit-v-part2.pptxdesignanalysisalgorithm_unit-v-part2.pptx
designanalysisalgorithm_unit-v-part2.pptx
 
Design & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment HelpDesign & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment Help
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
 
Conjugate Gradient Methods
Conjugate Gradient MethodsConjugate Gradient Methods
Conjugate Gradient Methods
 
Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
 
Developing Expert Voices
Developing Expert VoicesDeveloping Expert Voices
Developing Expert Voices
 

Recently uploaded

Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 

Recently uploaded (20)

Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 

Backtracking

  • 2.  Backtracking is a systematic way to search for the solution to a problem.  solution space .  This space must include at least one (optimal) solution to the problem.
  • 4. Rat in a Maze  Consider the 3 × 3 rat-in-a-maze instance given by the matrix  Every path from vertex (1,1) to vertex (3,3)  Green for alive node  New green node is E-node  Grey for dies 0 0 0 0 1 0 1 00 1 1 1 00
  • 5.  The search begins at position (1,1), which is the only live node at this time. It is also the E-node.  To avoid going through this position again, we set maze(1, 1) to 1.  From this position we can move to either (1,2) or (2,1).  the maze has a 0 at each position  the E-node (1,3), dies and we back up to the most  recently seen live node, which is (1,2)
  • 6. Traveling Salesperson  we are given an n vertex network (either directed or undirected) and are to find a cycle of minimum cost that includes all n vertices. Any cycle that includes all n vertices of a network is called a tour. In the traveling- salesperson problem, we are to find a least-cost tour.  1,2,4,3,1 ≡ 2,4,3,1,2 ≡ 4,3,1,2,4 ≡ 3,1,2,4,3  1,2,4,3,1 reverse 1,3,4,2,1 = 66  1,3,2,4,1 = 25  1,4,3,2,1 = 59
  • 7. Traveling Salesperson  the path to node L represents the tour 1,2,3,4,1  the path to node O represents the tour 1,3,4,2,1.  Every tour in the network is represented by exactly one root-to-leaf path in the tree.  the number of leaves in the tree is (n − 1)!. Cost = 59 Cost = 66 Cost = 25 Cost = 66 Cost = 25 Cost = 65
  • 8. Traveling Salesperson  A backtracking algorithm will find a minimum-cost tour by searching the solution space tree in a depth-first manner, beginning at the root.  At L the tour1,2,3,4,1 is recorded as the best tour seen so far. Its cost is 59.  From L we back- track to the live node F. As F has no unexamined children, it is killed and we backtrack to node C. C becomes the E- node, and we move forward to G and then to M. We have now constructed the tour 1,2,4,3,1 whose cost is 66. Since this tour isn’t superior to the best tour we have, we discard the new tour and backtrack to G, then C, and then B  From B the search moves forward to D and then to H and  N. The tour 1,3,2,4,1 defined at N has cost 25 and is better than the previous best tour. We save 1,3,2,4,1 as the best tour seen so far. From N the search backtracks to H and then to D. At D we can again move forward. We reach node O.  Continuing in this way, we search the entire tree; 1,3,2,4,1 is the least-cost tour.
  • 10. Container Loading  The problem  We have two ships and n containers. The capacity of the first ship is c1, and that of the second c2. wi is the weight of container i, and .  We wish to determine whether there is a way to load all n containers.  Example  When n = 3, c1 = c2 = 50, and w = [10, 40, 40],  we can load containers 1 and 2 onto the first ship and container 3 onto the second ship.  If the weights are [20, 40, 40], then we cannot load the containers onto the ships.
  • 11. Container Loading  You may verify that the following strategy to load the two ships succeeds whenever there is a way to load all n containers: (1) load the first ship as close to its capacity as possible (2) put the remaining containers into the second ship.
  • 12. Container Loading  we need to select a subset of containers with total weight as close to c1 as possible.  we can use the dynamic-programming solution to determine the best loading of the first ship.  The time needed is O(min{c1, 2n}) with the tuple method.  We can use the backtracking method to develop an O(2n) algorithm that can outperform the dynamic- programming algorithm
  • 13. First Backtracking Solution  Example  Suppose that n = 4, w = [8, 6, 2, 3], and c1 = 12. cw = 0 cw = 8 cw = 14 > c1 cw = 8 cw = 10 1 cw = 0 cw = 10 xi values are [1, 0, 1, 0] cw = 8 1 cw = 11 xi values are [1, 0, 0, 1]
  • 14. First Backtracking Solution  The solution space will be searched in a depth- first manner for the best solution.  If Z is a node on level j +1 of the tree, then the path from the root to Z defines values for xi, 1 ≤ i ≤ j.  Using these values, define cw (current weight) to be  If cw > c1 then the subtree with root Z cannot contain a feasible solution.  whether cw = c1. If it does, then we can terminate the search for the subset with the sum
  • 16. Second Backtracking Solution  We can improve the expected performance of function rLoad by not moving into right subtrees that cannot possibly contain better solutions than the best found so far.  n = 4, w = [8, 6, 2, 3], and c1 = 12. cw = 0 cw = 8 cw = 8 cw = 10 0 cw = 10 xi values are [1, 0, 1, 0] cw = 8 1 cw = 11 xi values are [1, 0, 0, 1] remaining=4 And weight=6 Remainging < weight
  • 18. Finding the Best Subset  To remember this subset, we employ a one-dimensional array bestLoadingSoFar.  The array currentLoading is used to record the path from the search tree root to the current node (i.e., it saves the xi values on this path)  The array bestLoadingSoFar records the best solution found so far. Whenever a leaf with a better value is reached, bestLoadingSoFar is updated to represent the path from the root to this leaf.
  • 21. Max Clique  A subset U of the vertices of an undirected graph G defines a complete subgraph iff for every u and v in U, (u, v) is an edge of G.  The size of a subgraph is the number of vertices in it.  A complete subgraph is a clique of G iff it is not contained in a larger complete subgraph of G. A max clique is a clique of maximum size.
  • 22. Max Clique  Example  max clique  it is contained in a larger complete subgraph  1, 2, 5  1, 4, 5  2, 3, 5  Independent set of G (Complement )  (u, v) is an edge of iff (u, v) is not an edge of G  {1,2} defines an empty subgraph  Notice that if U defines a complete subgraph of G, then U also defines an emptysubgraph of G
  • 23. Max Clique  Example  Suppose we have a collection of n animals. We may define a compatibility graph G that has n vertices. (u, v) is an edge of G iff animals u and v are compatible.  A max clique of G defines a largest subset of mutually compatible animals. The max-clique problem is to find a max clique of the graph G. Similarly, the max-independent-set problem is to find a max- independent set of .
  • 24. Max Clique  Backtracking solution  When attempting to move to the left child of a level i node Z of the space tree, we need to verify that there is an edge from vertex i every other vertex, j Empty 4 52 31 1, 51, 2 1, 4 2, 3 2, 5 1, 2, 5
  • 25.
  • 26.
  • 27.
  • 28. Board Permutation  Problem Description Has n circuit boards that are to be placed into slots in a cage  Placement of the boards B = {b1, · · ·, bn}  m Nets on the boards L = {N1, · · ·, Nm}
  • 29. Board Permutation  Example  Let n = 8 and m = 5. Let the boards and nets be as given below.  B = {b1, b2, b3, b4, b5, b6, b7, b8}  L = {N1,N2,N3,N4,N5}  N1 = {b4, b5, b6}  N2 = {b2, b3}  N3 = {b1, b3}  N4 = {b3, b6}  N5 = {b7, b8}
  • 30. Board Permutation  The backtracking algorithm will search a permutation space for the best board permutation.  represent the input as an integer array board such that board[i][j] is 1 iff net Nj includes board bi  boardsWithNet[j] be the number of boards that include net Nj .  boardsInPartialWithNet[j] be the number of boards in partial[1:i]
  • 31.
  • 32.
  • 33.
  • 34.

Editor's Notes

  1. 1,4,3,2,1 = 29 (1,2, 3, 4, 1)
  2. 1,4,3,2,1 = 29 (1,2, 3, 4, 1)
  3. 1,4,3,2,1 = 29 (1,2, 3, 4, 1)