Dijkstra routing
algorithm
presented by Biki Yeka Yader
Dijkstra algorithm overview
what why
Dijkstra’s algorithm is a link-state routing algorithm used to • Accurate Path Selection: Ensures reliable data
compute the shortest path between nodes in a network. It delivery via the most efficient routes.
helps routers determine the best route to forward packets by • Fast Convergence: Quickly adapts to topology
calculating the minimum cumulative cost (like bandwidth, changes, reducing downtime.
delay, or hop count) from the source to all other nodes. • Used in Protocols: Forms the backbone of
advanced routing protocols like OSPF (Open
Shortest Path First) and IS-IS.
how
Each router builds a complete map of the network using link-
state advertisements (LSAs). Then, it applies Dijkstra’s
algorithm to this topology to compute the shortest path tree
(SPT), updating its routing table with the best next-hop for
each destination.
Introduction to Routing algorithm
In between sending and receiving data packets from the sender to the
receiver, it will go through many routers and subnets. So as a part of
increasing the efficiency in routing the data packets and decreasing the
traffic, we must find the shortest path. One of the most commonly used
routing algorithms is Dijkstra’s algorithm.
Two main types:
• Distance-Vector Routing
• Link-State Routing (Figure 1)
• Flooding
Figure
Dijkstra is a Link-State routing algorithm. 1
What is Dijkstra algorithm?
• Solves the single-source shortest
Dijkstra’s algorithm is a popular path problem.
algorithm for solving single-source • Works only for non-negative edge
shortest path problems having non- weights.
negative edge weight in the graphs i.e., • Maintains a visited set and a
it is to find the shortest distance distance table.
between two vertices on a graph. It was • Prioritizes lowest cumulative cost
conceived by Dutch computer scientist path.
Edsger W. Dijkstra in 1956.
Working principle
1.Initialize all node distances to ∞ except the source (0).
2.Mark source as permanent.
3.For current node, update distances to adjacent nodes.
4.Select next working node: lowest tentative distance.
5.Repeat until destination becomes permanent.
6.Reconstruct path using predecessor list.
Example walkthrough
Step-by-Step Execution:
1. Initialization: Set distances: A=0, others=∞
2. Mark all nodes unvisited.
3. Set A as current node.
4. Visit Node A (min distance = 0)
- Updating neighbors B =2 and C =5
- Mark A as visited
5. Visit Node B (min distance = 2)
- Update neighbors C = 5 remains unchanged (as 6 >
5).
- Mark B as visited.
6. Visit Node C (min distance = 5)
- Update neighbor D=6(unchanged)
Final Shortest Paths:
- Mark C as visited
• A → B: Distance = 2
7. Visit Node D (min distance = 6)
• A → C: Distance = 5
- No further updates required.
• A → D: Distance = 6
- Mark D as visited.
Applications of Dijkstra Routing Algorithm
1. Network Routing:
• Used in protocols like OSPF (Open Shortest Path First) to determine the
most efficient path between routers in a computer network.
• Essential for optimizing data packet delivery.
2. GPS Navigation Systems:
• Calculates the shortest route between two locations, considering road
distances and travel times.
• Key technology behind real-time route optimization in Google Maps,
Waze, and similar applications.
3. Transportation Systems:
• Finds the optimal path for vehicles in road networks or logistics
planning.
• Enhances traffic flow management and minimizes travel costs.
Advantages Disdvantages
• Shortest Path: Guarantees finding the • Doesn't Work with Negative Weights: Fails to
shortest path. find the correct shortest paths if the graph
• Systematic: Uses a step-by-step, organized contains edges with negative weights.
approach. • Can Be Computationally Expensive: The time
• Efficient: Relatively efficient compared to complexity can be high for large graphs,
exhaustive search. especially with naive implementations.
• Versatile: Applicable to various problems • Global Knowledge Required: Requires
beyond routing. complete information about the graph, which
• Well-Understood: Widely taught and can be a challenge in distributed systems.
implemented. • May Explore Unnecessary Paths: Explores
• Adaptable: Works with different edge paths in all directions, potentially considering
weight metrics. many nodes before finding the destination.
• Supports Dynamic Routing: Can be used in
protocols that adapt to changing networks.
Dijkstra's Algorithm vs. Others
Features Dijkstra Algorithm Link-state routing Flooding Distance-vector
Routing Protocol (uses Bellman-
Type Shortest Path Algorithm Routing Protocol (uses Dijkstra) Packet Forwarding Method
Ford)
Immediate (no convergence
Convergence speed Fast (depends on implementation) Fast Slow
needed)
Simple broadcast/multicast RIP (Routing Information
Used in Link State protocols (like OSPF) OSPF, IS-IS
scenarios Protocol), IGRP
Reliability High when used in link-state protocols High Low Medium
Scalability Limited on its own Good (but memory-intensive) Poor (explosion of packets) Limited
Conclusion
• Dijkstra’s Algorithm is fundamental to modern routing — offering efficient and reliable
shortest-path computation.
• It serves as the backbone of link state routing protocols like OSPF and IS-IS, ensuring robust
path selection in dynamic networks.
• Through its deterministic and loop-free nature, it helps optimize network traffic and
performance.
• When compared with other algorithms (Flooding, Distance Vector), Dijkstra provides faster
convergence and greater accuracy — at the cost of higher overhead.
• As networks evolve, Dijkstra’s algorithm remains a key building block, influencing the
development of next-generation adaptive routing systems.
MCQs
1. What is the main purpose of Dijkstra’s
Algorithm?
a) Detect loops
b) Minimize broadcast
c) Find the shortest path
d) Encrypt data
MCQs
1. What is the main purpose of Dijkstra’s
Algorithm?
a) Detect loops
b) Minimize broadcast
c) Find the shortest path
d) Encrypt data
Answer: c)
MCQs
2. Which of the following protocols uses Dijkstra’s Algorithm?
a) RIP
b) BGP
c) OSPF
d) EIGRP
MCQs
2. Which of the following protocols uses Dijkstra’s Algorithm?
a) RIP
b) BGP
c) OSPF
d) EIGRP
Answer: c)
MCQs
3. Dijkstra's algorithm considers which factor for "shortest" path?
a) Hop count only.
b) Link cost/weight.
c) Administrative distance.
d) Maximum Transmission Unit.
MCQs
3. Dijkstra's algorithm considers which factor for "shortest" path?
a) Hop count only.
b) Link cost/weight.
c) Administrative distance.
d) Maximum Transmission Unit.
Answer: b)
MCQs
4. A key limitation of Dijkstra's algorithm is:
a) Inability to use OSPF.
b) Count-to-infinity problem.
c) Negative edge weight issue.
d) High O(V^3) complexity.
MCQs
4. A key limitation of Dijkstra's algorithm is:
a) Inability to use OSPF.
b) Count-to-infinity problem.
c) Negative edge weight issue.
d) High O(V^3) complexity.
Answer: c)
MCQs
5. How does Dijkstra's handle network topology changes?
a) Automatic recalculation.
b) Neighbor-based detection.
c) Manual intervention.
d) Switching to distance-vector.
MCQs
5. How does Dijkstra's handle network topology changes?
a) Automatic recalculation.
b) Neighbor-based detection.
c) Manual intervention.
d) Switching to distance-vector.
Answer: a)
MCQs
6. In routing, "convergence" refers to:
a) Routers agreeing on shortest paths.
b) Packet arrival time.
c) Graph conversion.
d) Algorithm iterations.
MCQs
6. In routing, "convergence" refers to:
a) Routers agreeing on shortest paths.
b) Packet arrival time.
c) Graph conversion.
d) Algorithm iterations.
Answer: a)
MCQs
7. Which of these is NOT a routing protocol?
a) Link State
b) Distance Vector
c) Flooding
d) OSPF
MCQs
7. Which of these is NOT a routing protocol?
a) Link State
b) Distance Vector
c) Flooding
d) OSPF
Answer: c)
MCQs
8. Dijkstra’s algorithm is guaranteed to produce correct results only when:
a) All edge weights are unique
b) There are no cycles in the graph
c) All edge weights are non-negative
d) The graph is directed
MCQs
8. Dijkstra’s algorithm is guaranteed to produce correct results only when:
a) All edge weights are unique
b) There are no cycles in the graph
c) All edge weights are non-negative
d) The graph is directed
Answer: c)
MCQs
9. Which of the following best describes Dijkstra’s selection strategy at each step?
a) Random node
b) First unvisited neighbor
c) Node with minimum tentative distance
d) Node with maximum outgoing edges
MCQs
9. Which of the following best describes Dijkstra’s selection strategy at each step?
a) Random node
b) First unvisited neighbor
c) Node with minimum tentative distance
d) Node with maximum outgoing edges
Answer: c)
MCQs
10. In a graph with V vertices and E edges, Dijkstra’s algorithm will:
a) Always visit all V vertices
b) Visit vertices in order of increasing shortest distance from the source
c) Use only E – 1 edges
d) Visit leaf nodes first
MCQs
10. In a graph with V vertices and E edges, Dijkstra’s algorithm will:
a) Always visit all V vertices
b) Visit vertices in order of increasing shortest distance from the source
c) Use only E – 1 edges
d) Visit leaf nodes first
Answer: b)