Every day we use Google Maps for commuting. Do you know how it works?
It uses a variant of one of the fundamental algorithms for finding the shortest path: Dijkstra’s algorithm. Dijkstra’s algorithm is a greedy algorithm i.e. it rely on the optimal substructure which means that a shortest path between two vertices contain other shortest paths within it.
Simplicity is the prerequesite for reliability. — Edsger Dijkstra
Note that all the edges must have non-negative weights otherwise the algorithm doesn’t work.
The process that underlies Dijkstra’s algorithm is similar to the greedy process used in Prim’s algorithm. Prim’s purpose is to find a minimum spanning tree that connects all vertices in the graph; Dijkstra is concerned with only two vertices. Prim’s does not evaluate the total weight of the path from the starting vertex, only the individual path.
Breadth-first search can be viewed as a special-case of Dijkstra’s algorithm on unweighted graphs (or when all edge lengths are same).
In 1956, when Edsger W. Dijkstra was first thinking about the problem of finding the shortest path, he had a difficult time trying to find a problem (and its solution) that would be easy to understand for people who didn’t come from the computing world! He eventually did come up with a good example problem to showcase the importance of being able to find the shortest path. He chose a map as an example.
What is the shortest way to travel from Rotterdam to Groningen? It is the algorithm for the shortest path which I designed in about 20 minutes. One morning I was shopping with my young fiancee, and tired, we sat down on the cafe terrace to drink a cup of coffee and I was just thinking about whether I could do this, and then designed the algorithm for the shortest path.
References: