A-level Mathematics/MEI/D1/Networks

Networks are weighted graphs, their edges have associated weights with them. Networks are useful for modelling geographical problems (though they have many other uses). Networks have a walk called the minimum spanning tree which is the shortest walk that connects every node in the network via edges. There are two algorithms for producing the minimal spanning tree: Kruskal's algorithm and Prim's algorithm, by the end of this page you should be able to use both algorithms in graphical form and Prim's algorithm in tabular form.

Finally you should also be able to use Dijkstra's algorithm to find the shortest route between two points.

Kruskal's algorithm

 * 1) Pick the shortest edge of the network.
 * 2) Pick the next shortest edge of the network that doesn't link nodes between which a path has already been established.
 * 3) Repeat 2, until n-1 edges have been selected (where n is the number of nodes in the network).

Here's an example on Wikipedia: Kruskal's algorithm example.

Graphical approach

 * 1) Pick an arbitrary node.
 * 2) Connect that node to its nearest node by an edge.
 * 3) Now connect the nearest node that isn't already connected to the walk you're forming.
 * 4) Repeat 3 until all nodes have been connected.

Example: Graphical run of Prim's algorithm.

Tabular approach
Networks can be represented in tabular form where distances are recorded between nodes.
 * 1) Select an arbitrary node X.
 * 2) Delete row X.
 * 3) Look for smallest value in column X, read which node it belongs to, this is your new node Y.
 * 4) Delete row Y.
 * 5) Look for smallest value in column X and Y, then go to 3, repeat until network is connected.

Example: Tabular run of Prim's algorithm.

Dijkstra's algorithm
Permanent labels (P-labels) are depicted by a value contained in a box.

Temporary labels (T-labels) are depicted by a value with no box.


 * 1) Step 1
 * 2) Label start node S with a P-label of 0.
 * 3) For all nodes reachable from S, assign a T-label equal to their direct distances from S.
 * 4) Select the node with the smallest T-label value, make this a P-label, this label marks the shortest distance from S to that node
 * 5) Step 2
 * 6) Put a T-label on each node that can be reached directly from the node that has just been marked with a P-label. The T-label should be equal to the sum of the P-label and the direct distance from it. If there is an existing T-label at a node, it should be replaced if the new sum is smaller.
 * 7) Select the minimum T-label and make it permanent.
 * 8) If this labels the destination node continue, else repeat step 2.
 * 9) Step 3
 * 10) Trace back from the current node (the destination node) to the start node including any edge MN where (P-label of M) - (P-lalbel of N) = length of arc MN.

Example:

Find the shortest route between S and T using Dijkstra's algorithm.