Graph Traversals
A campus network is modelled by the undirected graph below. Each edge represents one link between locations. The distance from A to another location is the smallest number of edges in any route connecting them.
Use breadth-first search starting at A to complete the table. Enter an exact integer counting edges for each reachable location, and enter unreachable for any location that cannot be reached from A.
| Location | Distance from A in edges |
| B | |
| C | |
| D | |
| E | |
| F | |
| G |
A connection map is represented by the undirected graph below. Run recursive depth-first search, which explores an unvisited neighbour's branch before returning to consider another neighbour.
Start at P and mark each vertex immediately when its recursive call begins. At every vertex, inspect neighbours in alphabetical order and recurse only into unmarked neighbours. Arrange the vertices in their order of first discovery, from earliest to latest. Record discoveries rather than returns from recursive calls.
1.
S
2.
U
3.
R
4.
Q
5.
P
6.
T