Before we start today’s section, we ask that you complete the course evaluations for this class. The evaluations can be found here. These submissions are anonymous, so please answer honestly about the course, Dr. Sullivan, and your TAs.
Consider the following weighted, undirected graph representing the distances from city to city by way of the Autobahn in Germany.
What are Berlin’s neighbors in the graph? 1
Is this graph connected? Why or why not? 2
Is it complete? Why or why not? 3
Is this graph acyclic? If the graph is cyclic, provide an example of a cycle. 4
If we used an adjacency matrix to represent this graph, what would it look like? Assume that the vertices are numbered alphabetically, starting from zero. 5
For the following graph traversals, list the order in which the cities would be considered and draw the resulting spanning tree.
Perform a depth-first traversal of the graph, starting from Düsseldorf. List the order in which cities are considered and draw the resulting spanning tree. 6
Perform a breadth-first traversal of the graph, starting from Berlin. List the order in which cities are considered and draw the resulting spanning tree. 7
Berlin’s neighbors are Hamburg, Düsseldorf, Cologne, and Stuttgart. ↩
This graph is connected, since there is a path from one vertex to any other vertex in the graph. ↩
This graph is not complete, since there is not an edge from each vertex to every other vertex in the graph. ↩
This graph has at least one cycle. It is therefore cyclic, or not acyclic. An example of a cycle is the one formed among Hamburg, Berlin, and Düsseldorf. ↩
Here’s the adjacency matrix. Each vertex is labeled with the first letter of its name.
| B | C | D | F | H | M | S | |
|---|---|---|---|---|---|---|---|
| B | - | 580 | 567 | 293 | 640 | ||
| C | 580 | - | 39 | 191 | |||
| D | 567 | 39 | - | 401 | |||
| F | 191 | - | 204 | ||||
| H | 293 | 401 | - | ||||
| M | - | 233 | |||||
| S | 640 | 204 | 233 | - |
A depth-first traversal from Düsseldorf results in the following sequence of visited vertices: Düsseldorf, Cologne, Frankfurt am Main, Stuttgart, Munich, Berlin, Hamburg. Here’s the spanning tree:
A breadth-first traversal from Berlin results in the following sequence of visited vertices: Berlin, Hamburg, Düsseldorf, Cologne, Stuttgart, Frankfurt, Munich.
Here’s the table showing the edges added to set A from set B, where A initially contains Hamburg. Each city is denoted by the first letter in its name.
| edge added | set A | set B |
|---|---|---|
| H | B, C, D, F, M, S | |
| B–H | B, H | C, D, F, M, S |
| D–H | B, D, H | C, F, M, S |
| C–D | B, C, D, H | F, M, S |
| C–F | B, C, D, F, H | M, S |
| F–S | B, C, D, F, H, S | M |
| M–S | B, C, D, F, H, M, S |
Here’s the table showing each step of Dijkstra’s algorithm. We start by finalizing Cologne’s distance of zero.
| city | |||||||
|---|---|---|---|---|---|---|---|
| Berlin | ∞ | 580 | 580 | 580 | 580 | 580 | |
| Cologne | 0 | ||||||
| Düsseldorf | ∞ | 39 | |||||
| Frankfurt | ∞ | 191 | 191 | ||||
| Hamburg | ∞ | ∞ | 440 | 440 | 440 | ||
| Munich | ∞ | ∞ | ∞ | ∞ | 628 | 628 | 628 |
| Stuttgart | ∞ | ∞ | ∞ | 395 |
Last updated on August 4, 2026.