Loading subject…
The words matter because each algorithm below is defined by one of them, for example an Eulerian circuit is about edges while a Hamiltonian cycle is about vertices.
| Term | Repeats edges? | Repeats vertices? | Starts = ends? |
|---|---|---|---|
| Walk | Allowed | Allowed | Either |
| Trail | No | Allowed | Either |
| Path | No | No | No |
| Circuit | No | Allowed | Yes |
| Cycle | No | No (except start) | Yes |
A graph has edges $AB$, $BC$, $BD$, $CD$ and $DA$. Give the most specific correct term (walk, trail, path, circuit, or cycle) for each journey: (i) $A\to B\to C\to D\to A$; (ii) $A\to B\to D\to C\to B$.
Solution
A connected graph has vertices of degree $A:2$, $B:2$, $C:4$, $D:2$, $E:4$. State whether it has an Eulerian circuit, an Eulerian trail, or neither, and justify your answer.
Solution
Deciding whether one exists in a large graph is genuinely hard, which is exactly what makes the travelling salesman problem difficult.
There are two standard algorithms, Kruskal's and Prim's, and both reach the same minimum total even if edges are added in a different order.
Kruskal's works on the whole edge list at once, so it can grow separate pieces that only merge into one tree at the end.
For the weighted graph above, use Kruskal's algorithm to find a minimum spanning tree and state its total weight.
Solution
Unlike Kruskal's, Prim's keeps a single connected tree growing at every stage, never separate pieces.
For the same graph, use Prim's algorithm starting at $A$ to find a minimum spanning tree.
Solution
| A | B | C | D | E | |
|---|---|---|---|---|---|
| A | - | 4 | 7 | - | - |
| B | 4 | - | 2 | 5 | - |
| C | 7 | 2 | - | 8 | 6 |
| D | - | 5 | 8 | - | 3 |
| E | - | - | 6 | 3 | - |
Use the distance matrix above and Prim's algorithm, starting at $A$, to find the minimum spanning tree.
Solution
The graph shown has edges $AB=4$, $AC=2$, $BC=3$, $BD=5$, $CD=3$, $CE=6$, $DE=4$. A road inspector must drive along every road and return to the start. Find the length of the shortest such route.
Solution
| Bound | Algorithm | What it gives |
|---|---|---|
| Upper bound | Nearest-neighbour | Length of one actual round trip |
| Lower bound | Deleted-vertex | MST of the rest, plus two shortest edges at the deleted vertex |
| A | B | C | D | E | |
|---|---|---|---|---|---|
| A | - | 5 | 8 | 9 | 7 |
| B | 5 | - | 6 | 12 | 4 |
| C | 8 | 6 | - | 3 | 10 |
| D | 9 | 12 | 3 | - | 11 |
| E | 7 | 4 | 10 | 11 | - |
Using the distance matrix above, apply the nearest-neighbour algorithm starting at $A$ to find an upper bound for the travelling salesman problem.
Solution
For the same graph, apply the deleted-vertex algorithm by deleting $A$ to find a lower bound.
Solution
Using the same distance matrix, apply the nearest-neighbour algorithm starting at $C$ to find an upper bound for the shortest round trip.
Solution