* Shortest paths in weighted graphs
- the problem is fundamentally different than the one corresponding to the
undirected graphs
- weights many times can be thought of as lengths: distances in a road
network, travel times for the Internet packets, strength of ties in social
networks
* Dijkstra's algorithm
- finds the shortest distance from a source vertex to all other vertices
- we assume that all the edge lengths are strictly positive (the total
distance can be reduced arbitrarily when edge weights are negative, and
a loop with negative edge weights exists along the path)
- works by keeping a record of the shortest distance found so far to each
vertex, and updating that record whenever a shorter one is found.
- Description:
We create 2 arrays with n elements: the first holds our current
estimates of the distances from s to every vertex, while the second
array we record which of these estimates are certainly true. Thus, at
all times, our estimates are upper bounds to the actual shortest
distances.
Initially, we set all distances to infinity except for the source
vertex s, for which we record 0. Also, all the distances are marked
uncertain initially. Then the following steps are performed:
1. find a vertex v that has the smallest estimated distance from those
vertices for which we are not sure
2. mark this distance as sure
3. calculate the distance from s to each neighbor of v by adding the
distance to v the edge length between v and the neighbour. If this
distance is smaller than the previous estimate for the neighbour,
replace it with the new estimate
4. repeat from 1
* Applications
- The Internet
- GPS navigation
* Running time of Dijkstra's algorithm
- O(m + n^2)
* Heap
- binary tree
- binary heap