- Classic view: Introduction to Algorithms
-
Initialize Single Source (G,s)
G ={V,E} is the graph
s is the source, one vertex.
- for each vertex v ∈ V[G]
- d[v]= ∞
- π[v] = NIL
- d[s] = 0
- The π array will contain pointers back to the source.
- The d array is the distance from the source.
-
Relax(u,v,w) {
if d[v] > d[u] + w[u,v]
d[v] = d[u] + w[u,v]
π[v] = u
}
- This routine will check to see if the current path is cheaper than
an existing path.
- If so, it will change the current path.
- The algorithm
Dijkstra(G,w,s)
G is the graph
w is a weight function
s is the starting point.
- Initialize Single Source(G,s)
- Q.enqueue(V[G])
- while !Q.empty() do
- u = Q.ExtractMin();
- foreach vertex v adjacent to u
- Relax(u,v,w);
- Q is a data structure which it is quick to extract the minimum
cost element.
- This is most likely a heap.
- This can be done in O(lg(n)) time, where n is the number of items in the heap.
- So the entire thing is O(VlgV + E)
- Kurose gives the following distributed version
Link State at node u
Initialization:
- N' = {u}
- for all nodes v
- v is a neighbor of u
- d[v] = w(u,v)
- else
- d[v] = ∞
Operation:
- Loop
- find w not in N' such that D(w) is a minimum
- add w to N'
- update d(v) for each neighbor v of x not in N'
- d(v) = min(d[v], d(x) + w(x,v))
- Until N = N'
- N is somehow a list of all nodes in the network.
- A link is determined using a reachability protocol
- The other nodes in the network can be found via Link-state advisement.
- This is pare of OSPF which we will discuss later.
- The network is flooded from each node.
- This flood includes adjacency list and a metric for each link.
- This occurs periodically
- And when a link changes (goes up or down)
- This is tremendously simplified.