The answer is no. To see why, let's first articulate the question like so:
Q: For a connected, undirected, weighted graph G = (V, E, w)
with only nonnegative edge weights, does the predecessor subgraph produced by Dijkstra's Algorithm form a minimum spanning tree of G?
(Note that undirected graphs are a special class of directed graphs, so it is perfectly ok to use Dijkstra's Algorithm on undirected graphs. Furthermore, MST's are defined only for connected, undirected graphs, and are trivial if the graph is not weighted, so we must restrict our inquiry to these graphs.)
A: Dijkstra's Algorithm at every step greedily selects the next edge that is closest to some source vertex s. It does this until s is connected to every other vertex in the graph. Clearly, the predecessor subgraph that is produced is a spanning tree of G
, but is the sum of edge weights minimized?
Prim's Algorithm, which is known to produce a minimum spanning tree, is highly similar to Dijkstra's Algorithm, but at each stage it greedily selects the next edge that is closest to any vertex currently in the working MST at that stage. Let's use this observation to produce a counterexample.
Counterexample: Consider the undirected graph G = (V, E, w)
where
V = { a, b, c, d }
E = { (a,b), (a,c), (a,d), (b,d), (c,d) }
w = {
( (a,b) , 5 )
( (a,c) , 5 )
( (a,d) , 5 )
( (b,d) , 1 )
( (c,d) , 1 )
}
Take a
as the source vertex.
Dijkstra's Algorithm takes edges { (a,b), (a,c), (a,d) }
.
Thus, the total weight of this spanning tree is 5 + 5 + 5 = 15.
Prim's Algorithm takes edges { (a,d), (b,d), (c,d) }
.
Thus, the total weight of this spanning tree is 5 + 1 + 1 = 7.