• Home
  • Textbooks
  • Foundations of Algorithms using C++ Pseudocode
  • Backtracking

Foundations of Algorithms using C++ Pseudocode

Richard Neapolitan, Kumarss Naimipour

Chapter 5

Backtracking - all with Video Answers

Educators


Chapter Questions

02:25

Problem 1

Apply the Backtracking algorithm for the $n$ Queens problem (Algorithm 5.1) to the problem instance in which $n=8,$ and show the actions step by step. Draw the pruned state space tree produced by this algorithm up to the point where the first solution is found.

WM
William Mead
Numerade Educator
02:25

Problem 2

Write a backtracking algorithm for the $n$ -Queens problem that uses a version of procedure expand instead ofa version of procedure checknode.

WM
William Mead
Numerade Educator
01:10

Problem 3

Show that, without backtracking, 155 nodes must be checked before the first solution to the $n$ $=4$ instance of the $n$ -Queens problem is found (in contrast to the 27 nodes in Figure 5.4 ).

Nick Johnson
Nick Johnson
Numerade Educator
02:25

Problem 4

Implement the Backtracking algorithm for the $n$ Queens problem (Algorithm 5.1) on your system, and run it on problem instances in which $n=4$ $8,10,$ and 12.

WM
William Mead
Numerade Educator
05:23

Problem 5

Improve the Backtracking algorithm for the $n$ Queens problem (Algorithm 5.1) by having the promising function keep track of the set of columns, of left diagonals, and of right diagonals controlled by the queens already placed.

Morgan Cheatham
Morgan Cheatham
Numerade Educator
02:13

Problem 6

Modify the Backtracking algorithm for the $n$ Queens problem (Algorithm 5.1) so that, instead of generating all possible solutions, it finds only a single solution.

Lucas Gagne
Lucas Gagne
Numerade Educator
12:19

Problem 7

Suppose we have a solution to the $n$ -Queens problem instance in which $n=4 .$ Can we extend this solution to find a solution to the problem instance in which $n=5 ?$ Can we then use the solutions for $n=4$ and $n=5$ to construct a solution to the instance in which $n=6$ and continue this dynamic programming approach to find a solution to any instance in which $n>4 ?$ Justify your answer.

Bryan Lynn
Bryan Lynn
Numerade Educator
05:23

Problem 8

Find at least two instances of the $n$ -Queens problem that have no solutions.

Morgan Cheatham
Morgan Cheatham
Numerade Educator
03:01

Problem 9

Implement algorithm 5.3 (Monte Carlo estimate for the Backtracking algorithm for the $n$ -Queens problem) on your system, run it 20 times on the problem instance in which $n=8,$ and find the average of the 20 estimates.

John Vanschoick
John Vanschoick
Numerade Educator
02:18

Problem 10

Modify the Backtracking algorithm for the $n$ Queens problem (Algorithm 5.1) so that it finds the number of nodes checked for an instance of a problem, run it on the problem instance in which $n=8,$ and compare the result against the average of Exercise 9.

Nick Johnson
Nick Johnson
Numerade Educator
03:56

Problem 11

Use the Backtracking algorithm for the Sum-ofSubsets problem (Algorithm 5.4) to find all combinations of the following numbers that sum to $W=52:$
\[
w_{1}=2 \quad w_{2}=10 \quad w_{3}=13 \quad w_{4}=17 \quad w_{5}=22 \quad w_{6}=42
\]
Show the actions step by step.

Akash Goyal
Akash Goyal
Numerade Educator
03:09

Problem 12

Implement the Backtracking algorithm for the Sum-of-Subsets problem (Algorithm 5.4) on your system, and run it on the problem instance of Exercise 11.

Nick Johnson
Nick Johnson
Numerade Educator
01:05

Problem 13

Write a backtracking algorithm for the Sum-ofSubsets problem that does not sort the weights in advance. Compare the performance of this algorithm with that of Algorithm 5.4.

Clarissa Noh
Clarissa Noh
Numerade Educator
01:18

Problem 14

Modify the Backtracking algorithm for the Sumof-Subsets problem (Algorithm 5.4) so that, instead of generating all possible solutions, it finds only a single solution. How does this algorithm perform with respect to Algorithm $5.4 ?$

Mohamed Mohamed
Mohamed Mohamed
Numerade Educator
07:51

Problem 15

Use the Monte Carlo technique to estimate the efficiency of the Backtracking algorithm for the Sum-of-Subsets problem (Algorithm 5.4).

Willis James
Willis James
Numerade Educator
01:40

Problem 16

Use the Backtracking algorithm for the $m$ Coloring problem (Algorithm 5.5) to find all possible colorings of the graph below using the three colors red, green, and white. Show the actions step by step.

Carson Merrill
Carson Merrill
Numerade Educator
05:12

Problem 17

Suppose that to color a graph properly we choose a starting vertex and a color to color as many vertices as possible. Then we select a new color and a new uncolored vertex to color as many more vertices as possible. We repeat this process until all the vertices of the graph are colored or all the colors are exhausted. Write an algorithm for this greedy approach to color a graph of $n$ vertices. Analyze this algorithm and show the results using order notation.

Carson Merrill
Carson Merrill
Numerade Educator
00:24

Problem 18

Use the algorithm of Exercise 17 to color the graph of Exercise 16.

Margaret Farmer
Margaret Farmer
Numerade Educator
01:01

Problem 19

Suppose we are interested in minimizing the number of colors used in coloring a graph. Does the greedy approach of Exercise 17 guarantee an optimal solution? Justify your answer.

Prathan Jarupoonphol
Prathan Jarupoonphol
Numerade Educator
04:22

Problem 20

Compare the performance of the Backtracking algorithm for the $m$ -Coloring problem (Algorithm 5.5 ) and the greedy algorithm of Exercise 17 Considering the result(s) of the comparison and your answer to Exercise $19,$ why might one be interested in using an algorithm based on the greedy approach?

Bryan Lynn
Bryan Lynn
Numerade Educator
02:27

Problem 21

Write an algorithm for the 2 -Coloring problem whose time complexity is not worst-case exponential in $n$.

Trang Hoang
Trang Hoang
Numerade Educator
01:44

Problem 22

List some of the practical applications that are representable in terms of the $m$ -Coloring problem.

SS
Sarvesh Somasundaram
Numerade Educator
07:16

Problem 23

Use the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6) to find all possible Hamiltonian Circuits of the following graph.
Show the actions step by step.

Brian Lin
Brian Lin
Numerade Educator
03:09

Problem 24

Implement the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6) on your system, and run it on theproblem instance of Exercise 23.

Carson Merrill
Carson Merrill
Numerade Educator
01:57

Problem 25

Change the starting vertex in the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6 ) in Exercise 24 and compare its performance with that of Algorithm 5.6.

WZ
Wen Zheng
Numerade Educator
00:36

Problem 26

Modify the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6) so that, instead of generating all possible solutions, it finds only a single solution. How does this algorithm perform with respect to Algorithm 5.6?

WZ
Wen Zheng
Numerade Educator
01:07

Problem 27

Analyze the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6) and show the worst-case complexity using order notation.

Clarissa Noh
Clarissa Noh
Numerade Educator
07:51

Problem 28

Use the Monte Carlo Technique to estimate the efficiency of the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6).

Willis James
Willis James
Numerade Educator
16:25

Problem 29

Compute the remaining values and bounds after visiting node (4,1) in Example 5.6 (Section $5.7 .1)$

Carlos Pinilla
Carlos Pinilla
Numerade Educator
01:18

Problem 30

Use the Backtracking algorithm for the $0-1$ Knapsack problem (Algorithm 5.7) to maximize the profit for the following problem instance. Show the actions step by step.
$$\begin{array}{ccccc}
i & p_{i} & w_{i} & \frac{p_{i}}{w_{i}} & \\
1 & \$ 20 & 2 & 10 & \\
2 & \$ 30 & 5 & 6 & \\
3 & \$ 35 & 7 & 5 & W=19 \\
4 & \$ 12 & 3 & 4 & \\
5 & \$ 3 & 1 & 3 &
\end{array}$$

Ernest Castorena
Ernest Castorena
Numerade Educator
01:07

Problem 31

Implement the Backtracking algorithm for the 0 -
1 Knapsack problem (Algorithm 5.7) on your system, and run it on the problem instance of Exercise 30.

Clarissa Noh
Clarissa Noh
Numerade Educator
01:07

Problem 32

Implement the dynamic programming algorithm for the $0-1 \text { Knapsack problem (see Section } 4.4 .3)$ and compare the performance of this algorithm with the Backtracking algorithm for the $0-1$ Knapsack problem (Algorithm 5.7) using large instances of the problem.

Clarissa Noh
Clarissa Noh
Numerade Educator
07:02

Problem 33

Improve the Backtracking algorithm for the $0-1$ Knapsack problem (Algorithm 5.7) by calling the promising function after only a move to the right.

Lucas Gagne
Lucas Gagne
Numerade Educator
07:51

Problem 34

Use the Monte Carlo technique to estimate the efficiency of the Backtracking algorithm for the $0-1$ Knapsack problem (Algorithm 5.7).

Willis James
Willis James
Numerade Educator
00:47

Problem 35

List three more applications of backtracking.

AG
Ankit Gupta
Numerade Educator
02:06

Problem 36

Modify the Backtracking algorithm for the $n$ Queens problem (Algorithm 5.1) so that it produces only the solutions that are invariant under reflections or rotations.

Adriano Chikande
Adriano Chikande
Numerade Educator
05:23

Problem 37

Given an $n \times n \times n$ cube containing $n^{3}$ cells, we are to place $n$ queens in the cube so that no two queens challenge each other (so that no two queens are in the same row, column, or diagonal). Can the $n$ -Queens algorithm (Algorithm 5.1) be extended to solve this problem? If so, write the algorithm and implement it on your system to solve problem instances in which $n=4$ and $n=8$.

Morgan Cheatham
Morgan Cheatham
Numerade Educator
03:09

Problem 38

Modify the Backtracking algorithm for the Sumof-Subsets (Algorithm 5.4) to produce the solutions in a variable-length list.

Nick Johnson
Nick Johnson
Numerade Educator
05:12

Problem 39

Explain how we can use the Backtracking algorithm for the $m$ -Coloring problem (Algorithm
5.5 to color the edges of the graph of Exercise 16 using the same three colors so that edges with a common end receive different colors.

Carson Merrill
Carson Merrill
Numerade Educator
00:36

Problem 40

Modify the Backtracking algorithm for the Hamiltonian Circuits problem (Algorithm 5.6) so that it finds a Hamiltonian Circuit with minimum cost for a weighted graph. How does your algorithm perform?

WZ
Wen Zheng
Numerade Educator
02:07

Problem 41

Modify the Backtracking algorithm for the $0-1$ Knapsack problem (Algorithm 5.7) to produce a solution in a variable-length list.

Lucas Gagne
Lucas Gagne
Numerade Educator