60 likes | 183 Views
Learn about Dijkstra's shortest path algorithm for link-state routing, with examples and spanning tree computation, offering insights into routing table generation and algorithm complexity.
E N D
Dijkstra’s Shortest Path Algorithm Gordon College
Notation: c(i,j): link cost from node i to j. cost infinite if not direct neighbors D(v): current value of cost of path from source to dest. V p(v): predecessor node along path from source to v, that is next v N: set of nodes already in spanning tree (least cost path known) A D E B F C A Link-State Routing Algorithm Examples: • c(B,C) = 3 • D(E) = 2 • p(B) = A • N = { A, B, D, E } 5 3 5 2 2 1 3 1 2 1
Dijsktra’s Algorithm 1 Initialization: 2 N = {A} 3 for all nodes v 4 if v adjacent to A 5 then D(v) = c(A,v) 6 else D(v) = infinity 7 8 Loop 9 find w not in N such that D(w) is a minimum 10 add w to N 11 update D(v) for all v adjacent to w and not in N: 12 D(v) = min( D(v), D(w) + c(w,v) ) 13 /* new cost to v is either old cost to v or known 14 shortest path cost to w plus cost from w to v */ 15 until all nodes in N
2,A 5,A 1,A infinity,- infinity,- A 2,A 4,D1,A2,D infinity,- AD 2,A 3,E1,A2,D4,E ADE 2,A 3,E 1,A2,D 4,E ADEB 2,A3,E1,A2,D 4,E ADEBC 2,A3,E1,A2,D4,E ADEBCF A D B E F C Dijkstra’s algorithm: example D(B),p(B) D(D),p(D) D(C),p(C) D(E),p(E) Step 0 1 2 3 4 5 N D(F),p(F) 5 3 5 2 2 1 3 1 2 1
2,A3,E1,A2,D4,E ADEBCF A D B E F C Spanning tree gives routing table D(B),p(B) D(D),p(D) D(C),p(C) D(E),p(E) Step N D(F),p(F) Result fromDijkstra’s algorithm B,2 D,3 D,1 D,2 D,4 B C D E F Outgoing link to use, cost Routing table: 5 3 5 2 2 1 3 1 2 1 destination
Algorithm complexity (n nodes and l links) Computation n iterations each iteration: need to check all nodes, w, not in N n*(n+1)/2 comparisons: O(n2) more efficient implementations possible: O(n log n) Messages network topology and link cost known to all nodes each node broadcasts its direct link cost O(l) messages per broadcast announcement O(n l) Dijkstra’s algorithm performance