SlideShare a Scribd company logo
BACKTRACK SEARCH
ALGORITHM
BACKTRACKING
 Suppose you have to make a series of decisions,
among various choices, where
 You don’t have enough information to know what to
choose
 Each decision leads to a new set of choices
 Some sequence of choices (possibly more than one)
may be a solution to your problem
 Backtracking is a methodical way of trying out
various sequences of decisions, until you find the
correct one that “works”.
BACKTRACKING
 Backtracking is used to solve problems in which a
sequence of objects is chosen from a specified set
so that the sequence satisfies some criterion.
 Backtracking is a modified depth-first search of a
tree.
 It is the procedure whereby, after determining that a
node can lead to nothing but dead nodes, we go
back (“backtrack”) to the node’s parent and proceed
with the search on the next child.
BACKTRACK 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) Recursive
c) If recursion returns a solution, return it
4. If no choices remain, return failure
 Some times called “search tree”
IMPROVING BACKTRACKING
 Search pruning will help us to reduce the search
space and hence get a solution faster.
 The idea is to avoid those paths that may not lead
to a solutions as early as possible by finding
contradictions so that we can backtrack
immediately without the need to build a hopeless
solution vector.
BACKTRACKING EXAMPLES
 The backtracking can be used in this cases:
Solving a maze
Coloring a map
Solving a puzzle
N queens problem etc.,
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM
 The 8-queens problem is a classical combinatorial
problem in which it is required to place eight
queens on an 8 x 8 chessboard so no two can
attack each other.
 A queen can attack another queen if it exists in the
same row, column or diagonal as the queen.
7
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 This problem can be solved by trying to place the
first queen, then the second queen so that it cannot
attack the first, and then the third so that it is not
conflicting with previously placed queens.
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 It is an empty 8 x 8
chess board. We have
to place the queens in
this board.
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 We have placed the
first queen on the
chess board
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 Then we have placed
the second queen on
the board.
 The darken place
should not have the
queens because they
are horizontal, vertical,
diagonal to the placed
queens.
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 We have placed the
third queen on board.
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 We have placed the 4th
queen on the board.
 We have placed that in
the wrong spot, so we
backtrack and change
the place of that one.
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 In this way, we have to
continue the process
untill our is reached ie.,
we must place 8
queens on the board.
BACKTRACKING EXAMPLE—8 QUEENS
PROBLEM(CONT…)
 Backtracking provides the hope to solve some
problem instances of nontrivial sizes by pruning
non-promising branches of the state-space tree.
 The success of backtracking varies from problem
to problem and from instance to instance.
 Backtracking possibly generates all possible
candidates in an exponentially growing state-
space tree.
PARALLELIZING BACKTRACK ALGORITHM
 First, we have to parallelize the root node of the
algorithm.
 Then the sub nodes and the child nodes should be
parallelized independently using the other
processors.
 For example, if we take the 8 queens problem then
it can be easily implemented in parallel.
 The N-queens problem can be parallelized in this
way.
PARALLELIZING BACKTRACK ALGORITHM
 The solutions to the n-queens problem can be
generated in parallel by using the master-worker
technique.
 The manager generates the upper portion of the
search tree by generating those nodes of fixed
depth d, for some d.
 The manager dynamically passes each of these
sequences to an idle worker, who in turn continues
to search for sequences with n-queens property
that contain the fixed subsequence of length d.
 The master-worker technique is particularly well-
suited for implementation with MPI
PARALLELIZING BACKTRACK ALGORITHM
 Parallelizing the backtrack algorithm will gives us a
good speedup and efficiency when compared to the
normal algorithm.
 The speedup and the efficiency will gets drastically
increased when it is done in the parallel.
THANK YOU!!!

More Related Content

PPTX
Mult and divide sci not. 1 9 c
DOC
HW2-1_05.doc
PDF
Nl eqn lab
DOC
Lesson 8
PDF
backtracking algorithms of ada
PDF
Application of Chebyshev and Markov Inequality in Machine Learning
PPTX
Backtrack-search-algorithm (2).pptx
PPTX
Backtracking Basics.pptx
Mult and divide sci not. 1 9 c
HW2-1_05.doc
Nl eqn lab
Lesson 8
backtracking algorithms of ada
Application of Chebyshev and Markov Inequality in Machine Learning
Backtrack-search-algorithm (2).pptx
Backtracking Basics.pptx

Similar to Backtrack search-algorithm (20)

PPTX
Branch and bound
PPTX
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
PPTX
Back tracking and branch and bound class 20
PDF
module5_backtrackingnbranchnbound_2022.pdf
PPTX
8 QUEENS PROBLEM.pptx
PPTX
data structures- back tracking
PPTX
Backtracking
PPTX
Design Algorithms - - Backtracking.pptx
PPT
BackTracking Algorithm: Technique and Examples
PDF
N Queens problem
PPT
5.5 back track
PPTX
Backtracking Algorithm.pptx
PPT
(Radhika) presentation on chapter 2 ai
PPT
Optimization problems
PPT
Knapsack problem using fixed tuple
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
PDF
Equations and tilings
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Branch and bound
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
Back tracking and branch and bound class 20
module5_backtrackingnbranchnbound_2022.pdf
8 QUEENS PROBLEM.pptx
data structures- back tracking
Backtracking
Design Algorithms - - Backtracking.pptx
BackTracking Algorithm: Technique and Examples
N Queens problem
5.5 back track
Backtracking Algorithm.pptx
(Radhika) presentation on chapter 2 ai
Optimization problems
Knapsack problem using fixed tuple
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Equations and tilings
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Ad

More from Ruchika Sinha (20)

PPT
Python Programming Introduction - Loops & Boolean
PPTX
Difference Between Normal & Smart/Automated Home
PPT
Greedy Algorithms WITH Activity Selection Problem.ppt
PPT
Greedy with Task Scheduling Algorithm.ppt
PPT
Greedy Algorithms Huffman Coding.ppt
PPT
DynProg_Knapsack.ppt
PPT
Dijkstra.ppt
PPT
Greedy with Task Scheduling Algorithm.ppt
PPT
Clipping
PPT
Lec22 intel
PPTX
Pc assembly
PPT
PPTX
Installation of motherboard
PPT
Shortest path
PPT
Bellman ford algorithm
PPTX
Python material
PPT
Python3
PPT
Regular Grammar
PPTX
Software Teting
PPTX
Python Programming Introduction - Loops & Boolean
Difference Between Normal & Smart/Automated Home
Greedy Algorithms WITH Activity Selection Problem.ppt
Greedy with Task Scheduling Algorithm.ppt
Greedy Algorithms Huffman Coding.ppt
DynProg_Knapsack.ppt
Dijkstra.ppt
Greedy with Task Scheduling Algorithm.ppt
Clipping
Lec22 intel
Pc assembly
Installation of motherboard
Shortest path
Bellman ford algorithm
Python material
Python3
Regular Grammar
Software Teting
Ad

Recently uploaded (20)

PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
composite construction of structures.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
web development for engineering and engineering
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Construction Project Organization Group 2.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CH1 Production IntroductoryConcepts.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
composite construction of structures.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
web development for engineering and engineering
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Operating System & Kernel Study Guide-1 - converted.pdf
additive manufacturing of ss316l using mig welding
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
bas. eng. economics group 4 presentation 1.pptx
Internet of Things (IOT) - A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
UNIT 4 Total Quality Management .pptx
Construction Project Organization Group 2.pptx

Backtrack search-algorithm

  • 2. BACKTRACKING  Suppose you have to make a series of decisions, among various choices, where  You don’t have enough information to know what to choose  Each decision leads to a new set of choices  Some sequence of choices (possibly more than one) may be a solution to your problem  Backtracking is a methodical way of trying out various sequences of decisions, until you find the correct one that “works”.
  • 3. BACKTRACKING  Backtracking is used to solve problems in which a sequence of objects is chosen from a specified set so that the sequence satisfies some criterion.  Backtracking is a modified depth-first search of a tree.  It is the procedure whereby, after determining that a node can lead to nothing but dead nodes, we go back (“backtrack”) to the node’s parent and proceed with the search on the next child.
  • 4. BACKTRACK 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) Recursive c) If recursion returns a solution, return it 4. If no choices remain, return failure  Some times called “search tree”
  • 5. IMPROVING BACKTRACKING  Search pruning will help us to reduce the search space and hence get a solution faster.  The idea is to avoid those paths that may not lead to a solutions as early as possible by finding contradictions so that we can backtrack immediately without the need to build a hopeless solution vector.
  • 6. BACKTRACKING EXAMPLES  The backtracking can be used in this cases: Solving a maze Coloring a map Solving a puzzle N queens problem etc.,
  • 7. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM  The 8-queens problem is a classical combinatorial problem in which it is required to place eight queens on an 8 x 8 chessboard so no two can attack each other.  A queen can attack another queen if it exists in the same row, column or diagonal as the queen. 7
  • 8. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  This problem can be solved by trying to place the first queen, then the second queen so that it cannot attack the first, and then the third so that it is not conflicting with previously placed queens.
  • 9. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  It is an empty 8 x 8 chess board. We have to place the queens in this board.
  • 10. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  We have placed the first queen on the chess board
  • 11. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  Then we have placed the second queen on the board.  The darken place should not have the queens because they are horizontal, vertical, diagonal to the placed queens.
  • 12. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  We have placed the third queen on board.
  • 13. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  We have placed the 4th queen on the board.  We have placed that in the wrong spot, so we backtrack and change the place of that one.
  • 14. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  In this way, we have to continue the process untill our is reached ie., we must place 8 queens on the board.
  • 15. BACKTRACKING EXAMPLE—8 QUEENS PROBLEM(CONT…)  Backtracking provides the hope to solve some problem instances of nontrivial sizes by pruning non-promising branches of the state-space tree.  The success of backtracking varies from problem to problem and from instance to instance.  Backtracking possibly generates all possible candidates in an exponentially growing state- space tree.
  • 16. PARALLELIZING BACKTRACK ALGORITHM  First, we have to parallelize the root node of the algorithm.  Then the sub nodes and the child nodes should be parallelized independently using the other processors.  For example, if we take the 8 queens problem then it can be easily implemented in parallel.  The N-queens problem can be parallelized in this way.
  • 17. PARALLELIZING BACKTRACK ALGORITHM  The solutions to the n-queens problem can be generated in parallel by using the master-worker technique.  The manager generates the upper portion of the search tree by generating those nodes of fixed depth d, for some d.  The manager dynamically passes each of these sequences to an idle worker, who in turn continues to search for sequences with n-queens property that contain the fixed subsequence of length d.  The master-worker technique is particularly well- suited for implementation with MPI
  • 18. PARALLELIZING BACKTRACK ALGORITHM  Parallelizing the backtrack algorithm will gives us a good speedup and efficiency when compared to the normal algorithm.  The speedup and the efficiency will gets drastically increased when it is done in the parallel.