This fle contains the exercises, hints, and solutions For Chapter 12 oF the
book ”Introduction to the Design and Analysis oF Algorithms,” 2nd edition, by
A. Levitin. The problems that might be challenging For at least some students
are marked by
±
;
those that might be diﬃcult For a majority oF students are
marked by
²
.
Exercises 12.1
1. a. Continue the backtracking search For a solution to the Fourqueens
problem, which was started in this section, to fnd the second solution to
the problem.
b. Explain how the board’s symmetry can be used to fnd the second
solution to the Fourqueens problem.
2. a. Which is the
last
solution to the fvequeens problem Found by the
backtracking algorithm?
b. Use the board’s symmetry to fnd at least Four other solutions to the
problem.
3. a. Implement the backtracking algorithm For the
n
queensprob
leminthe
language oF your choice. Run your program For a sample oF
n
values to
get the numbers oF nodes in the algorithm’s statespace trees. Compare
these numbers with the numbers oF candidate solutions generated by the
exhaustivesearch algorithm For this problem.
b. ±or each value oF
n
For which you run your program in part a, estimate
the size oF the statespace tree by the method described in Section 12.1
and compare the estimate with the actual number oF nodes you obtained.
4. Apply backtracking to the problem oF fnding a Hamiltonian circuit in the
Following graph.
f
a
b
g
d
e
c
5. Apply backtracking to solve the 3coloring problem For the graph in ±igure
12.3a.
6. Generate all permutations oF
{
1
,
2
,
3
,
4
}
by backtracking.
7. a. Apply backtracking to solve the Following instance oF the subsetsum
problem:
S
=
{
1
,
3
,
4
,
5
}
and
d
=11
.
b. Will the backtracking algorithm work correctly iF we use just one oF
the two inequalities to terminate a node as nonpromising?
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document8. The general template for backtracking algorithms, which was given in
Section 12.1, works correctly only if no solution is a preFx to another
solution to the problem.
Change the pseudocode to work correctly for
such problems as well.
9. Write a program implementing a backtracking algorithm for
a. the Hamiltonian circuit problem.
b. the
m
coloring problem.
10.
Puzzle pegs
This puzzlelike game is played on a board with 15 small
holes arranged in an equilateral triangle.
In an initial position, all but
one of the holes are occupied by pegs, as in the example shown below. A
legal move is a jump of a peg over its immediate neighbor into an empty
square opposite; the jump removes the jumpedover neighbor from the
board.
Design and implement a backtracking algorithm for solving the following
versions of this puzzle.
a. Starting with a given location of the empty hole, Fnd a shortest se
quence of moves that eliminates 14 pegs with no limitations on the Fnal
position of the remaining peg.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 DrT
 Algorithms, Approximation algorithm

Click to edit the document details