cs3401-algorithm-unit4
cs3401-algorithm-unit4
UNIT IV
STATE SPACE SEARCH ALGORITHMS
Backtracking: n-Queens problem – Hamiltonian Circuit Problem – Subset Sum Problem – Graph
colouring problem- Branch and Bound: Solving 15-Puzzle problem – Assignment problem
Knapsack Problem – Travelling Salesman Problem.
PART - A
1. Differentiate backtracking and Exhaustive search. (AN)
S.No Backtracking Exhaustive search
1. Backtracking is to build up the Exhaustive search is simply a “brute
solution vector one component at a – force” approach to combinatorial
time and to use modified criterion problems. It suggests generating each
Function Pi(x1,..,xi) (sometimes and every element of the problem’s
called bounding function) to test domain, selecting those of them that
whether the vector being formed has satisfy the problem’s constraints, and
any chance of success. then finding a desired element.
2. Backtracking makes it possible to Exhaustive search is impractical for
solve many large instances of NP- large instances, however applicable
hard problems in an acceptable for small instances of problems.
amount of time.
2. What are the factors that influence the efficiency of the backtracking
algorithm?(APRIL/MAY 2008) (R)
The efficiency of the backtracking algorithm depends on the following four
factors. They are:
i. The time needed to generate the next xk
ii. The number of xk satisfying the explicit constraints.
iii. The time for the bounding functions Bk
iv. The number of xk satisfying the Bk.
1
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
Q
Q
Q
Q
2
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
where each coordinate xi is an element of some finite linearly ordered set Si. If such a
tuple (x1, …xi) is not a solution, the algorithm finds the next element in Si+1 that is
consistent with the values of (x1, …xi) and the problem’s constraints and adds it to the
tuple as its (I+1)st coordinate. If such an element does not exist, the algorithm
backtracks to consider the next value of xi, and so on. Give a template for a generic
backtracking algorithm.(APRIL/MAY 2012) (R)
ALGORITHM Backtrack(X [1..i])
//Gives a template of a generic backtracking algorithm
//Input X[1..i] specifies the first I promising components of a solution
//Output All the tuples representing the
problem’s solution if X[1..i] is a solution write
X[1..i]
else
for each element x Si+1 consistent with X[1..i] and the
constraints do X[i+1] = x
Backtrack(X[1..i+1])
9. State m color-ability decision problem.(NOV/DEC 2012) (R)
Let G be a graph and m be a given positive integer. We want to discover whether
thenodes of G can be colored in such a way that no two adjacent nodes have the same
color yet only m colors are used.
10. What are the two types of constraints used in Backtracking? (R)
Explicit constraints
Implicit constraints
11. Define implicit constraint.(APR/MAY 2010& 2012) (R)
The rules that restrict each element to be chosen from the given set.
13. What is a promising node in the state-space tree? (R) (Nov 17)
A node in a state-space tree is said to be promising if it corresponds to a partially
3
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
4
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
update the latter with the former if the new solution is better.
21. Give the formula used to find the upper bound for knapsack problem.
A simple way to find the upper bound ‘ub’ is to add ‘v’, the total valueof the items
already selected, the product of the remaining capacity of theknapsack W-w and the
best per unit payoff among the remaining items, whichis vi+1/wi+1, ub = v + (W-w)(
vi+1/wi+1)
22. Define Hamiltonian circuit problem. (R)
Hamiltonian circuit problem Determine whether a given graph has a
Hamiltonian circuit—a path that starts and ends at the same vertex and passes through
all the other vertices exactly once.
23. State Assignment problem. (MAY\JUNE 2016) (R)
There are n people who need to be assigned to execute n jobs, one person per
job. (That is, each person is assigned to exactly one job and each job is assigned to
exactly one person.) The cost that would acquire if the ith person is assigned to the jth
job is a known quantity [ , ] for each pair , = 1, 2, . . . , . The problem is to find an
assignment with the minimum total cost.
24. What is state space tree? (MAY\JUNE 2016) (R)
A state space tree is a rooted tree whose nodes represent partially constructed solutions to the
given problem. In backtracking method the state space tree is built for finding the solution. This
tree is built using depth first search fashion.
5
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
Euclidean distance between those two points. In simpler terms, an EMST connects a set
of dots using lines such that the total length of all the lines is minimized and any dot can
be reached from any other by following the lines.
28. Write the formula for decision tree for searching a sorted array? (NOV/DEC 2016)
(R)
29. State the reason for terminating search path at the current node in branch and
bound algorithm. (NOV/DEC 2016) (R)
The value of the node‘s bound is not better than the value of the best
solution seen so far.
The node represents no feasible solutions because the constraints of the
problem are already violated.
6
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
7. Explain the algorithm for finding all m-colorings of a graph.(APRIL/MAY 2012) (R)
7
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
sum is equivalent to m.Draw the portion of state space tree for this problem. (8) (A)
15.How backtracking works on 8-Queens problem with suitable example?
(MAY/JUNE 2013) (A)
16.(i) Give the backtracking algorithm for knapsack problem. (MAY/JUNE 2013)(8)
(ii) Explain elaborately recursive backtracking algorithm. (8) (R)
17.Explain Assignment problem using branch & bound technique with suitable example.
18. Explain Knapsack problem using branch & bound technique with suitable example.
19.Explain travelling salesman problem with suitable example.
REVIEW QUESTIONS:
1. Using backtracking, find the optimal solution to a knapsack problem for the knapsack
instance n=8,m=110,(p1…p7)=(11,21,31,33,43,53,55,65) and
(w1…w7)=(1,11,21,33,43,53,55,65). (A)
2.Write an algorithm to determine Hamiltonian cycle in a given graph using back tracking.
For the following graph determine the Hamiltonian cycle. (A)
A B
C F
D E
3.Write an algorithm to determine the Sum of Subsets for a given sum and a Set of
numbers. Draw the tree representation to solve the subset sum problem given the numbers
set as {3, 5, 6, 7, 2} with the sum=15. Derive all the subsets. (A)
4.Write an algorithm for N QUEENS problem and Trace it for n=6. (R)
6.Suggest an approximation algorithm for travelling salesperson problem. Assume that the
cost function satisfies the triangle inequality. (MAY 2015) (R)
7.Explain how job assignment problem could be solved, given n tasks and n agents where
each agent has a cost to complete each task, using branch and bound. (MAY 2015) (AN)
8
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
8. (i)The knight is placed on the first block of an empty board and, moving according
to the rules of chess, must visit each square exactly once. Solve the above problem
using backtracking procedure. (MAY 2015) (AN)
(ii) Implement an algorithm for Knapsack problem using NP-Hard approach. (MAY
2015) (R)
9. State the subset-sum problem and Complete state-space tree of the backtracking
algorithm applied to the instance A={3, 5, 6, 7} and d=15 of the subset-sum
problem.(MAY\JUNE 2016) (A)
10. (i) Draw a decision tree and find the number of key comparisons in the worst and
average cases for the three element bubble sort. (8) (NOV/DEC 2016) (AN)
a. Write backtracking algorithm for 4 queen’s problem and discuss the possible solution.
(8)
11. Solve the following instance of knapsack problem by branch and bound algorithm
W= 15.(16) (NOV/DEC 2016) (AN)
40
1 5
35
2 7
3 2 18
4
4 4
10
5 5
6 1 2
12. Apply Branch and bound algorithm to solve the travelling salesman problem.
(NOV/DEC 2016) (A)
13. Give the methods for Establishing Lower Bound. (NOV/DEC 17)
9
Prepared by D.Sujatha, AP/CSE SRRCET/CSE/II/IVSEM/CS3401-ALGORITHM
14. Find the optimal solution using branch and bound for the following assignment problem.
Draw the state space and show the reduced matrices corresponding to each of the
node. (13)(NOV/DEC 2018)
17. Write an algorithm for subset sum and explain with an example. (13)(APR/MAY 2019)
18. Explain the 4-queens problem using backtracking. Write the algorithms . Giv the
estimated cost for all possible solutions of 4-queens problem.Specify the implicit
and explicit constrints. (APR/MAY 2019)
10