尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Module 5
Backtracking & Branch and
Bound
The backtracking method
• For problems where no. of choices grow exponentially with problem size
• A given problem has a set of constraints and possibly an objective function
• The solution optimizes an objective function, and/or is feasible.
• We can represent the solution space for the problem using a state space tree
– The root of the tree represents 0 choices,
– Nodes at depth 1 represent first choice
– Nodes at depth 2 represent the second choice, etc.
– In this tree a path from root to a leaf represents a candidate solution
• Definition: We call a node nonpromising if it cannot lead to a feasible (or
optimal) solution, otherwise it is promising
• Main idea: Backtracking consists of doing a DFS of the state space tree,
checking whether each node is promising and if the node is nonpromising
backtracking to the node’s parent
Backtracking
• For some problems, the only way to solve is to check all
possibilities.
• Backtracking is a systematic way to go through all the possible
configurations of a search space.
• Many problems solved by backtracking satisfy a set of
constraints which may divided into two categories: explicit and
implicit.
Explicit constraints are rules that restrict each to take on values only
from a given set
Implicit constraints are rules which relate to each other.
i
x
i
x
Backtracking
• Find whether there is any feasible solution? Decision Problem
• What is best solution? Optimization Problem
• List all feasible solutions? Enumeration Problem
• Problem State is each node in the tree
• State Space is all possible paths from root to other nodes
• Solution State is all possible paths from root to solution
• Answer State satisfies implicit constraints
• A live node is a node which has been generated but whose all children
have not been generated.
• An E-node (i.e., expanding node) is a live node whose children are
currently being generated.
• A dead node is a generated node which is not to be expanded further or
all of whose children have been generated.
• Two ways to generate problem states:
• Breadth First Generation (queue of live nodes)
• Depth First Generation (stack of live nodes)
Generating Problem States
• Depth First Generation (stack of live nodes)
• When a new child C of the current E-node R is generated, this child
becomes the new E-node.
• Then R will become the new E-node again when the subtree C has
been fully explored.
• Corresponds to a depth first search of the problem states.
Generating Problem States
• Breadth First Generation (queue of live nodes)
• The E-node remains the E-node until it is dead.
• Bounding functions are used in both to kill live nodes without generating all
of their children.
• At the end of the process, an answer node (or all answer nodes) are generated.
• The depth search generation method with bounding function is called
backtracking.
• The breadth first generation method is used in the branch-and-bound
method.
Generating Problem States
Improving Backtracking: Search Pruning
• 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 solution as early
as possible by finding contradictions so that we can backtrack
immediately without the need to build a hopeless solution vector.
Greedy vs Backtracking
• Method of obtaining
optimum solution, without
revising previously
generated solutions
• State space tree not created
• Less efficient
• Eg. Job sequencing with
deadlines, Optimal storage
on tapes
• Method of obtaining
optimum solution, may
require revision of previously
generated solutions
• State space tree created
• Efficient to obtain optimum
solution
• Eg. 8 Queen problem, Sum of
subset problem
Applications of Backtracking
• 8 Queen / n Queen Problem
• Sum of Subset problem
• Graph Coloring
• 0/1 Knapsack
N Queens problem
Eight Queen Problem
• Attempts to place 8 queens on a chessboard in such a
way that no queen can attack any other.
• A queen can attack another queen if it exists in the same
row, column or diagonal as the queen.
• 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.
• The solution is a vector of length 8 (x1, x2, x3, ... x8)
xi corresponds to the column where we should place the ith queen.
• The solution is to build a partial solution element by element until it is complete.
• We should backtrack in case we reach to a partial solution of length k, that we couldn't
expand any more.
Eight Queen Problem: Algorithm
putQueen(row)
{ for every position col on the same row
if position col is available
place the next queen in position col
if (row<8)
putQueen(row+1);
else success;
}
• Define an 8 by 8 array of 1s and 0s to represent the chessboard
• Note that the search space is very huge:
16,772, 216 (88) possibilities.
• Is there a way to reduce search space?
Yes Search Pruning.
• Since each queen (1-8) must be on a different row, we can assume queen i is
on row i.
• All solutions to the 8-queens problem can be represented as an 8-tuple
where queen i is on column j.
• The explicit constraints are
• The implicit constraints are that no two ’s can be the same (as queens must
be on different columns) and no two queens can be on the same diagonal.
• This implies that all solutions are permutations of the 8-tuple (1,2,…,8),
and reduces the solution space from tuples to 8! tuples.
1
0
,
0 or
x
x i
i 

)
,...,
,
( 8
2
1 x
x
x
.
8
1
},
8
,...,
2
,
1
{ 

 i
Si
8
8
i
x
Eight Queen Problem
• Generalizing earlier discussion, solution space contains all n! permutations of (1,2,…,n).
• The tree below shows possible organization for n=4.
• Tree is called a permutation tree (nodes are numbered as in depth first search).
• Edges labeled by possible values of
• The solution space is all paths from the root node to a leaf node.
• There are 4!=24 leaf nodes in tree.
44
42
39
37
33
31
28
26
23
21
17
15
12
10
7
5
1

1
x

2
x
2 3
1 4
60
58
55
53
49
47 63 65
43
41
38
36
32
30
27
25
22
20
16
14
11
9
6
4 59
57
54
52
48
46 62 64
40
35
29
24
19
13
8
3 56
51
45 61
34
18
2 50
2 3 4
2
3
1
4
1 1
2
3
4
2
3
4 2 3
4
2
3
4
2
3
4 3
4
3 4
1 2 3
4
1 2
3
4
1 2
3
4
1 2
4
1
2 3
2
1
2
3
2
1
3
1 2
1 2
1
1
1
i
x
Four Queen Problem
33
15
1

1
x

2
x
2
1
32
16
14
11
9
29
24
19
13
8
3
18
2
2 3 4
2
1
2
3
4 3
3 4
3
1

3
x

4
x
Backtracking on 4-queens problem
B
B B
B
B
B B
1
2
3
4
Backtracking Algorithm for n-Queens
problem
• Let represent where the ith queen is placed (in row i and
column on an n by n chessboard.
• Observe that two queens on the same diagonal that runs from “upper
left” to “lower right” have the same “row-column” value.
• Also two queens on the same diagonal from “upper right” to “lower
left” have the same “row+column” value
)
,...,
,
( 2
1 n
x
x
x
i
x
• Then two queens at (i,j) and (k,l) are on the same diagonal
• iff i-j=k-l or i+j=k+l
• iff i-k=j-l or j-l = k-i
• iff |j-l|=|i-k| .
• Algorithm PLACE(k,i) returns true if the kth queen can be placed in column i and
runs in O(k) time (see next slide)
• Using PLACE, the recursive version of the general backtracking method can be
used to give a precise solution to the n-queens problem
• Array x[ ] is global in the Algorithm invoked by NQUEENS(1, n).
Backtracking Algorithm for n-Queens
problem
bool Place(int k, int i)
// Returns true if a queen can be placed in kth row and ith column. Otherwise it returns false.
// x[] is a global array whose first (k-1) values have been set.
// abs(r) returns the absolute value of r.
{
for (int j = 1; j < k; j++)
if ((x[j] == i) // Two in the same column
|| (abs(x[j]-i) == abs(j-k))) // or in the same diagonal
return(false);
return(true);
}
void NQueens(int k, int n)
// Using backtracking, this procedure prints all possible placements of n queens on an n x n
// chessboard so that they are nonattacking
{
for (int i=1; i<=n; i++) {
if (Place(k, i)) {
x[k] = i; //if no conflict place queen
if (k==n) { for (int j=1;j<=n;j++) //dead end
cout << x[j] << ' '; cout << endl; //print board configuration
}
else NQueens(k+1, n); //try next queen next position
}
}
}
Backtracking Algorithm for n-Queens
problem
Complexity: n!
jth queen at x[j] and kth queen at i
TASK
• Solve problem on slide 16 as per algorithm on slide 19
Sum of Subset problem
Sum of Subset Problem
• Given positive numbers and m, find all subsets of ,
whose sum is m.
• If n=4, ={11, 13, 24, 7} and m=31, the desired solution sets
are (11, 13, 7) and (24, 7).
• If the solution vectors are given using the indices of the xi values used, then
the solution vectors are (1,2,4) and (3,4).
• In general, all solutions are k-tuples with and different solutions
may have different values of k.
• The explicit constraints on the solution space are that each
• The implicit constraints are that (so each item will occur
only once) and that the sum of the corresponding ’s be m.
i
w
)
,...,
,
( 2
1 k
x
x
x
n
k 

1
}.
,...,
2
,
1
{ n
xi 
,
1
,
1 n
i
x
x i
i 

 
}
,
,
,
{ 4
3
2
1 w
w
w
w
,
1
, n
i
wi 

1 1
(1)
k n
i i i
i i k
wk w m
  
 
  m
w
k
w k
k
i
i
i 
 

 1
1
)
2
(
hold
)
2
(
and
)
1
(
iff
)
,...,
,
( 2
1 true
x
x
x
B k
k 
The boundary function used uses both of the preceding conditions:
Bounding function
• The next figure gives the tree that corresponds to this variable tuple formation.
• An edge from a level i node to a level i+1 node represents a value for
• The solution space is all paths from the root node to any node in the tree.
• Possible paths include empty path, (1), (1,2), (1,2,3), (1,2,3,4), (1,2,4), (1,3,4), …
• The leftmost subtree gives all subsets containing , the next subtree gives all
subsets containing but not , etc.
.
i
x
1
w
2
w 1
w
16
1

1
x

2
x
2 3
1
4
15
14
13
12
11
10
9
8
7
6
4
3
2 5
2 3 4
4
3
3
4
4
4
4
4

3
x

4
x
Nodes are numbered as in breadth first search
First
Formulation
• Another formulation of this problem represents each solution by an n-tuple
with
• Here if is not chosen and if is chosen
• Given the earlier instance of (11,13,24,7) and m=31, the solutions (11,13,7) and
(24,7) are represented by (1,1,0,1) and (0,0,1,1).
• Here, all solutions have a fixed tuple size. The tree on next slide corresponds to this
formulation (nodes are numbered as in D-search).
• Edge from a level i node to a level i+1 node is labeled with the value of
• All paths from the root to a leaf give solution space.
• The left subtree gives all subsets containing and the right subtree gives all subsets
not containing .
)
,...,
,
( 2
1 n
x
x
x
.
1
},
1
,
0
{ n
i
xi 


0

i
x i
w 1

i
x
i
w
)
1
0
( or
xi
1
w
1
w
Sum of Subset Problem : Second Formulation
9
8
11
10
15
14
17
16
23
22
25
24
29
28
31
30
7
6
13
12
21
20
27
26
5
4
19
18
3
2
1

1
x

2
x

3
x

4
x
0
0
0
0
0
0
0 0
0
0
0
0
0
0
0
1
1
1
1
1
1
1 1
1 1 1
1 1 1 1
Sum of subset Problem
i1
i2
i3
yes no
0
0
0
0
2
2
2
6
6
12 8
4
4
10 6
yes
yes
no
no
no
no
no
no
The sum of the included integers is stored at the node.
yes
yes yes
yes
State SpaceTree for n= 3 items
w1 = 2, w2 = 4, w3 = 6 and S = 6
Solutions:
{2,4} and {6}
A Depth First Search Solution
Pruned State Space Tree
0
0
0
3
3
3
7
7
12 8
4
4
9
5
3
4 4
0
0
0
5 5
0 0 0
0
6
13 7 - backtrack
1
2
3
4 5
6 7
8
10
9
11
12
15
14
13
Nodes numbered in “call” order
w1 = 3, w2 = 4, w3 = 5, w4 = 6;
S = 13
sumOfSubsets ( s,k,r ) //sum, index, remaining sum
//generate left child until s+w[k]≤m
if (s+w[k]=m)
write(x(1:k)) //subset found
else if (s+w[k]+w[k+1]] ≤ m)
sumOfSubsets ( s+w[k],k+1,r-w[k] )
//generate right child
if (s+r-w[k]≥ m) and (s+w[k+1]] ≤ m)
x[k]=0
sumOfSubsets ( s,k+1,r-w[k] )
Initial call sumOfSubsets(0, 0, )


n
i
i
w
1
Sum of subset Algorithm
Complexity: 2n
Given n=6,M=30 and
W(1…6)=(5,10,12,13,15,18).
Ist solution is A -> 1 1 0 0 1 0
IInd solution is B -> 1 0 1 1 0 0
III rd solution is C -> 0 0 1 0 0 1
15,5,33
0,1,73
5,2,68
15,3,58
27,4,46 15,4,46
5,3,58
17,4,46 5,4,4
0,2,68
10,3,587
10,4,46
0,3,58
C
A
B 5,5,33 10,5,33
20,6,18
Xi=1
Xi=0 Xi=1
Xi=0
Xi=0
Xi=1 Xi=0
Xi=1
Xi=0
Xi=0
Xi=0
Xi=1
Xi=1
Xi=1
Xi=1
Xi=1
Xi=0
Xi=0
Xi=0
B 27,5,33
B
27,6,18
B
B
TASK
• M=13 w={3,4,5,6}
GRAPH / MAP coloring
• Graph Coloring is an assignment of colors
• Proper Coloring is if no two adjacent vertices have the same color
• Optimization Problem
• Chromatic no: smallest no. of colors used to color graph
• The Four Color Theorem states that any map on a plane can be
colored with no more than four colors, so that no two countries with a
common border are the same color
Origin of the problem
m-coloring decision problem: whether the graph can be colored or not
m-coloring optimization problem: min # of colors to color graph
chromatic problem
More than 1 possible solution
Algo
• Number out each vertex (V0, V1, V2, … Vn-1)
• Number out the available colors (C0, C1, C2, … Cm-1)
• Start assigning Ci to each Vi. While assigning the colors note that two
adjacent vertices should not be colored by the same color. And least
no. of colors should be used.
• While assigning the appropriate color, just backtrack and change the
color if two adjacent colors are getting the same.
Complexity: mn
Applications of Graph Theory
• Computer N/W security (Minimum Vertex Cover)
• Timetabling Problem (Vertex Coloring of Bipartite MultiGraph)
• GSM Mobile Phone Networks (Map Coloring)
• Represent Natural Language Parsing Diagrams
• Pattern recognition
• Molecules in chemistry and physics
Branch and Bound
• Branch and bound is used to find optimal solutions to optimization
problems.
• Is applied where Greedy and Dynamic fail.
• Is indeed much slower. Might require exponential time in worst case.
• BnB uses state space tree where in all children of node generated
before expanding any of its child.
Backtracking vs Branch and Bound
• Follows DFS approach
• Solves Decision Problems
• While finding solution, bad
choices can be made
• State space tree is searched until
solution is found
• Space required is O(ht. of tree)
• Applications: N Queens, Sum of
subset
• Follows DFS / BFS / Best First
Search approach
• Solves optimization problems
• Proceeds on a better solution, so
possibility of bad solution is
ruled out
• State space tree is searched
completely since solution can be
found elsewhere
• Space required is O(No. of
leaves)
• Applications: 15 puzzle, TSP
The Branch and Bound Steps
• In BnB, a state space tree is built and all children of E nodes (a live
node whose children are currently been generated) are generated
before any other node can become live node.
• For exploring new nodes either BFS (FIFO queue) or D-search (LIFO
stack) is used or replace the FIFO queue with a priority queue (least-
cost (or max priority)).
– The search for an answer node can often be speeded up using an
“intelligent” ranking function for the live nodes though it requires
additional computational effort.
• In this method, a space tree of possible solutions is generated. Then
partitioning (branching) is done at each node. LB and UB computed
at each node, leading to selection of answer node.
• Bounding functions (when LB>=UB) avoid generation of trees
(fathoming) not containing answer node.
• A branch-and-bound algorithm computes a number (bound) at a node
to determine whether the node is promising.
• The number is a bound on the value of the solution that could be
obtained by expanding beyond the node.
• If that bound is no better than the value of the best solution found so
far, the node is nonpromising. Otherwise, it is promising.
• Besides using the bound to determine whether a node is promising, we
can compare the bounds of promising nodes and visit the children of
the one with the best bound.
• This approach is called best-first search with branch-and-bound
pruning. The implementation of this approach is a modification of the
breadth-first search with branch-and-bound pruning.
The Branch and Bound variants
Branch and Bound Algorithm
Algorithm BnB()
E←new(node) //E is node pointer pointing root node
while(true)
if(E is a final leaf)
write(path from E to root) //E is optimal sol.
return
Expand(E)
if(H is empty) //H is heap for all live nodes
write(“there is no solution”) //E is optimal sol.
return
E← delete_top(H)
Algorithm Expand(E)
Generate all children of E
Compute approximate cost value of each child
Insert each child into heap H
Least Cost search
• In BnB, basic idea is selection of E-node, so that we reach to answer
node quickly.
• Using FIFO and LIFO BnB selection of E-node is complicated (since
expansion of all live nodes required before leading to an answer) and
blind.
• Best First Search and D-search are special cases of LC-search.
• In LC-search an intelligent ranking function (smallest c^(x)) is
formed. c^(x)=f(x)+ ĝ(x) (where f(x) is cost of reaching x from root,
ĝ(x) is an estimate of additional effort needed to reach an answer node
from x).
• LC-search terminates only when either an answer node is found or the
entire state space tree has been generated and searched.
• Note that termination is only guaranteed for finite space trees.
Applications of Branch and Bound
• 8 Puzzle Problem
• Travelling Salesman Problem
8 Puzzle problem using Branch and Bound
TASK
1 3 4 15 1 2 3 4
2 5 12 5 6 7 8
7 6 11 14 9 10 11 12
8 9 10 13 13 14 15
Initial Arrangement Goal Arrangement

More Related Content

What's hot

Backtracking
BacktrackingBacktracking
Backtracking
Pranay Meshram
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Swapnil Agrawal
 
Vertex cover Problem
Vertex cover ProblemVertex cover Problem
Vertex cover Problem
Gajanand Sharma
 
Activation functions
Activation functionsActivation functions
Activation functions
PRATEEK SAHU
 
Fractional knapsack problem
Fractional knapsack problemFractional knapsack problem
Fractional knapsack problem
Learning Courses Online
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
srilekhagourishetty
 
np complete
np completenp complete
np complete
Gayathri Gaayu
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 
Introduction to Recurrent Neural Network
Introduction to Recurrent Neural NetworkIntroduction to Recurrent Neural Network
Introduction to Recurrent Neural Network
Knoldus Inc.
 
Big o notation
Big o notationBig o notation
Big o notation
hamza mushtaq
 
Deep learning
Deep learningDeep learning
Deep learning
Kuppusamy P
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent method
Sanghyuk Chun
 
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Mohammed Hussein
 
Lecture 26 local beam search
Lecture 26 local beam searchLecture 26 local beam search
Lecture 26 local beam search
Hema Kashyap
 
Problem solving in Artificial Intelligence.pptx
Problem solving in Artificial Intelligence.pptxProblem solving in Artificial Intelligence.pptx
Problem solving in Artificial Intelligence.pptx
kitsenthilkumarcse
 
Optimization for Deep Learning
Optimization for Deep LearningOptimization for Deep Learning
Optimization for Deep Learning
Sebastian Ruder
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)
Archana432045
 

What's hot (20)

Backtracking
BacktrackingBacktracking
Backtracking
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Vertex cover Problem
Vertex cover ProblemVertex cover Problem
Vertex cover Problem
 
Activation functions
Activation functionsActivation functions
Activation functions
 
Fractional knapsack problem
Fractional knapsack problemFractional knapsack problem
Fractional knapsack problem
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
 
np complete
np completenp complete
np complete
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Introduction to Recurrent Neural Network
Introduction to Recurrent Neural NetworkIntroduction to Recurrent Neural Network
Introduction to Recurrent Neural Network
 
Big o notation
Big o notationBig o notation
Big o notation
 
Deep learning
Deep learningDeep learning
Deep learning
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent method
 
NP completeness
NP completenessNP completeness
NP completeness
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Lecture 26 local beam search
Lecture 26 local beam searchLecture 26 local beam search
Lecture 26 local beam search
 
Problem solving in Artificial Intelligence.pptx
Problem solving in Artificial Intelligence.pptxProblem solving in Artificial Intelligence.pptx
Problem solving in Artificial Intelligence.pptx
 
Optimization for Deep Learning
Optimization for Deep LearningOptimization for Deep Learning
Optimization for Deep Learning
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)
 

Similar to module5_backtrackingnbranchnbound_2022.pdf

backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
JoshipavanEdduluru1
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
Kumar
 
8-Queens Problem.pptx
8-Queens Problem.pptx8-Queens Problem.pptx
8-Queens Problem.pptx
rajinooka
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
Mohanlal Sukhadia University (MLSU)
 
Back tracking
Back trackingBack tracking
Branch and bound
Branch and boundBranch and bound
Branch and bound
Acad
 
Sudoku
SudokuSudoku
Sudoku
Yara Ali
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
sunidhi740916
 
Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptx
sunidhi740916
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
B.T.L.I.T
 
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjekAIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
pavan402055
 
DAA UNIT-4 (1).pdf
DAA UNIT-4 (1).pdfDAA UNIT-4 (1).pdf
DAA UNIT-4 (1).pdf
ssuser1eba0d
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptx
sangeeta194160
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
TayyabSattar5
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
varun arora
 
N Queens problem
N Queens problemN Queens problem
N Queens problem
Arkadeep Dey
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
Ruchika Sinha
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
Nv Thejaswini
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
Monika Choudhery
 

Similar to module5_backtrackingnbranchnbound_2022.pdf (20)

backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
8-Queens Problem.pptx
8-Queens Problem.pptx8-Queens Problem.pptx
8-Queens Problem.pptx
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
Back tracking
Back trackingBack tracking
Back tracking
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Sudoku
SudokuSudoku
Sudoku
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
 
Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptx
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
 
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjekAIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
 
DAA UNIT-4 (1).pdf
DAA UNIT-4 (1).pdfDAA UNIT-4 (1).pdf
DAA UNIT-4 (1).pdf
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptx
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
 
N Queens problem
N Queens problemN Queens problem
N Queens problem
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
 

More from Shiwani Gupta

ML MODULE 6.pdf
ML MODULE 6.pdfML MODULE 6.pdf
ML MODULE 6.pdf
Shiwani Gupta
 
ML MODULE 5.pdf
ML MODULE 5.pdfML MODULE 5.pdf
ML MODULE 5.pdf
Shiwani Gupta
 
ML MODULE 4.pdf
ML MODULE 4.pdfML MODULE 4.pdf
ML MODULE 4.pdf
Shiwani Gupta
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
Shiwani Gupta
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
Shiwani Gupta
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
Shiwani Gupta
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdf
Shiwani Gupta
 
ML MODULE 1_slideshare.pdf
ML MODULE 1_slideshare.pdfML MODULE 1_slideshare.pdf
ML MODULE 1_slideshare.pdf
Shiwani Gupta
 
ML MODULE 2.pdf
ML MODULE 2.pdfML MODULE 2.pdf
ML MODULE 2.pdf
Shiwani Gupta
 
ML Module 3.pdf
ML Module 3.pdfML Module 3.pdf
ML Module 3.pdf
Shiwani Gupta
 
Problem formulation
Problem formulationProblem formulation
Problem formulation
Shiwani Gupta
 
Simplex method
Simplex methodSimplex method
Simplex method
Shiwani Gupta
 
Functionsandpigeonholeprinciple
FunctionsandpigeonholeprincipleFunctionsandpigeonholeprinciple
Functionsandpigeonholeprinciple
Shiwani Gupta
 
Relations
RelationsRelations
Relations
Shiwani Gupta
 
Logic
LogicLogic
Set theory
Set theorySet theory
Set theory
Shiwani Gupta
 
Uncertain knowledge and reasoning
Uncertain knowledge and reasoningUncertain knowledge and reasoning
Uncertain knowledge and reasoning
Shiwani Gupta
 
Introduction to ai
Introduction to aiIntroduction to ai
Introduction to ai
Shiwani Gupta
 
Planning Agent
Planning AgentPlanning Agent
Planning Agent
Shiwani Gupta
 
Knowledge based agent
Knowledge based agentKnowledge based agent
Knowledge based agent
Shiwani Gupta
 

More from Shiwani Gupta (20)

ML MODULE 6.pdf
ML MODULE 6.pdfML MODULE 6.pdf
ML MODULE 6.pdf
 
ML MODULE 5.pdf
ML MODULE 5.pdfML MODULE 5.pdf
ML MODULE 5.pdf
 
ML MODULE 4.pdf
ML MODULE 4.pdfML MODULE 4.pdf
ML MODULE 4.pdf
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdf
 
ML MODULE 1_slideshare.pdf
ML MODULE 1_slideshare.pdfML MODULE 1_slideshare.pdf
ML MODULE 1_slideshare.pdf
 
ML MODULE 2.pdf
ML MODULE 2.pdfML MODULE 2.pdf
ML MODULE 2.pdf
 
ML Module 3.pdf
ML Module 3.pdfML Module 3.pdf
ML Module 3.pdf
 
Problem formulation
Problem formulationProblem formulation
Problem formulation
 
Simplex method
Simplex methodSimplex method
Simplex method
 
Functionsandpigeonholeprinciple
FunctionsandpigeonholeprincipleFunctionsandpigeonholeprinciple
Functionsandpigeonholeprinciple
 
Relations
RelationsRelations
Relations
 
Logic
LogicLogic
Logic
 
Set theory
Set theorySet theory
Set theory
 
Uncertain knowledge and reasoning
Uncertain knowledge and reasoningUncertain knowledge and reasoning
Uncertain knowledge and reasoning
 
Introduction to ai
Introduction to aiIntroduction to ai
Introduction to ai
 
Planning Agent
Planning AgentPlanning Agent
Planning Agent
 
Knowledge based agent
Knowledge based agentKnowledge based agent
Knowledge based agent
 

Recently uploaded

Microsoft Azure AD architecture and features
Microsoft Azure AD architecture and featuresMicrosoft Azure AD architecture and features
Microsoft Azure AD architecture and features
ssuser381403
 
Online train ticket booking system project.pdf
Online train ticket booking system project.pdfOnline train ticket booking system project.pdf
Online train ticket booking system project.pdf
Kamal Acharya
 
BBOC407 Module 1.pptx Biology for Engineers
BBOC407  Module 1.pptx Biology for EngineersBBOC407  Module 1.pptx Biology for Engineers
BBOC407 Module 1.pptx Biology for Engineers
sathishkumars808912
 
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
simrangupta87541
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Poonam Singh
 
SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )
Tsuyoshi Horigome
 
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
sexytaniya455
 
Lateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptxLateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptx
DebendraDevKhanal1
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Dr.Costas Sachpazis
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
Guangdong Ctube Industry Co., Ltd.
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
sonamrawat5631
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
kamka4105
 
My Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdfMy Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdf
Geoffrey Wardle. MSc. MSc. Snr.MAIAA
 
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
nonods
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptxMODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
NaveenNaveen726446
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
ShurooqTaib
 
Technological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdfTechnological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdf
tanujaharish2
 
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl LucknowCall Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
yogita singh$A17
 

Recently uploaded (20)

Microsoft Azure AD architecture and features
Microsoft Azure AD architecture and featuresMicrosoft Azure AD architecture and features
Microsoft Azure AD architecture and features
 
Online train ticket booking system project.pdf
Online train ticket booking system project.pdfOnline train ticket booking system project.pdf
Online train ticket booking system project.pdf
 
BBOC407 Module 1.pptx Biology for Engineers
BBOC407  Module 1.pptx Biology for EngineersBBOC407  Module 1.pptx Biology for Engineers
BBOC407 Module 1.pptx Biology for Engineers
 
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
 
SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )
 
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
 
Lateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptxLateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptx
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
 
My Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdfMy Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdf
 
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptxMODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
 
Technological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdfTechnological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdf
 
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl LucknowCall Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
 

module5_backtrackingnbranchnbound_2022.pdf

  • 1. Module 5 Backtracking & Branch and Bound
  • 2. The backtracking method • For problems where no. of choices grow exponentially with problem size • A given problem has a set of constraints and possibly an objective function • The solution optimizes an objective function, and/or is feasible. • We can represent the solution space for the problem using a state space tree – The root of the tree represents 0 choices, – Nodes at depth 1 represent first choice – Nodes at depth 2 represent the second choice, etc. – In this tree a path from root to a leaf represents a candidate solution • Definition: We call a node nonpromising if it cannot lead to a feasible (or optimal) solution, otherwise it is promising • Main idea: Backtracking consists of doing a DFS of the state space tree, checking whether each node is promising and if the node is nonpromising backtracking to the node’s parent
  • 3. Backtracking • For some problems, the only way to solve is to check all possibilities. • Backtracking is a systematic way to go through all the possible configurations of a search space. • Many problems solved by backtracking satisfy a set of constraints which may divided into two categories: explicit and implicit. Explicit constraints are rules that restrict each to take on values only from a given set Implicit constraints are rules which relate to each other. i x i x
  • 4. Backtracking • Find whether there is any feasible solution? Decision Problem • What is best solution? Optimization Problem • List all feasible solutions? Enumeration Problem
  • 5. • Problem State is each node in the tree • State Space is all possible paths from root to other nodes • Solution State is all possible paths from root to solution • Answer State satisfies implicit constraints • A live node is a node which has been generated but whose all children have not been generated. • An E-node (i.e., expanding node) is a live node whose children are currently being generated. • A dead node is a generated node which is not to be expanded further or all of whose children have been generated. • Two ways to generate problem states: • Breadth First Generation (queue of live nodes) • Depth First Generation (stack of live nodes) Generating Problem States
  • 6. • Depth First Generation (stack of live nodes) • When a new child C of the current E-node R is generated, this child becomes the new E-node. • Then R will become the new E-node again when the subtree C has been fully explored. • Corresponds to a depth first search of the problem states. Generating Problem States
  • 7. • Breadth First Generation (queue of live nodes) • The E-node remains the E-node until it is dead. • Bounding functions are used in both to kill live nodes without generating all of their children. • At the end of the process, an answer node (or all answer nodes) are generated. • The depth search generation method with bounding function is called backtracking. • The breadth first generation method is used in the branch-and-bound method. Generating Problem States
  • 8. Improving Backtracking: Search Pruning • 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 solution as early as possible by finding contradictions so that we can backtrack immediately without the need to build a hopeless solution vector.
  • 9. Greedy vs Backtracking • Method of obtaining optimum solution, without revising previously generated solutions • State space tree not created • Less efficient • Eg. Job sequencing with deadlines, Optimal storage on tapes • Method of obtaining optimum solution, may require revision of previously generated solutions • State space tree created • Efficient to obtain optimum solution • Eg. 8 Queen problem, Sum of subset problem
  • 10. Applications of Backtracking • 8 Queen / n Queen Problem • Sum of Subset problem • Graph Coloring • 0/1 Knapsack
  • 12. Eight Queen Problem • Attempts to place 8 queens on a chessboard in such a way that no queen can attack any other. • A queen can attack another queen if it exists in the same row, column or diagonal as the queen. • 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. • The solution is a vector of length 8 (x1, x2, x3, ... x8) xi corresponds to the column where we should place the ith queen. • The solution is to build a partial solution element by element until it is complete. • We should backtrack in case we reach to a partial solution of length k, that we couldn't expand any more.
  • 13. Eight Queen Problem: Algorithm putQueen(row) { for every position col on the same row if position col is available place the next queen in position col if (row<8) putQueen(row+1); else success; } • Define an 8 by 8 array of 1s and 0s to represent the chessboard • Note that the search space is very huge: 16,772, 216 (88) possibilities. • Is there a way to reduce search space? Yes Search Pruning.
  • 14. • Since each queen (1-8) must be on a different row, we can assume queen i is on row i. • All solutions to the 8-queens problem can be represented as an 8-tuple where queen i is on column j. • The explicit constraints are • The implicit constraints are that no two ’s can be the same (as queens must be on different columns) and no two queens can be on the same diagonal. • This implies that all solutions are permutations of the 8-tuple (1,2,…,8), and reduces the solution space from tuples to 8! tuples. 1 0 , 0 or x x i i   ) ,..., , ( 8 2 1 x x x . 8 1 }, 8 ,..., 2 , 1 {    i Si 8 8 i x Eight Queen Problem
  • 15. • Generalizing earlier discussion, solution space contains all n! permutations of (1,2,…,n). • The tree below shows possible organization for n=4. • Tree is called a permutation tree (nodes are numbered as in depth first search). • Edges labeled by possible values of • The solution space is all paths from the root node to a leaf node. • There are 4!=24 leaf nodes in tree. 44 42 39 37 33 31 28 26 23 21 17 15 12 10 7 5 1  1 x  2 x 2 3 1 4 60 58 55 53 49 47 63 65 43 41 38 36 32 30 27 25 22 20 16 14 11 9 6 4 59 57 54 52 48 46 62 64 40 35 29 24 19 13 8 3 56 51 45 61 34 18 2 50 2 3 4 2 3 1 4 1 1 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 3 4 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 4 1 2 3 2 1 2 3 2 1 3 1 2 1 2 1 1 1 i x Four Queen Problem
  • 16. 33 15 1  1 x  2 x 2 1 32 16 14 11 9 29 24 19 13 8 3 18 2 2 3 4 2 1 2 3 4 3 3 4 3 1  3 x  4 x Backtracking on 4-queens problem B B B B B B B 1 2 3 4
  • 17. Backtracking Algorithm for n-Queens problem • Let represent where the ith queen is placed (in row i and column on an n by n chessboard. • Observe that two queens on the same diagonal that runs from “upper left” to “lower right” have the same “row-column” value. • Also two queens on the same diagonal from “upper right” to “lower left” have the same “row+column” value ) ,..., , ( 2 1 n x x x i x
  • 18. • Then two queens at (i,j) and (k,l) are on the same diagonal • iff i-j=k-l or i+j=k+l • iff i-k=j-l or j-l = k-i • iff |j-l|=|i-k| . • Algorithm PLACE(k,i) returns true if the kth queen can be placed in column i and runs in O(k) time (see next slide) • Using PLACE, the recursive version of the general backtracking method can be used to give a precise solution to the n-queens problem • Array x[ ] is global in the Algorithm invoked by NQUEENS(1, n). Backtracking Algorithm for n-Queens problem
  • 19. bool Place(int k, int i) // Returns true if a queen can be placed in kth row and ith column. Otherwise it returns false. // x[] is a global array whose first (k-1) values have been set. // abs(r) returns the absolute value of r. { for (int j = 1; j < k; j++) if ((x[j] == i) // Two in the same column || (abs(x[j]-i) == abs(j-k))) // or in the same diagonal return(false); return(true); } void NQueens(int k, int n) // Using backtracking, this procedure prints all possible placements of n queens on an n x n // chessboard so that they are nonattacking { for (int i=1; i<=n; i++) { if (Place(k, i)) { x[k] = i; //if no conflict place queen if (k==n) { for (int j=1;j<=n;j++) //dead end cout << x[j] << ' '; cout << endl; //print board configuration } else NQueens(k+1, n); //try next queen next position } } } Backtracking Algorithm for n-Queens problem Complexity: n! jth queen at x[j] and kth queen at i
  • 20. TASK • Solve problem on slide 16 as per algorithm on slide 19
  • 21. Sum of Subset problem
  • 22. Sum of Subset Problem • Given positive numbers and m, find all subsets of , whose sum is m. • If n=4, ={11, 13, 24, 7} and m=31, the desired solution sets are (11, 13, 7) and (24, 7). • If the solution vectors are given using the indices of the xi values used, then the solution vectors are (1,2,4) and (3,4). • In general, all solutions are k-tuples with and different solutions may have different values of k. • The explicit constraints on the solution space are that each • The implicit constraints are that (so each item will occur only once) and that the sum of the corresponding ’s be m. i w ) ,..., , ( 2 1 k x x x n k   1 }. ,..., 2 , 1 { n xi  , 1 , 1 n i x x i i     } , , , { 4 3 2 1 w w w w , 1 , n i wi   1 1 (1) k n i i i i i k wk w m        m w k w k k i i i      1 1 ) 2 ( hold ) 2 ( and ) 1 ( iff ) ,..., , ( 2 1 true x x x B k k  The boundary function used uses both of the preceding conditions: Bounding function
  • 23. • The next figure gives the tree that corresponds to this variable tuple formation. • An edge from a level i node to a level i+1 node represents a value for • The solution space is all paths from the root node to any node in the tree. • Possible paths include empty path, (1), (1,2), (1,2,3), (1,2,3,4), (1,2,4), (1,3,4), … • The leftmost subtree gives all subsets containing , the next subtree gives all subsets containing but not , etc. . i x 1 w 2 w 1 w 16 1  1 x  2 x 2 3 1 4 15 14 13 12 11 10 9 8 7 6 4 3 2 5 2 3 4 4 3 3 4 4 4 4 4  3 x  4 x Nodes are numbered as in breadth first search First Formulation
  • 24. • Another formulation of this problem represents each solution by an n-tuple with • Here if is not chosen and if is chosen • Given the earlier instance of (11,13,24,7) and m=31, the solutions (11,13,7) and (24,7) are represented by (1,1,0,1) and (0,0,1,1). • Here, all solutions have a fixed tuple size. The tree on next slide corresponds to this formulation (nodes are numbered as in D-search). • Edge from a level i node to a level i+1 node is labeled with the value of • All paths from the root to a leaf give solution space. • The left subtree gives all subsets containing and the right subtree gives all subsets not containing . ) ,..., , ( 2 1 n x x x . 1 }, 1 , 0 { n i xi    0  i x i w 1  i x i w ) 1 0 ( or xi 1 w 1 w Sum of Subset Problem : Second Formulation
  • 26. Sum of subset Problem i1 i2 i3 yes no 0 0 0 0 2 2 2 6 6 12 8 4 4 10 6 yes yes no no no no no no The sum of the included integers is stored at the node. yes yes yes yes State SpaceTree for n= 3 items w1 = 2, w2 = 4, w3 = 6 and S = 6 Solutions: {2,4} and {6}
  • 27. A Depth First Search Solution Pruned State Space Tree 0 0 0 3 3 3 7 7 12 8 4 4 9 5 3 4 4 0 0 0 5 5 0 0 0 0 6 13 7 - backtrack 1 2 3 4 5 6 7 8 10 9 11 12 15 14 13 Nodes numbered in “call” order w1 = 3, w2 = 4, w3 = 5, w4 = 6; S = 13
  • 28. sumOfSubsets ( s,k,r ) //sum, index, remaining sum //generate left child until s+w[k]≤m if (s+w[k]=m) write(x(1:k)) //subset found else if (s+w[k]+w[k+1]] ≤ m) sumOfSubsets ( s+w[k],k+1,r-w[k] ) //generate right child if (s+r-w[k]≥ m) and (s+w[k+1]] ≤ m) x[k]=0 sumOfSubsets ( s,k+1,r-w[k] ) Initial call sumOfSubsets(0, 0, )   n i i w 1 Sum of subset Algorithm Complexity: 2n
  • 29. Given n=6,M=30 and W(1…6)=(5,10,12,13,15,18). Ist solution is A -> 1 1 0 0 1 0 IInd solution is B -> 1 0 1 1 0 0 III rd solution is C -> 0 0 1 0 0 1 15,5,33 0,1,73 5,2,68 15,3,58 27,4,46 15,4,46 5,3,58 17,4,46 5,4,4 0,2,68 10,3,587 10,4,46 0,3,58 C A B 5,5,33 10,5,33 20,6,18 Xi=1 Xi=0 Xi=1 Xi=0 Xi=0 Xi=1 Xi=0 Xi=1 Xi=0 Xi=0 Xi=0 Xi=1 Xi=1 Xi=1 Xi=1 Xi=1 Xi=0 Xi=0 Xi=0 B 27,5,33 B 27,6,18 B B
  • 31. GRAPH / MAP coloring • Graph Coloring is an assignment of colors • Proper Coloring is if no two adjacent vertices have the same color • Optimization Problem • Chromatic no: smallest no. of colors used to color graph • The Four Color Theorem states that any map on a plane can be colored with no more than four colors, so that no two countries with a common border are the same color
  • 32. Origin of the problem m-coloring decision problem: whether the graph can be colored or not m-coloring optimization problem: min # of colors to color graph chromatic problem More than 1 possible solution
  • 33. Algo • Number out each vertex (V0, V1, V2, … Vn-1) • Number out the available colors (C0, C1, C2, … Cm-1) • Start assigning Ci to each Vi. While assigning the colors note that two adjacent vertices should not be colored by the same color. And least no. of colors should be used. • While assigning the appropriate color, just backtrack and change the color if two adjacent colors are getting the same. Complexity: mn
  • 34.
  • 35. Applications of Graph Theory • Computer N/W security (Minimum Vertex Cover) • Timetabling Problem (Vertex Coloring of Bipartite MultiGraph) • GSM Mobile Phone Networks (Map Coloring) • Represent Natural Language Parsing Diagrams • Pattern recognition • Molecules in chemistry and physics
  • 36. Branch and Bound • Branch and bound is used to find optimal solutions to optimization problems. • Is applied where Greedy and Dynamic fail. • Is indeed much slower. Might require exponential time in worst case. • BnB uses state space tree where in all children of node generated before expanding any of its child.
  • 37. Backtracking vs Branch and Bound • Follows DFS approach • Solves Decision Problems • While finding solution, bad choices can be made • State space tree is searched until solution is found • Space required is O(ht. of tree) • Applications: N Queens, Sum of subset • Follows DFS / BFS / Best First Search approach • Solves optimization problems • Proceeds on a better solution, so possibility of bad solution is ruled out • State space tree is searched completely since solution can be found elsewhere • Space required is O(No. of leaves) • Applications: 15 puzzle, TSP
  • 38. The Branch and Bound Steps • In BnB, a state space tree is built and all children of E nodes (a live node whose children are currently been generated) are generated before any other node can become live node. • For exploring new nodes either BFS (FIFO queue) or D-search (LIFO stack) is used or replace the FIFO queue with a priority queue (least- cost (or max priority)). – The search for an answer node can often be speeded up using an “intelligent” ranking function for the live nodes though it requires additional computational effort. • In this method, a space tree of possible solutions is generated. Then partitioning (branching) is done at each node. LB and UB computed at each node, leading to selection of answer node. • Bounding functions (when LB>=UB) avoid generation of trees (fathoming) not containing answer node.
  • 39. • A branch-and-bound algorithm computes a number (bound) at a node to determine whether the node is promising. • The number is a bound on the value of the solution that could be obtained by expanding beyond the node. • If that bound is no better than the value of the best solution found so far, the node is nonpromising. Otherwise, it is promising. • Besides using the bound to determine whether a node is promising, we can compare the bounds of promising nodes and visit the children of the one with the best bound. • This approach is called best-first search with branch-and-bound pruning. The implementation of this approach is a modification of the breadth-first search with branch-and-bound pruning. The Branch and Bound variants
  • 40. Branch and Bound Algorithm Algorithm BnB() E←new(node) //E is node pointer pointing root node while(true) if(E is a final leaf) write(path from E to root) //E is optimal sol. return Expand(E) if(H is empty) //H is heap for all live nodes write(“there is no solution”) //E is optimal sol. return E← delete_top(H) Algorithm Expand(E) Generate all children of E Compute approximate cost value of each child Insert each child into heap H
  • 41. Least Cost search • In BnB, basic idea is selection of E-node, so that we reach to answer node quickly. • Using FIFO and LIFO BnB selection of E-node is complicated (since expansion of all live nodes required before leading to an answer) and blind. • Best First Search and D-search are special cases of LC-search. • In LC-search an intelligent ranking function (smallest c^(x)) is formed. c^(x)=f(x)+ ĝ(x) (where f(x) is cost of reaching x from root, ĝ(x) is an estimate of additional effort needed to reach an answer node from x). • LC-search terminates only when either an answer node is found or the entire state space tree has been generated and searched. • Note that termination is only guaranteed for finite space trees.
  • 42. Applications of Branch and Bound • 8 Puzzle Problem • Travelling Salesman Problem
  • 43. 8 Puzzle problem using Branch and Bound
  • 44. TASK 1 3 4 15 1 2 3 4 2 5 12 5 6 7 8 7 6 11 14 9 10 11 12 8 9 10 13 13 14 15 Initial Arrangement Goal Arrangement
  翻译: