Dijkstra's Algorithm

Back to Algorithms
Dijkstra's Shortest Path
Dijkstra's algorithm finds the shortest path between a starting node and all other nodes in a weighted graph with non-negative edge weights.
Time Complexity (Worst)O(V^2)
Time Complexity (Average)O((V + E) log V)
Space ComplexityO(V)
Primary Data StructureMin-Priority Queue / Binary Heap

Real-World Problems We Solve

01

GPS & Map Navigation

The Problem: Finding the shortest or fastest driving route from location A to B on a physical road network.

How It Solves: Road intersections are vertices, road segments are edges, and travel times/distances are weights. Dijkstra finds the optimal sequence of turns to minimize travel cost.

Real Example: Routing engines in Google Maps, Apple Maps, or Waze calculating driving routes.
02

Network Routing Protocols (OSPF)

The Problem: Directing internet data packets through servers to reach destinations with minimal latency.

How It Solves: Routers run OSPF (Open Shortest Path First) which relies on Dijkstra to dynamically update routing tables, choosing links with the lowest delay or highest bandwidth.

Real Example: Core internet switches routing your video streaming traffic through optimal server hops.
03

Flight & Logistics Scheduling

The Problem: Finding the cheapest or fastest multi-connection flight route.

How It Solves: Airports are nodes, flights are edges with ticket prices/durations as weights. Dijkstra searches combinations to find the absolute cheapest travel path.

Real Example: Travel aggregates like Skyscanner or Expedia matching connecting flights.
04

Telecom Network Path Routing

The Problem: Assigning dedicated paths for telecommunication signals to avoid congestion.

How It Solves: Dijkstra calculates routes based on line congestion rates and signal quality degradation coefficients as edge weights.

Real Example: routing optical signals across submarine fiber cables.