17: Graph Search

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


A. (1 point) Suppose you treat the integers as a graph. In other words, there are an infinite number of vertices; 0 is adjacent to -1 and 1; 1 is adjacent to 0 and 2; and so on. This representation is similar to the “number line” that is sometimes used to teach basic arithmetic.

If you were to perform a breadth-first search, starting at 0 and with a goal of 3, in what order would the integers be visited? Assume that the neighbors of each integer are returned in their natural order (for example, the neighbors of 0 are -1 and 1, in that order).

B. Suppose you have the following directed graph.

hw17-graph

(1 point) If you were to perform a breadth-first search, starting at S and trying to reach either of the two goal vertices (G1 or G2), in what order would the vertices be added to the frontier? Use the BFS algorithm we covered in class (findPath).

Assume that the neighbors of each vertex are returned in alphabetical order. For example, the only neighbors of S are A and B, in that order. But neither B nor A are neighbors of S.

C. (1 point) What is the first path from S to one of the goal vertices that this search would return?