Math 156
Discrete Mathematics for Computer Science
Fall 2001

This page is no longer actively maintained. You might want to visit the most recent Math 156 page.

Three Labeled Graphs

Find the shortest path from a to z through each of these graphs. Notice that all the edges connected to the vertices a and z are identical in each graph, but the shortest paths are different. This demonstrates that a greedy algorithm that simply chooses at each step to follow the shortest untraveled edge adjacent to the current vertex will not always find the shortest route.

                   3
                b --- d
             2 / \     \ 2
              /   \     \
             a     \ 6   z              upper path best
              \     \   /
             4 \     \ / 1
                c --- e
                   5

                   5
                b --- d
             2 / \     \ 2
              /   \     \
             a     \ 6   z              lower path best
              \     \   /
             4 \     \ / 1
                c --- e
                   3

                   5
                b --- d
             2 / \     \ 2
              /   \     \
             a     \ 3   z              middle path best
              \     \   /
             4 \     \ / 1
                c --- e
                   6


Dijkstra's Algorithm

Dijkstra's algorithm is also a kind of "greedy" algorithm, but it explores more than just a single path in the graph. In fact, for some graphs, Dijkstra's algorithm will "visit" every vertex and every edge of the graph.

For more information on Dijkstra's Algorithm, visit the web overheads page.