Optimizing Network Routing
Optimizing Network Routing
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj
University of Ain Temouchent Belhadj Bouchaïb
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 1/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Plan
1 A Quick Reminder
2 Bellman-Ford Algorithm
Pseudocode
Example
Time Complexity
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 2/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Plan
3 Dijkstra Algorithm
Pseudocode
Example
Time complexity
4 Floyd-Warshall Algorithm
Pseudocode
Example
Time Complexity
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 3/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Plan
5 Comparison of Algorithms
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 4/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A Quick Reminder
Dijkstra : Shortest path from one node to all nodes,
negative edge weights not allowed.
Bellman-Ford : Shortest path from one node to all
nodes, negative edge weights allowed.
Floyd-Warshall : Shortest path between all pairs of
vertices, negative edge weights allowed.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 5/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Bellman-Ford Algorithm
The Bellman-Ford algorithm shares some characteristics with
dynamic programming, however it is more accurately described
as a relaxation-based algorithm.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 6/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Bellman-Ford Algorithm
The Bellman-Ford Algorithm is used to nd the shortest
paths from a single source vertex to all other vertices in a
weighted graph.
It can handle graphs with negative weight edges, unlike
Dijkstra's algorithm, but cannot handle negative weight
cycles.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 7/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 8/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 9/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 10/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 11/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 12/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Explanation (Cont.)
2 Step 2 : Relaxation
For each vertex, relax all the edges. This means checking
if a shorter path exists to each vertex through another
vertex and updating accordingly.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 13/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 14/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Explanation (Cont.)
2 Step 2 : Relaxation
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 15/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Explanation (Cont.)
3 Step 3 : Check for Negative-Weight Cycles
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 16/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
-1
A B
4 3
C 1 2
2
D E
-3
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 17/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
Let's nd the shortest paths from vertex A to all other vertices
using the Bellman-Ford algorithm.
1 Initialization :
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 18/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Table 1 Initialization.
Vertex Distance Predecessor
A 0 -
B ∞ -
C ∞ -
D ∞ -
E ∞ -
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 19/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 21/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
2 Relaxation :
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 22/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 23/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 24/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 25/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
2 Relaxation :
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 26/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 27/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 28/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 29/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
3 Checking for Negative-Weight Cycles :
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 30/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 31/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Time Complexity
1 The time complexity of the Bellman-Ford algorithm is
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 32/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 33/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 34/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Dijkstra's Algorithm
Dijkstra's Algorithm is a greedy algorithm used to nd
the shortest path from a single source vertex to all other
vertices in a graph with non-negative edge weights.
Unlike the Floyd-Warshall algorithm, which computes
shortest paths between all pairs of vertices, Dijkstra's
algorithm focuses on paths starting from a single source.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 35/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 36/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 37/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 38/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
10: end if
11: end for
12: end while
13: end procedure
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 39/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 40/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
10
A B
5 2 1
9
C D
3 7
4
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 41/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
The adjacency matrix :
A B C D E
A
0 10 5 ∞ ∞
B ∞ 0 ∞ 1 ∞
d =C ∞
2 0 9 3
D 0 4
∞ ∞ ∞
E ∞ ∞ ∞ 7 0
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 42/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 43/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 44/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 45/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 46/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 47/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
Let's nd the shortest paths from vertex A to all other vertices using the Dijkstra's
Algorithm :
6 Step 5 (Process D) :
The last unprocessed vertex is D with distance 8. No
neighbors to update.
Mark D as processed : S={A,C, B, E, D}.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 48/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
Final Shortest Distances from A :
A to A:0
A to B:7
A to C:5
A to D:8
A to E:8
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 49/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Remark
Order of processing D and E : We can choose either vertex in any order since
their distances are equal (8).
For any vertex in Dijkstra's algorithm, if all of its neighbors are already in the
set S (meaning they have already been processed), there is no need to update
their distances. This is because the shortest path to each of those neighbors has
already been determined when they were processed. Therefore, revisiting or
updating these neighbors would not yield any shorter paths.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 50/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Time Complexity
O(V 2 ) with an adjacency matrix
O((E + V ) log V ) using adjacency list with a min-heap
priority queue
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 51/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Floyd-Warshall Algorithm
The Floyd-Warshall Algorithm is a dynamic programming
algorithm used to nd the shortest paths between all pairs
of vertices in a weighted graph.
Unlike the Bellman-Ford algorithm, which nds the
shortest path from a single source to all other vertices,
the Floyd-Warshall algorithm computes the shortest paths
between every pair of vertices.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 52/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 53/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 54/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 55/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 56/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 57/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example
Consider the following graph with 4 vertices (1, 2, 3, 4) and weighted edges :
3
1 2
8
2 7 5 2
4 3
1
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 58/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
1 Initialisation :
1 2 3 4
1 0 3 7
∞
d = 23
8 0 2 ∞
5 0 1
∞
4 2 ∞ ∞ 0
The diagonal elements are 0, representing the distance from any vertex to itself.
Non-diagonal elements show the weights of the edges between vertices.
∞ signies that there is no edge between those vertices.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 59/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 60/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
1 2 3 4
1 0 3 7
∞
d = 23
8 0 2 15
5 8 0 1
4 2 5 ∞ 0
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 61/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
1 2 3 4
1 0 3 5 7
d = 23
8 0 2 15
5 8 0 1
4 2 5 7 0
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 62/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
3 Vertex 3 as intermediate vertex ⇒ 3rd Column and 3rd Line remain unchanged.
1 2 3 4
1 0 3 5 6
d = 23
7 0 2 3
5 8 0 1
4 2 5 7 0
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 63/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
4 Vertex 4 as intermediate vertex ⇒ 4th Column and 4th Line remain unchanged.
1 2 3 4
1 0 3 5 6
d = 23
5 0 2 3
3 6 0 1
4 2 5 7 0
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 64/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Example (Cont.)
Final Distance Matrix : After the algorithm completes, the distance matrix contains the shortest
paths between all pairs of vertices.
The nal matrix tells you the shortest distance, and we can reconstruct the path by manually
checking possible intermediate vertices that lead to the shortest distance or by using a
predecessor matrix for easier path reconstruction.
1 2 3 4
1 0 3 5 6
2
d =3
5 0 2 3
3 6 0 1
4 2 5 7 0
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 65/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm Pseudocode
Floyd-Warshall Algorithm Example
Comparison of Algorithms Time Complexity
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Time Complexity
O(V 3 ), where V is the number of vertices.
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 66/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 67/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 68/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Relaxation Process Relax all edges Relax edges based Relax all edges
up to V − 1 times on the vertex with for each vertex
the smallest distance
Handling of Negative Weights Yes No Yes
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 69/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 70/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 71/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 73/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
2
A B
1 3
C D
4
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 74/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 75/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A 0 -
B 2 B (Direct)
C 1 C (Direct)
D ∞ -
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 76/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A 2 A (Direct)
B 0 -
C ∞ -
D 3 D
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 77/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A 1 A (Direct)
B ∞ -
C 0 -
D 4 D
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 78/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A ∞ -
B 3 D
C 4 C
D 0 -
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 79/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 80/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 81/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 82/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 83/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 84/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 85/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A 2 A
B 0 -
C 3 A
D 3 D
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 86/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 87/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 88/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 89/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 90/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
A 2 A
B 0 -
C 3 A
D 3 D
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 91/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 92/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 93/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
2
A B
1 3
C D
4
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 94/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 95/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 96/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 97/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 98/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 99/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 100/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 101/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 102/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 103/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 104/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 105/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 106/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 107/108
A Quick Reminder
Bellman-Ford Algorithm
Dijkstra Algorithm
Floyd-Warshall Algorithm
Comparison of Algorithms
How Bellman-Ford algorithm is leveraged in the RIP
How OSPF uses Dijkstra's algorithm
Ali Benzerbadj Networks: Optimizing Network Routing: Bellman-Ford, Dijkstra and Floyd-Warshall 108/108