SlideShare a Scribd company logo
2
Most read
4
Most read
7
Most read
Brute Force Approach
Backtracking
Backtracking
Backtracking is nothing but the
modified process of the Brute
Force approach. which will try
for every possible solutions,
then from which select the
optimum solution or select
best possible solution. It does
so by assuming that the
solutions are represented by
vectors ( vi
……………in) of values and by
traversing through the domains
of the vectors until the
solutions is found.
Backtracking- Introduction
 Suppose we have to make a series of decisions, among
various choices, where we 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 our problem.
 Backtracking is a methodical way of trying out various
sequences of decisions, until you find one that “works”.
Backtracking and Recursion
 Backtracking is easily implemented with recursion
because:
 The run-time stack takes care of keeping track of
the choices that got us to a given point.
 Upon failure we can get to the previous choice
simply by returning a failure code from the recursive
call.
Backtracking :General Method
 Backtracking is used to solve problem in which a
sequence of objects is chosen from a specified set so
that the sequence satisfies some criterion.
 The desired solution is expressed as an n-tuple
(x1……… xn) where each xi Є S, S being a finite set.
 The solution is based on finding one or more vectors
that maximize, minimize, or satisfy a criterion function
P((x1……… xn) .
 Form a solution and check at every step if this has
any chance of success. If the solution at any point
seems not promising, ignore it.
 All solutions requires a set of constraints divided into
two categories: Explicit and implicit constraints.
Explicit & implicit Constraints
 Explicit constraints are rules that restrict each
xi to take on values only from a given set. Explicit
constraints depend on the particular instance I of
problem being solved.
 Implicit constraints are rules that determine
which of the tuples in the solution space of I
satisfy the criterion function. Thus, implicit
constraints describe the way in which the xi’s
must relate to each other.
 The implicit constraints narrow the solution space
down to an answer space.
Explicit & implicit Constraints
 Explicit Constraints are rules which restrict the
values of xi . Example xi>=0 or xi =0 or 1 or
Li<=xi<=Ui.
 All tuples that satisfy the explicit constraints
define a possible solution space for I.
 Implicit Constraints describe the way in which the
xi must relate to each other.
 Implicit Constraints allow to find those tuples in
the solution space that satisfy the criterion
function.
Backtracking :General Method
 Backtracking is a modified depth first search of a tree.
 Backtracking algorithms determine problem solutions by
systematically searching the solution space for the given
problem instance. This search is facilitated by using a tree
organization for
the solution space.
 Backtracking is the procedure whereby, after determining that a
node can lead to nothing but dead end, we go back (backtrack)
to the nodes parent and proceed with the search on the next
child.
 A backtracking algorithm need not actually create a tree. Rather,
it only needs to keep track of the values in the current branch
being investigated. This is the way we implement backtracking
algorithm. We say that the state space tree exists implicitly in
the algorithm because it is not actually constructed.
State Space Tree
 Its root represents an initial state before the search for a
solution begins.
 State space is the set of paths from root node to other
nodes.
 State space tree is the tree organization of the solution
space.
 A state-space tree for a backtracking algorithm is
constructed in the manner of depth-first search.
 A node in a state-space tree is said to be promising if it
corresponds to a partially constructed solution that may still
lead to a complete solution; otherwise,
 it is called nonpromising. Leaves represent either
nonpromising dead ends or complete solutions found by the
algorithm.
Backtracking
how we find out all the permutations. If you are given three numbers [1,2,3]
Backtracking
Backtracking
 Problem: Find out all 3-bit binary numbers for
which the sum of the 1's is greater than or equal
to 2.
 The only way to solve this problem is to check all
the possibilities: (000, 001, 010, ....,111)
 The 8 possibilities are called the search space of
the problem. They can be organized into a tree
which is called State Space Tree.
Backtracking
Terminology
 Problem state is each node in the depth first search
tree.
 Solution states are the problem states “S” for which
the path from the root node to “S” defines a tuple in
the solution space.
 Answer states are those solution states for which the
path from root node to S defines a tuple that is a
member of the set of solutions.
 Live node is a node that has been generated but
whose children have not yet been generated.
 E-node is a live node whose children are currently
being explored. In other words, an E-node is a node
currently being expanded.
 Dead node is a generated node that is not to be
expanded or explored any further. All children of a
dead node have already been expanded.
Sum of subsets problem
 Problem definition: Find a subset of a given set A
= {a1, . . . , an} of n positive integers whose sum
is equal to a given positive integer d.
 For example, for A = {1, 2, 5, 6, 8} and d = 9,
 there are two solutions: {1, 2, 6} and {1, 8}. Of
course, some instances of this problem may have
no solutions. It is convenient to sort the set’s
elements in increasing order. So, we will assume
that a1< a2< . . . < an.
Sum of subsets problem
Problems

More Related Content

What's hot (20)

PPTX
Critical section problem in operating system.
MOHIT DADU
 
PPTX
Hierarchical clustering.pptx
NTUConcepts1
 
PPT
Minimum spanning tree
Hinal Lunagariya
 
PPTX
Gradient descent method
Prof. Neeta Awasthy
 
PPTX
Breadth First Search & Depth First Search
Kevin Jadiya
 
PPT
Dinive conquer algorithm
Mohd Arif
 
PPT
Amortized Analysis of Algorithms
sathish sak
 
PPT
Greedy Algorithm
Waqar Akram
 
PPTX
Prim's algorithm
Pankaj Thakur
 
PPTX
Solving recurrences
Megha V
 
PPTX
daa-unit-3-greedy method
hodcsencet
 
PPTX
State space search
chauhankapil
 
DOCX
BANKER'S ALGORITHM
Muhammad Baqar Kazmi
 
PDF
Divide and Conquer
Mohammed Hussein
 
PPT
Finite automata
Bipul Roy Bpl
 
PPTX
Propositional logic
Rushdi Shams
 
PPTX
Mathematical Analysis of Non-Recursive Algorithm.
mohanrathod18
 
PDF
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
PPTX
Presentation on Elementary data structures
Kuber Chandra
 
PDF
Elementary data structure
Biswajit Mandal
 
Critical section problem in operating system.
MOHIT DADU
 
Hierarchical clustering.pptx
NTUConcepts1
 
Minimum spanning tree
Hinal Lunagariya
 
Gradient descent method
Prof. Neeta Awasthy
 
Breadth First Search & Depth First Search
Kevin Jadiya
 
Dinive conquer algorithm
Mohd Arif
 
Amortized Analysis of Algorithms
sathish sak
 
Greedy Algorithm
Waqar Akram
 
Prim's algorithm
Pankaj Thakur
 
Solving recurrences
Megha V
 
daa-unit-3-greedy method
hodcsencet
 
State space search
chauhankapil
 
BANKER'S ALGORITHM
Muhammad Baqar Kazmi
 
Divide and Conquer
Mohammed Hussein
 
Finite automata
Bipul Roy Bpl
 
Propositional logic
Rushdi Shams
 
Mathematical Analysis of Non-Recursive Algorithm.
mohanrathod18
 
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
Presentation on Elementary data structures
Kuber Chandra
 
Elementary data structure
Biswajit Mandal
 

Similar to Backtracking in Data Structure and Algorithm (20)

PPTX
General methodin Data Structure for UG.pptx
LakshmiSamivel
 
PPTX
Backtracking (11111111111111111111).pptx
5dftmtp4ws
 
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
dakccse
 
PPT
Optimization problems
Ruchika Sinha
 
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
AmitBhola17
 
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
ZeelGoyani
 
PDF
module5_backtrackingnbranchnbound_2022.pdf
Shiwani Gupta
 
PPT
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
BinayakMukherjee4
 
PPT
Backtracking
Vikas Sharma
 
PPTX
Algo
Raghu nath
 
PPTX
Backtrack search-algorithm
Ruchika Sinha
 
PPTX
Design Algorithms - - Backtracking.pptx
Kishor767966
 
PPTX
Backtracking
Sally Salem
 
PPTX
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
B.T.L.I.T
 
PPTX
Maze Path Finding
MdShanewazAkib1
 
PPTX
it is a ppt discussing important topic of daa such as branch and bound.pptx
rajbaibhav004
 
PPTX
Backtracking
Raghu nath
 
PPTX
Backtrack-search-algorithm (2).pptx
AnLPhc1
 
PPTX
backtracking 8 Queen.pptx
JoshipavanEdduluru1
 
PPT
5.5 back track
Krish_ver2
 
General methodin Data Structure for UG.pptx
LakshmiSamivel
 
Backtracking (11111111111111111111).pptx
5dftmtp4ws
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
dakccse
 
Optimization problems
Ruchika Sinha
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
AmitBhola17
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
ZeelGoyani
 
module5_backtrackingnbranchnbound_2022.pdf
Shiwani Gupta
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
BinayakMukherjee4
 
Backtracking
Vikas Sharma
 
Backtrack search-algorithm
Ruchika Sinha
 
Design Algorithms - - Backtracking.pptx
Kishor767966
 
Backtracking
Sally Salem
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
B.T.L.I.T
 
Maze Path Finding
MdShanewazAkib1
 
it is a ppt discussing important topic of daa such as branch and bound.pptx
rajbaibhav004
 
Backtracking
Raghu nath
 
Backtrack-search-algorithm (2).pptx
AnLPhc1
 
backtracking 8 Queen.pptx
JoshipavanEdduluru1
 
5.5 back track
Krish_ver2
 
Ad

Recently uploaded (20)

PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Controller Request and Response in Odoo18
Celine George
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Ad

Backtracking in Data Structure and Algorithm

  • 2. Backtracking Backtracking is nothing but the modified process of the Brute Force approach. which will try for every possible solutions, then from which select the optimum solution or select best possible solution. It does so by assuming that the solutions are represented by vectors ( vi ……………in) of values and by traversing through the domains of the vectors until the solutions is found.
  • 3. Backtracking- Introduction  Suppose we have to make a series of decisions, among various choices, where we 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 our problem.  Backtracking is a methodical way of trying out various sequences of decisions, until you find one that “works”.
  • 4. Backtracking and Recursion  Backtracking is easily implemented with recursion because:  The run-time stack takes care of keeping track of the choices that got us to a given point.  Upon failure we can get to the previous choice simply by returning a failure code from the recursive call.
  • 5. Backtracking :General Method  Backtracking is used to solve problem in which a sequence of objects is chosen from a specified set so that the sequence satisfies some criterion.  The desired solution is expressed as an n-tuple (x1……… xn) where each xi Є S, S being a finite set.  The solution is based on finding one or more vectors that maximize, minimize, or satisfy a criterion function P((x1……… xn) .  Form a solution and check at every step if this has any chance of success. If the solution at any point seems not promising, ignore it.  All solutions requires a set of constraints divided into two categories: Explicit and implicit constraints.
  • 6. Explicit & implicit Constraints  Explicit constraints are rules that restrict each xi to take on values only from a given set. Explicit constraints depend on the particular instance I of problem being solved.  Implicit constraints are rules that determine which of the tuples in the solution space of I satisfy the criterion function. Thus, implicit constraints describe the way in which the xi’s must relate to each other.  The implicit constraints narrow the solution space down to an answer space.
  • 7. Explicit & implicit Constraints  Explicit Constraints are rules which restrict the values of xi . Example xi>=0 or xi =0 or 1 or Li<=xi<=Ui.  All tuples that satisfy the explicit constraints define a possible solution space for I.  Implicit Constraints describe the way in which the xi must relate to each other.  Implicit Constraints allow to find those tuples in the solution space that satisfy the criterion function.
  • 8. Backtracking :General Method  Backtracking is a modified depth first search of a tree.  Backtracking algorithms determine problem solutions by systematically searching the solution space for the given problem instance. This search is facilitated by using a tree organization for the solution space.  Backtracking is the procedure whereby, after determining that a node can lead to nothing but dead end, we go back (backtrack) to the nodes parent and proceed with the search on the next child.  A backtracking algorithm need not actually create a tree. Rather, it only needs to keep track of the values in the current branch being investigated. This is the way we implement backtracking algorithm. We say that the state space tree exists implicitly in the algorithm because it is not actually constructed.
  • 9. State Space Tree  Its root represents an initial state before the search for a solution begins.  State space is the set of paths from root node to other nodes.  State space tree is the tree organization of the solution space.  A state-space tree for a backtracking algorithm is constructed in the manner of depth-first search.  A node in a state-space tree is said to be promising if it corresponds to a partially constructed solution that may still lead to a complete solution; otherwise,  it is called nonpromising. Leaves represent either nonpromising dead ends or complete solutions found by the algorithm.
  • 10. Backtracking how we find out all the permutations. If you are given three numbers [1,2,3]
  • 12. Backtracking  Problem: Find out all 3-bit binary numbers for which the sum of the 1's is greater than or equal to 2.  The only way to solve this problem is to check all the possibilities: (000, 001, 010, ....,111)  The 8 possibilities are called the search space of the problem. They can be organized into a tree which is called State Space Tree.
  • 14. Terminology  Problem state is each node in the depth first search tree.  Solution states are the problem states “S” for which the path from the root node to “S” defines a tuple in the solution space.  Answer states are those solution states for which the path from root node to S defines a tuple that is a member of the set of solutions.  Live node is a node that has been generated but whose children have not yet been generated.  E-node is a live node whose children are currently being explored. In other words, an E-node is a node currently being expanded.  Dead node is a generated node that is not to be expanded or explored any further. All children of a dead node have already been expanded.
  • 15. Sum of subsets problem  Problem definition: Find a subset of a given set A = {a1, . . . , an} of n positive integers whose sum is equal to a given positive integer d.  For example, for A = {1, 2, 5, 6, 8} and d = 9,  there are two solutions: {1, 2, 6} and {1, 8}. Of course, some instances of this problem may have no solutions. It is convenient to sort the set’s elements in increasing order. So, we will assume that a1< a2< . . . < an.
  • 16. Sum of subsets problem