## Graph Theory Lecture Notes 17

### Dijkstra's Shortest Path Algorithm

Given a directed network and interpreting the arc weights as distances, a very common practical
problem is to find the path of minimum distance (shortest path) between some specified pair of
vertices, say x and y. An algorithm for doing this is due to Dijkstra.
We will maintain two lists, W a list of vertices and B a list of arcs. For each vertex that gets put in
W we will also record the distance from x to that vertex. Initially, the list B is empty, x is placed in
W and d(x,x) = 0.

The algorithm proceeds as follows:

For each vertex u in W and v not in W we calculate the number d(x,u) + wt(u,v). Select the u
and v that give the minimum value (in case of ties, chose arbitrarily). If there is no minimum then
stop and indicate that there is no path from x to y. If there is a minimum then put v in W, put (u,v)
in B and record d(x,v) = d(x,u) + wt(u,v).

Repeat the procedure until y is placed in W. The shortest path is the unique path of arcs in B that
lead from x to y (most easily obtained by working backwards from y).

There is an animated explanation of this algorithm on the web.

### Scheduling Problems

Instead of interpreting the edge weights as distances, they may represent costs or times. The
algorithm we have used can then be applied to find schedules of minimum cost or minimum time.
In these situations the network is often called a **PERT** (Project Evaluation and Review Technique)
network or a **CPM** (Critical Path Method) network.

### The Chinese Postman Problem revisited

In the chinese postman problem, we needed to find the minimum number of multiple edges to add to
a graph, so that the multigraph obtained would have a closed eulerian chain, that is, so that every
vertex would have even degree. We can now describe a procedure to do this.
First we construct, from the given graph G, a graph G' consisting of the vertices of odd degree in
G. We join the vertices in G' with edges if there is a chain in G between them, and we label each
edge by the length of the shortest path between the two endpoints. This information is obtained by
using Dijsktra's algorithm in G. When all the edges of G' have been labeled, then we seek a
minimum weight perfect matching in G'. The matching will tell us which vertices in G will be
joined by chains of multiple edges to obtain the minimum number of edges to add to G.