• Home
  • Textbooks
  • Artificial Intelligence. A Modern Approach [Global Edition]
  • Solving Problems by Searching

Artificial Intelligence. A Modern Approach [Global Edition]

Stuart Russell, Peter Norvig

Chapter 3

Solving Problems by Searching - all with Video Answers

Educators


Chapter Questions

01:00

Problem 1

Explain why problem formulation must follow goal formulation.

Karly Williams
Karly Williams
Numerade Educator
12:00

Problem 2

Give a complete problem formulation for each of the following problems. Choose a formulation that is precise enough to be implemented.
a. There are six glass boxes in a row, each with a lock. Each of the first five boxes holds a key unlocking the next box in line; the last box holds a banana. You have the key to the first box, and you want the banana.
b. You start with the sequence $A B A B A E C C E C$, or in general any sequence made from $A$, $\mathrm{B}, \mathrm{C}$, and $\mathrm{E}$. You can transform this sequence using the following equalities: $\mathrm{AC}=\mathrm{E}$, $\mathrm{AB}=\mathrm{BC}, \mathrm{BB}=\mathrm{E}$, and $\mathrm{E} x=x$ for any $x$. For example, $\mathrm{ABBC}$ can be transformed into $\mathrm{AEC}$, and then $\mathrm{AC}$, and then $\mathrm{E}$. Your goal is to produce the sequence $\mathrm{E}$.
c. There is an $n \times n$ grid of squares, each square initially being either unpainted floor or a bottomless pit. You start standing on an unpainted floor square, and can either paint the square under you or move onto an adjacent unpainted floor square. You want the whole floor painted.
d. A container ship is in port, loaded high with containers. There 13 rows of containers, each 13 containers wide and 5 containers tall. You control a crane that can move to any location above the ship, pick up the container under it, and move it onto the dock. You want the ship unloaded.

Amit Srivastava
Amit Srivastava
Numerade Educator

Problem 3

You have a $9 \times 9$ grid of squares, each of which can be colored red or blue. The grid is initially colored all blue, but you can change the color of any square any number of times. Imagining the grid divided into nine $3 \times 3$ sub-squares, you want each sub-square to be all one color but neighboring sub-squares to be different colors.
a. Formulate this problem in the straightforward way. Compute the size of the state space.
b. You need color a square only once. Reformulate, and compute the size of the state space. Would breadth-first graph search perform faster on this problem than on the one in (a)? How about iterative deepening tree search?
c. Given the goal, we need consider only colorings where each sub-square is uniformly colored. Reformulate the problem and compute the size of the state space.
d. How many solutions does this problem have?
e. Parts (b) and (c) successively abstracted the original problem (a). Can you give a translation from solutions in problem (c) into solutions in problem (b), and from solutions in problem (b) into solutions for problem (a)?

Check back soon!

Problem 4

Suppose two friends live in different cities on a map, such as the Romania map shown in Figure 3.2. On every turn, we can simultaneously move each friend to a neighboring city on the map. The amount of time needed to move from city $i$ to neighbor $j$ is equal to the road distance $d(i, j)$ between the cities, but on each turn the friend that arrives first must wait until the other one arrives (and calls the first on his/her cell phone) before the next turn can begin. We want the two friends to meet as quickly as possible.
a. Write a detailed formulation for this search problem. (You will find it helpful to define some formal notation here.)
b. Let $D(i, j)$ be the straight-line distance between cities $i$ and $j$. Which of the following heuristic functions are admissible? (i) $D(i, j)$; (ii) $2 \cdot D(i, j)$; (iii) $D(i, j) / 2$.
c. Are there completely connected maps for which no solution exists?
d. Are there maps in which all solutions require one friend to visit the same city twice?

Check back soon!
00:50

Problem 5

Show that the 8-puzzle states are divided into two disjoint sets, such that any state is reachable from any other state in the same set, while no state is reachable from any state in the other set. (Hint: See Berlekamp et al. (1982).) Devise a procedure to decide which set a given state is in, and explain why this is useful for generating random states.

Sherrie Fenner
Sherrie Fenner
Numerade Educator

Problem 6

Consider the $n$-queens problem using the "efficient" incremental formulation given on page 72. Explain why the state space has at least $\sqrt[3]{n !}$ states and estimate the largest $n$ for which exhaustive exploration is feasible. (Hint: Derive a lower bound on the branching factor by considering the maximum number of squares that a queen can attack in any column.)

Check back soon!

Problem 7

Consider the problem of finding the shortest path between two points on a plane that has convex polygonal obstacles as shown in Figure 3.31. This is an idealization of the problem that a robot has to solve to navigate in a crowded environment.
a. Suppose the state space consists of all positions $(x, y)$ in the plane. How many states are there? How many paths are there to the goal?
b. Explain briefly why the shortest path from one polygon vertex to any other in the scene must consist of straight-line segments joining some of the vertices of the polygons. Define a good state space now. How large is this state space?
c. Define the necessary functions to implement the search problem, including an ACTIONS function that takes a vertex as input and returns a set of vectors, each of which maps the current vertex to one of the vertices that can be reached in a straight line. (Do not forget the neighbors on the same polygon.) Use the straight-line distance for the heuristic function.
d. Apply one or more of the algorithms in this chapter to solve a range of problems in the domain, and comment on their performance.

Check back soon!

Problem 8

On page 68, we said that we would not consider problems with negative path costs. In this exercise, we explore this decision in more depth.
a. Suppose that actions can have arbitrarily large negative costs; explain why this possibility would force any optimal algorithm to explore the entire state space.
b. Does it help if we insist that step costs must be greater than or equal to some negative constant $c$ ? Consider both trees and graphs.
c. Suppose that a set of actions forms a loop in the state space such that executing the set in some order results in no net change to the state. If all of these actions have negative cost, what does this imply about the optimal behavior for an agent in such an environment?
d. One can easily imagine actions with high negative cost, even in domains such as route finding. For example, some stretches of road might have such beautiful scenery as to far outweigh the normal costs in terms of time and fuel. Explain, in precise terms, within the context of state-space search, why humans do not drive around scenic loops indefinitely, and explain how to define the state space and actions for route finding so that artificial agents can also avoid looping.
e. Can you think of a real domain in which step costs are such as to cause looping?

Check back soon!

Problem 9

The missionaries and cannibals problem is usually stated as follows. Three missionaries and three cannibals are on one side of a river, along with a boat that can hold one or two people. Find a way to get everyone to the other side without ever leaving a group of missionaries in one place outnumbered by the cannibals in that place. This problem is famous in AI because it was the subject of the first paper that approached problem formulation from an analytical viewpoint (Amarel, 1968).
a. Formulate the problem precisely, making only those distinctions necessary to ensure a valid solution. Draw a diagram of the complete state space.
b. Implement and solve the problem optimally using an appropriate search algorithm. Is it a good idea to check for repeated states?
c. Why do you think people have a hard time solving this puzzle, given that the state space is so simple?

Check back soon!
02:09

Problem 10

Define in your own words the following terms: state, state space, search tree, search node, goal, action, transition model, and branching factor.

Christopher Nilsen
Christopher Nilsen
Numerade Educator
00:28

Problem 11

What's the difference between a world state, a state description, and a search node? Why is this distinction useful?

Niamat Khuda
Niamat Khuda
Numerade Educator

Problem 12

An action such as Go(Sibiu) really consists of a long sequence of finer-grained actions: turn on the car, release the brake, accelerate forward, etc. Having composite actions of this kind reduces the number of steps in a solution sequence, thereby reducing the search time. Suppose we take this to the logical extreme, by making super-composite actions out of every possible sequence of Go actions. Then every problem instance is solved by a single supercomposite action, such as Go(Sibiu)Go(Rimnicu Vilcea)Go(Pitesti)Go(Bucharest). Explain how search would work in this formulation. Is this a practical approach for speeding up problem solving?

Check back soon!

Problem 13

Does a finite state space always lead to a finite search tree? How about a finite state space that is a tree? Can you be more precise about what types of state spaces always lead to finite search trees? (Adapted from Bender, 1996.)

Check back soon!
05:35

Problem 14

Prove that GRAPH-SEARCH satisfies the graph separation property illustrated in Figure 3.9. (Hint: Begin by showing that the property holds at the start, then show that if it holds before an iteration of the algorithm, it holds afterwards.) Describe a search algorithm that violates the property.

Chris Trentman
Chris Trentman
Numerade Educator
02:56

Problem 15

Which of the following are true and which are false? Explain your answers.
a. Depth-first search always expands at least as many nodes as $\mathrm{A}^*$ search with an admissible heuristic.
b. $h(n)=0$ is an admissible heuristic for the 8-puzzle.
c. $A^*$ is of no use in robotics because percepts, states, and actions are continuous.
d. Breadth-first search is complete even if zero step costs are allowed.
e. Assume that a rook can move on a chessboard any number of squares in a straight line, vertically or horizontally, but cannot jump over other pieces. Manhattan distance is an admissible heuristic for the problem of moving the rook from square A to square B in the smallest number of moves.

Angelo Rendina
Angelo Rendina
Numerade Educator
05:20

Problem 16

A basic wooden railway set contains the pieces shown in Figure 3.32. The task is to connect these pieces into a railway that has no overlapping tracks and no loose ends where a train could run off onto the floor.
a. Suppose that the pieces fit together exactly with no slack. Give a precise formulation of the task as a search problem.
b. Identify a suitable uninformed search algorithm for this task and explain your choice.
c. Explain why removing any one of the "fork" pieces makes the problem unsolvable.
d. Give an upper bound on the total size of the state space defined by your formulation. (Hint: think about the maximum branching factor for the construction process and the maximum depth, ignoring the problem of overlapping pieces and loose ends. Begin by pretending that every piece is unique.)

Sheryl Ezze
Sheryl Ezze
Numerade Educator

Problem 17

Implement two versions of the $\operatorname{Result}(s, a)$ function for the 8-puzzle: one that copies and edits the data structure for the parent node $s$ and one that modifies the parent state directly (undoing the modifications as needed). Write versions of iterative deepening depth-first search that use these functions and compare their performance.

Check back soon!

Problem 18

On page 90, we mentioned iterative lengthening search, an iterative analog of uniform cost search. The idea is to use increasing limits on path cost. If a node is generated whose path cost exceeds the current limit, it is immediately discarded. For each new iteration, the limit is set to the lowest path cost of any node discarded in the previous iteration.
a. Show that this algorithm is optimal for general path costs.
b. Consider a uniform tree with branching factor $b$, solution depth $d$, and unit step costs. How many iterations will iterative lengthening require?
c. Now consider step costs drawn from the continuous range $[\epsilon, 1]$, where $0<\epsilon<1$. How many iterations are required in the worst case?
d. Implement the algorithm and apply it to instances of the 8-puzzle and traveling salesperson problems. Compare the algorithm's performance to that of uniform-cost search, and comment on your results.

Check back soon!
01:32

Problem 19

Describe a state space in which iterative deepening search performs much worse than depth-first search (for example, $O\left(n^2\right)$ vs. $O(n)$ ).

James Chok
James Chok
Numerade Educator

Problem 20

Write a program that will take as input two Web page URLs and find a path of links from one to the other. What is an appropriate search strategy? Is bidirectional search a good idea? Could a search engine be used to implement a predecessor function?

Check back soon!

Problem 21

Consider the vacuum-world problem defined in Figure 2.2.
a. Which of the algorithms defined in this chapter would be appropriate for this problem? Should the algorithm use tree search or graph search?
b. Apply your chosen algorithm to compute an optimal sequence of actions for a $3 \times 3$ world whose initial state has dirt in the three top squares and the agent in the center.
c. Construct a search agent for the vacuum world, and evaluate its performance in a set of $3 \times 3$ worlds with probability 0.2 of dirt in each square. Include the search cost as well as path cost in the performance measure, using a reasonable exchange rate.
d. Compare your best search agent with a simple randomized reflex agent that sucks if there is dirt and otherwise moves randomly.
e. Consider what would happen if the world were enlarged to $n \times n$. How does the performance of the search agent and of the reflex agent vary with $n$ ?

Check back soon!
01:10

Problem 22

Prove each of the following statements, or give a counterexample:
a. Breadth-first search is a special case of uniform-cost search.
b. Depth-first search is a special case of best-first tree search.
c. Uniform-cost search is a special case of $\mathrm{A}^*$ search.

James Kiss
James Kiss
Numerade Educator
02:21

Problem 23

Compare the performance of $\mathrm{A}^*$ and RBFS on a set of randomly generated problems
in the 8-puzzle (with Manhattan distance) and TSP (with MST—see Exercise 3.33) domains. Discuss your results. What happens to the performance of RBFS when a small random number is added to the heuristic values in the 8-puzzle domain?

James Kiss
James Kiss
Numerade Educator

Problem 24

Trace the operation of $\mathrm{A}^*$ search applied to the problem of getting to Bucharest from Lugoj using the straight-line distance heuristic. That is, show the sequence of nodes that the algorithm will consider and the $f, g$, and $h$ score for each node.

Check back soon!

Problem 25

Sometimes there is no good evaluation function for a problem but there is a good comparison method: a way to tell whether one node is better than another without assigning numerical values to either. Show that this is enough to do a best-first search. Is there an analog of $\mathrm{A}^*$ for this setting?

Check back soon!

Problem 26

Devise a state space in which $\mathrm{A}^*$ using GRAPH-SEARCH returns a suboptimal solution with an $h(n)$ function that is admissible but inconsistent.

Check back soon!

Problem 27

Accurate heuristics don't necessarily reduce search time in the worst case. Given any depth $d$, define a search problem with a goal node at depth $d$, and write a heuristic function such that $\left|h(n)-h^*(n)\right| \leq O\left(\log h^*(n)\right)$ but $\mathrm{A}^*$ expands all nodes of depth less than $d$.

Check back soon!
02:01

Problem 28

The heuristic path algorithm (Pohl, 1977) is a best-first search in which the evaluation function is $f(n)=(2-w) g(n)+w h(n)$. For what values of $w$ is this complete? For what values is it optimal, assuming that $h$ is admissible? What kind of search does this perform for $w=0, w=1$, and $w=2$ ?

James Kiss
James Kiss
Numerade Educator

Problem 29

Consider the unbounded version of the regular 2D grid shown in Figure 3.9. The start state is at the origin, $(0,0)$, and the goal state is at $(x, y)$.
a. What is the branching factor $b$ in this state space?
b. How many distinct states are there at depth $k$ (for $k>0$ )?
c. What is the maximum number of nodes expanded by breadth-first tree search?
d. What is the maximum number of nodes expanded by breadth-first graph search?
e. Is $h=|u-x|+|v-y|$ an admissible heuristic for a state at $(u, v)$ ? Explain.
f. How many nodes are expanded by $\mathrm{A}^*$ graph search using $h$ ?
g. Does $h$ remain admissible if some links are removed?
h. Does $h$ remain admissible if some links are added between nonadjacent states?

Check back soon!
01:34

Problem 30

Consider the problem of moving $k$ knights from $k$ starting squares $s_1, \ldots, s_k$ to $k$ goal squares $g_1, \ldots, g_k$, on an unbounded chessboard, subject to the rule that no two knights can land on the same square at the same time. Each action consists of moving up to $k$ knights simultaneously. We would like to complete the maneuver in the smallest number of actions.
a. What is the maximum branching factor in this state space, expressed as a function of $k$ ?
b. Suppose $h_i$ is an admissible heuristic for the problem of moving knight $i$ to goal $g_i$ by itself. Which of the following heuristics are admissible for the $k$-knight problem? Of those, which is the best?
(i) $\min \left\{h_1, \ldots, h_k\right\}$.
(ii) $\max \left\{h_1, \ldots, h_k\right\}$.
(iii) $\sum_{i=1}^k h_i$.
c. Repeat (b) for the case where you are allowed to move only one knight at a time.

Carson Merrill
Carson Merrill
Numerade Educator
01:58

Problem 31

We saw on page 93 that the straight-line distance heuristic leads greedy best-first search astray on the problem of going from Iasi to Fagaras. However, the heuristic is perfect on the opposite problem: going from Fagaras to Iasi. Are there problems for which the heuristic is misleading in both directions?

Victor Salazar
Victor Salazar
Numerade Educator

Problem 32

Prove that if a heuristic is consistent, it must be admissible. Construct an admissible heuristic that is not consistent.

Check back soon!

Problem 33

The traveling salesperson problem (TSP) can be solved with the minimum-spanningtree (MST) heuristic, which estimates the cost of completing a tour, given that a partial tour has already been constructed. The MST cost of a set of cities is the smallest sum of the link costs of any tree that connects all the cities.
a. Show how this heuristic can be derived from a relaxed version of the TSP.
b. Show that the MST heuristic dominates straight-line distance.
c. Write a problem generator for instances of the TSP where cities are represented by random points in the unit square.
d. Find an efficient algorithm in the literature for constructing the MST, and use it with $\mathrm{A}^*$ graph search to solve instances of the TSP.

Check back soon!

Problem 34

On page 105, we defined the relaxation of the 8-puzzle in which a tile can move from square A to square B if B is blank. The exact solution of this problem defines Gaschnig's heuristic (Gaschnig, 1979). Explain why Gaschnig's heuristic is at least as accurate as $h_1$ (misplaced tiles), and show cases where it is more accurate than both $h_1$ and $h_2$ (Manhattan distance). Explain how to calculate Gaschnig's heuristic efficiently.

Check back soon!

Problem 35

We gave two simple heuristics for the 8-puzzle: Manhattan distance and misplaced tiles. Several heuristics in the literature purport to improve on this-see, for example, Nilsson (1971), Mostow and Prieditis (1989), and Hansson et al. (1992). Test these claims by implementing the heuristics and comparing the performance of the resulting algorithms.

Check back soon!