Using Dijkstra's Algorithm to Find The Shortest Path

The Problem We Want to Solve:

Say we want to find the fastest time to get from airport A to every other airport (B,C,etc.), or the cheapest way or using the least amount of fuel etc. We can represent all of the different airports as nodes of a graph and the routes between them as the weighted edges. We then want to find the shortest (i.e. lowest-cost) path in the weighted graph from the start node (Airport A) to every other node. So how do we do this? We use Dijkstra's Algorithm.

Dijkstra's Algorithm is the fastest shortest start algorithm with single starts for both directed and undirected weigthed graphs with edge weights that are non-negative and unbounded. So how does it work?

The Algorithm

  1. Create a priority queue
  2. Insert the starting node with cost 0
  3. Then, do the following while the priority queue is not empty:
    1. Remove the array with the lowest weight(highest priority) and if the destination is unvisited then:
    2. Mark the destination node as visited and store the previous node and cost
    3. For each edge from the node, add the array [current node, destination node, cost/weight] to the priority queue

An Example

TODO

Further Reading On Wikipedia