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
Branch and bound
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
Branch and bound

Similar to Backtrack search-algorithm (20)

PPTX
proficiency presenattion on topic of backtracking algo
PPTX
Back tracking and branch and bound class 20
PPTX
Backtracking in Data Structure and Algorithm
PPT
Backtracking Algorithm.ppt
PDF
module5_backtrackingnbranchnbound_2022.pdf
PPTX
Design Algorithms - - Backtracking.pptx
PPTX
Maze Path Finding
PPTX
General methodin Data Structure for UG.pptx
PPTX
PDF
unit 4 of Unit 4 of design and analysis of algorithms
PPTX
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
PPTX
Backtracking
PPTX
it is a ppt discussing important topic of daa such as branch and bound.pptx
PPTX
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
PPTX
backtracking 8 Queen.pptx
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
PPT
Optimization problems
PPTX
N queens using backtracking
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
proficiency presenattion on topic of backtracking algo
Back tracking and branch and bound class 20
Backtracking in Data Structure and Algorithm
Backtracking Algorithm.ppt
module5_backtrackingnbranchnbound_2022.pdf
Design Algorithms - - Backtracking.pptx
Maze Path Finding
General methodin Data Structure for UG.pptx
unit 4 of Unit 4 of design and analysis of algorithms
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking
it is a ppt discussing important topic of daa such as branch and bound.pptx
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
backtracking 8 Queen.pptx
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Optimization problems
N queens using backtracking
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)

PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Mechanical Engineering MATERIALS Selection
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
composite construction of structures.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
Digital Logic Computer Design lecture notes
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
web development for engineering and engineering
PPTX
Welding lecture in detail for understanding
PDF
Well-logging-methods_new................
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Mechanical Engineering MATERIALS Selection
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
composite construction of structures.pdf
CH1 Production IntroductoryConcepts.pptx
Internet of Things (IOT) - A guide to understanding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
additive manufacturing of ss316l using mig welding
Digital Logic Computer Design lecture notes
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
OOP with Java - Java Introduction (Basics)
web development for engineering and engineering
Welding lecture in detail for understanding
Well-logging-methods_new................

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.