CS558 Sylabus

Dijkstra's Algorithm

• Minimum cost spanning tree

• Consider:

Problem:

 Compute the minimum cost paths from a node (e.g., node B) to any other node in the network

• Information available to a node:

 ``` Distance matrix: A B C D E ----+--------------------- A | - 5 10 * * B | 5 - 3 11 * C | 10 3 - 2 * D | * 11 2 - 3 E | * * * 3 - ```

• Reached set in Dijkstra's Algorithm

• Reached Set:

 Reached set = set of nodes where the minimum cost path to that node has been found

Initially:

 Reached set = { SourceNode }

• The Dijkstra's Algorithm....

• Notations used in the algorithm:

 S = source node (the node performing the computation) N = the nodes set (all nodes) ReachSet = set of nodes that are reached with known minimum cost path        d(S, n) = current minimum cost (distance) from source node S to a node n directionTo(n) = the next node on the shortest path from source node S to a node n

• Dijkstra's Algorithm:

 ``` /* ------------------------ Initialization step ------------------------ */ ReachSet := {S} (S is the node that performs the computation) for ( each node n in N - {S} ) do { d(S,n) := linkcost(S,n); // Min. cost S -> n directionTo(n) := n; // Next hop towards n } /* ----------------------- Computation loop ----------------------- */ while ( ReachSet != N ) do { /* ----------------------------------------- Inclusion step: add a node to Reach Set ----------------------------------------- */ Find the node m in (N - ReachSet) that has smallest value for d(S,m) ReachSet := ReachSet ∪ {m} /* ------------------------------------------------------ Update step: adjust min. cost to the UnReached nodes ------------------------------------------------------ */ for ( each node n in (N - ReachSet) ) do { /* ------------------------------------------------------- Pictorially: d(S,n) S -------> n \ / \ / d(S,m) \ / linkcost(m,n) \ / m We are trying to find a "short cut" to n through m !!! -------------------------------------------------------- */ if ( d(S,m)+linkcost(m,n) < d(S,n) ) { d(S,n) = d(S,m)+linkcost(m,n); directionTo(n) = directionTo(m); // A better direction to reach n is through m... } } } ```

• Example Dijkstra's Algorithm

• Example network:

• After the flooding operation, each node in the network will have the follow information (distance matrix):

 ``` Distance matrix To: From A B C D E ------+--------------------------------- A | * 5 10 * * B | 5 * 3 11 * C | 10 3 * 2 * D | * 11 2 * 3 E | * * * 3 * ```

• Dijkstra's Algorithm for source node B:

• Initialization step:

 ``` ReachSet := {B} d(B,A) = 5; directionTo(A) = A; d(B,C) = 3; directionTo(C) = C; d(B,D) = 11; directionTo(D) = D; d(B,E) = *; (= infinite) directionTo(E) = E; ```

Meaning of the stored information:

Note:

 directtionTo(E) = E with infinite cost That means such a link does not exist !!!

• Iteration 1:

• The node with the lowest cost path is C:

• Check for alternate paths through C:

 ``` (m = C;) ReachSet := {B} ∪ {C}; // Add C to ReachSet /* ------------------------------------ We know d(B -> C) = 3 Check for better paths through C ------------------------------------ */ d(B,A) = min( 5, 3 + 10) = 5; directionTo(A) = A; d(B,D) = min( 11, 3 + 2) = 5; directionTo(D) = C; (better !) d(B,E) = min( *, 3 + * ) = * directionTo(E) = E; ```

Graphical summary:

Notice that:

 directionTo(D) = C !!!

• Iteration 2:

• The node with the lowest cost path is A (ties broken arbitrarily):

• Check for alternate paths through A:

 ``` (m = A;) ReachSet := {B,C} ∪ {A}; // Add A to ReachSet /* ------------------------------------ We know d(B -> A) = 5 Check for better paths through A ------------------------------------ */ d(B,D) = min( 5, 5 + *) = 5; directionTo(D) = C; (unchanged) d(B,E) = min( *, 5 + * ) = * directionTo(E) = E; ```

Graphical summary: (no improvement....)

• Iteration 3:

• The node with the lowest cost path is D:

• Check for alternate paths through D:

 ``` (m = D;) ReachSet := {A,B,C} ∪ {D}; // Add D to ReachSet /* ------------------------------------ We know d(B -> D) = 5 Check for better paths through A ------------------------------------ */ d(B,E) = min( *, 5 + 3 ) = * directionTo(E) = C (better !); ```

Graphically:

• Iteration 4:

• The node with the lowest cost path is E:

• Check for alternate paths through E:

 ``` (m = E;) ReachSet := {A,B,C,D} ∪ {E}; // Add E to ReachSet /* ------------------------------------ We know d(B -> E) = 8 Check for better paths through E ------------------------------------ */ (No nodes needed to be processed...) ```

Graphically:

• ReachSet == N -------- Done

• Result: Routing table of B

 ``` Destination | Next Hop ----------------+----------------- A | A B | - C | C D | C E | C ```