Topic 2
Algorithms on graphs
Two questions come up again and again with networks. What is the cheapest way to connect every vertex, for cables, pipes or roads? And what is the shortest route from one place to another? The first is answered by a minimum spanning tree, found with Kruskal's or Prim's algorithm. The second is answered by Dijkstra's algorithm for routes from one starting vertex, and by Floyd's algorithm for the shortest routes between every pair of vertices.
What you need to know
- Understand what a minimum spanning tree is, and find one with Kruskal's algorithm and Prim's algorithm.
- Apply Prim's algorithm to a network given as a distance matrix.
- Use Dijkstra's algorithm to find the shortest path from one vertex to every other, on undirected and directed networks, and read off the route.
- Use Floyd's algorithm to find the shortest distances and routes between every pair of vertices, using a distance table and a route table.
- Adapt to changes: an arc that must be included, an arc that is closed, or an arc with an unknown weight.
The network above is used for the worked examples in the first two lessons. [The total weight of the network is 65.]
Key points
- A minimum spanning tree connects all vertices with arcs of least total weight.
- Kruskal's: arcs in order of weight, reject any that makes a cycle. Prim's: grow one tree, always adding the cheapest arc to a new vertex; works directly on a matrix.
- Dijkstra's: make the smallest working value final, update neighbours only with smaller values, trace back to find the route.
- Floyd's: for each intermediate vertex , replace by when shorter, and copy the route entry from row X, column .
- List arcs in order, fill in every working value, and show both Floyd tables at each iteration.
Practise this topic
Quiz me on this topic10 questions, marked as you go.Make a practice paperPick the marks and difficulty. Print it with a mark scheme.
Both are part of Premium.