Professional Documents
Culture Documents
GENERAL METHOD
• Problems searching for a set of solutions or which require
an optimal solution can be solved using the backtracking
method .
Si = {1,2,3,4,5,6,7,8} 1 i n or 1 xi 8,
6
• The solution space consists of 88 8- tuples.
Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
8 queens problem (Contd..)
(i) no two xis can be the same that is, all queens must
be on different columns.
Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
8 queens problem (Contd..)
1 2 3 4 5 6 7 8
1 Q
2 Q
3 Q
4 Q
5 Q
6 Q
7 Q
8 Q
8
State space tree representation
Solution Space :
• Tuples that satisfy the explicit constraints define a solution space.
• All paths from the root to other nodes define the state- space of the
problem.
1 1 1 1
. . 2 2 2
3
. . . .
1 1
2
3
. . 4
14
State space tree: 4 Queens problem
1
x1 = 1 x1=2
2 18
x2=2 3 4 x2=1 x2=3 x2 = 4
B 3 8 13 19 24 29
x3=3 x3=4 2 3 B B
4 6 14 16 x3 = 1
x4=4 3 B 30
5 7 15 x4 = 3
B 31
15
State space tree: 4 Queens problem contd..
16
State space tree: 4 Queens problem contd..
17
State space tree: 4 Queens problem contd..
• Node 8 is generated, and the path is (1,3).
• Node 8 gets killed as all its children
represent board configurations that cannot
lead to answer. We backtrack to node 2 and
generate another child node 13.
• But the path (1,4) cannot lead to answer
nodes.
• So , we backtrack to 1 and generate the
path (2) with node 18. We observe that the
path to answer node is (2 4 1 3 )
• Other solution is (3, 1, 4, 2)
18
GENERAL BACKTRACKING METHOD
1 2 3 4 5 6 7 8
1 Q
2 Q
3 Q
4 Q
5 Q
6 Q
7 Q
8 Q
8
8 queens problem (Contd..)
i-j=k-l or i+j=k+l
Example
Given positive numbers wi, 1<=i<=n, and m, if n=4,
(w1,w2,w3,w4)=(11,13,24,7), and m=31, then the desired
subsets are (11,13,7) and (24,7). Rather than representing
solution vector by the wi, which sum is m, we could represent
the solution vector by giving the indices of these wi. Now the
two solutions are described by the vectors(1,2,4) and (3,4).
SUM OF SUBSETS
In general, all solutions are k-tuples (x1,x2,…..,xk), 1≤k ≤ n,
and different solutions may have different sized tuples.
At each node, the solution space is defined by all paths from
the root node to any node in the tree, since any such path
corresponds to subset satisfying the explicit constrains.
All paths from root to a leaf node define the solution space. The
left subtree of the root defines all subsets containing w1, the
right subtree of the root defines all subsets not containing w1,
and so on.
2 3 4 5
2 3 4 5
8 9 6 7
2 3 4 5
6 7 8 9
We compute lower bound and upper bound at each node. This
computation leads to selection of answer node.
Using FIFO and LIFO branch and bound method the selection of
E-node is very complicates and somewhat blind.
The Least Cost (LC) search is a kind of search in which least cost
is involved for reaching to answer node. At each E-node the
probability of being an answer node is checked.
LEAST COST SEARCH
BFS and D-search are special cases of LC search.
Each time the next E-node is selected on the basis of the ranking
function(smallest c^(x)). Let g^(x) be an estimate of the additional
effort needed to reach an answer node x. Let h(x) to be the cost of
reaching x from the root and f(x) to be any non-decreasing function
such that
C^(x)=f(h(x))+g^(x).
•As we know that the bounding functions are used to avoid the
generation of subtrees that do not contain the answer nodes. In
bounding lower bound and upper bounds are generated at each
node.
•At the start the upper is usually set to ∞. After generating the
children current E-node, upper can be updated by minimum cost
answer node. Each time a new answer node can be obtained.