





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






In the last lecture it was mentioned that graphs represent a type of space, in which discrete places are connected to one another via edges. One basic question that can be asked about this space is “How to find the shortest path from one place to another?”. For Cartesian space we know the answer involves taking a linear path from point A to point B. Moreover, the distance between these points can be obtained using the Pythagorean Theorem. For graphs a different method must be used since in general vertices on a graph are not directly connected by a line.
Let G = (V, E, c) be a network where c : E → R+^ represents the cost of traversing an edge of the graph. Then the cost of the path e 1 , e 2 ,... , em is defined as cost =
∑m i=1 c(ei). Moreover, the distance d between u and v is defined as the cost of the path which minimizes the above sum.
Example 1. Let G = (V, E, c), where
V = {a, b, c, d, e, f }
and the edges-costs are given by
E = {(a, b, 1), (a, c, 3), (b, c, 1), (b, d, 1), (b, e, 4), (c, d, 1), (c, f, 2),
(d, e, 1), (d, f, 3), (e, f, 2)}.
Draw the graph and determine the distance of each vertex from vertex a.
A Special Case: Unweighted Graphs
Let G = (V, E) be a unweighted graph. In other words c(e) = 1 for every edge e ∈ E. In this case the distance from vertex u to vertex v is the length of the shortest simple path that connects u and v. Thus we can define the distance d(a, v) between vertex a and any other vertex v using the following recursive definition.
Theorem 1. The recursive definition above yields the correct distances from a to any other vertex in G.
Proof.
Implementation of shortest- path algorithm for the unweigted case:
The above algorithm is an example of performing a breadth-first search on a graph. In other words, the vertices of the graph are examined in the order in which they are reached (FIFO).
Example 3. Show the contents of the queue Q during the execution of the algorithm on the graph of Example 2.
Dijkstra’s Algorithm
For the unweighted case, once a vertex v is reached, d(a, v) is immediately known. In the general case, however, this is not true. For example edge (a, b) may have a cost of 5, while edges (a, c) and (c, b) may each have costs of 1, thus making the distance from a to b ≤ 2 < 5. Hence, during each stage we only have estimated distances which may decrease during later rounds. However Dijkstra’s algorithm, which was discovered in the 1950’s, makes use of the following key observation: at any stage, the least estimated distance from a vertex v to a is the exact distance. This observation leads to Dijkstra’s Algorithm.
Dijkstra’s Algorithm
Theorem 1. Dijkstra’s Algorithm yields the correct distance from a for every vertex.
Proof.
Analysis of Dijkstra’s Algorithm: In the worst case, each edge needs to be examined at most twice. On the other hand, the vertices must be kept in a heap so that vertex with least estimated distance can be efficiently deleted. However, the fact that the priority values (i.e. estimated distances) are being dynamically updated makes the heaps we studied earlier this semester inadequate. However, there do exist heaps (namely Fibonacci heaps) which allow for the dynamic updating of priorities, in such a way that the worst-case complexity of building, updating, and deleting from the heap is O(|v| log |v|). Therefore, the worst-case complexity is O(|E| + |v| log |v|).
Example 5. For the graph G shown below. Use Dijkstra’s Algorithm to find the distance of each vertex from vertex a.
vertex minimum parent minimum parent minimum parent distance distance distance a b c d e f
Stage 1 Stage 2 Stage 3