Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Dijkstra’s Shortest Path Algorithm Gordon College.

Similar presentations


Presentation on theme: "1 Dijkstra’s Shortest Path Algorithm Gordon College."— Presentation transcript:

1 1 Dijkstra’s Shortest Path Algorithm Gordon College

2 2 A Link-State Routing Algorithm 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 E D CB F 2 2 1 3 1 1 2 5 3 5 Examples: c(B,C) = 3 D(E) = 2 p(B) = A N = { A, B, D, E }

3 3 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

4 4 Dijkstra’s algorithm: example Step 0 1 2 3 4 5 N D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F) 2 2 1 3 1 1 2 5 3 5 A 2,A 5,A 1,A infinity,- infinity,- AD 2,A 4,D 1,A 2,D infinity,- ADE 2,A 3,E 1,A 2,D 4,E ADEB 2,A 3,E 1,A 2,D 4,E ADEBC 2,A 3,E 1,A 2,D 4,E ADEBCF 2,A 3,E 1,A 2,D 4,E E D CB F A

5 5 Spanning tree gives routing table BCDEF BCDEF B,2 D,3 D,1 D,2 D,4 Outgoing link to use, cost destination Result from Dijkstra’s algorithm Routing table: Step N D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F) ADEBCF 2,A 3,E 1,A 2,D 4,E 2 2 1 3 1 1 2 5 3 5 E D CB F A

6 6 Dijkstra’s algorithm performance 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(n 2 ) –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)


Download ppt "1 Dijkstra’s Shortest Path Algorithm Gordon College."

Similar presentations


Ads by Google