Dijkstra's shortest path algorithm

We introduce and study Dijkstra's algorithm. This algorithm is an example of a greedy algorithm. It finds the shortest distance from a source to all other nodes or vertices in a graph. By the end of this section, you will come to understand why it is classified as a greedy algorithm.

Consider the following graph:

By inspection, the first answer to the question of finding the shortest path between node A and node D that comes to mind is the edge with value or distance 9. From the diagram, it would seem that the straight path from node A to D would also yield the shortest route between the two nodes. But the ...

Get Python Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.