What is Dijikstra Algorithm?

The Dijkstra Algorithm is a widely used shortest path routing algorithm in computer networks. It finds the shortest path between nodes in a weighted graph by systematically exploring all possible routes and selecting the one with minimum cost.

In network routing, this algorithm enables packets to travel along the shortest path from source to destination. However, it has limitations as it doesn't adapt to dynamic network conditions like congestion or varying traffic loads.

How It Works

Dijkstra's algorithm maintains a set of vertices whose shortest distance from the source is known. It uses a cost matrix C[S, V] to represent the shortest path costs between nodes.

The algorithm starts by setting the cost to all nodes as infinity, except the source node which is set to zero. For each iteration, it selects the unvisited node with the smallest distance and updates the distances to its neighbors using the formula:

D[V] = min(D[V], D[S] + C(S, V))

Where D[V] is the shortest distance to node V, D[S] is the distance to current node S, and C(S, V) is the cost of the edge between S and V.

Dijkstra Algorithm Example: Finding Shortest Path from A to G A B C E F G 4 2 5 3 6 2 1 Shortest Path: A ? C ? F ? G (Total Cost: 7) Source Node Selected Path Destination

Steps of Algorithm

  1. Initialize − Set the source node distance to 0 and all other nodes to infinity. Mark all nodes as unvisited.

  2. Select current node − Choose the unvisited node with the smallest distance as the current node.

  3. Update neighbors − Calculate tentative distances to all unvisited neighbors and update if a shorter path is found.

  4. Mark as visited − Mark the current node as visited and repeat until the destination is reached or all nodes are processed.

Advantages and Disadvantages

Advantages Disadvantages
Finds optimal shortest path Doesn't adapt to traffic changes
Well-established and reliable Computationally intensive for large networks
Works with any non-negative weights May cause congestion on popular paths

Conclusion

Dijkstra's algorithm efficiently finds the shortest path in weighted networks but lacks dynamic adaptation to changing network conditions. While optimal for static routing scenarios, it may not always provide the best performance in congested networks where alternative longer paths might offer faster delivery times.

Updated on: 2026-03-16T23:36:12+05:30

846 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements