Tags

Dijkstra's Algorithm

Dijkstra's Algorithm

1 lesson
1 problem
2 code snippets
1 question bank
1 system design
2 community items

dijkstra

Algorithms

1 lesson

Graph Algorithms (Core)

Intermediate

75 min

2 prereqs

Webpack figures out the order to compile your modules using topological sort. Google Maps figures out the route to your destination using Dijkstra. Your CI system rejects circular imports using cycle detection. The same handful of graph algorithms power an enormous slice of real infrastructure, and almost all of them are short additions to a BFS or DFS skeleton you already wrote. **Graph Algorithms (Core)** covers that handful in detail. You will implement topological sort in two ways (Kahn's BFS-with-in-degree algorithm and the DFS-reverse-postorder algorithm), cycle detection on undirected graphs (DFS with parent tracking) and on directed graphs (DFS with white/gray/black coloring), Dijkstra's shortest-path algorithm with a min-heap and the relaxation invariant that makes it work, connected-component counting via DFS or Union-Find, and bipartite checking via two-color BFS. Along the way you will see why Dijkstra fails on negative edge weights, which motivates Bellman-Ford in the advanced lesson later. In **BFS & DFS (Intro)**, you wrote the two traversal skeletons. **Weighted Graph Representation** gave you the adjacency-list-of-tuples format that Dijkstra and friends actually consume. This lesson is where those primitives turn into named algorithms with clear use cases. From here, **Greedy (Intro)** introduces a different paradigm: instead of exploring every option, commit to the locally best choice at each step.

Not Started

0%

Algorithms
Graphs
Topological Sort
Cycle Detection
Dijkstra's Algorithm
Connected Components
Bipartite Check
Intermediate
Premium

Practice Problems

1 problem

Network Delay Time

Not Started
Medium

Given a network of n nodes and weighted directed edges representing signal travel times, find the time it takes for a signal sent from node k to reach all nodes.

Graphs
Dijkstra's Algorithm
Shortest Path
Weighted Graphs
Directed Graphs
Heap
Intermediate

1k

24

Code Snippets

2 snippets
Code Snippet
Premium

Dijkstra Shortest Path Template

Dijkstra's algorithm finds the shortest path from a source to every reachable node in a weighted graph with non-negative edge weights. The textbook O((V + E) log V) implementation pairs a min-heap with a relaxation loop. This snippet covers the heap-based template, a parent-tracking variant that reconstructs the actual path, and an early-exit form for single-target queries.

JavaScript
algorithms
dijkstra
code-template
heap

1.1k

17

Hard
Code Snippet
Premium

Dijkstra in Python with heapq

Dijkstra finds the shortest path in a weighted graph with non-negative edge weights. The Python idiom is `heapq` (a binary min-heap) plus a distance dict, which gives O((V + E) log V) without external libraries. This entry covers the standard single-source template, path reconstruction, and the early-exit shortest-path-to-one-target variant.

Python
dijkstra
graph-algorithms
min-heap
algorithms

674

16

Hard

Question Banks

1 item
Question Bank
Premium

Dijkstra and Shortest Paths

Decide between Dijkstra, Bellman-Ford, and 0/1 BFS, and trace Dijkstra on a small weighted graph. Code stems are Python.

Python
dijkstra
shortest-path
bellman-ford
algorithms

952

18

Hard

System Design

1 article
System Design
Premium

Design Google Maps

Design Google Maps: a global mapping service that renders the Earth from 256x256 tiles, computes the shortest driving route in under 200 ms, and folds live traffic into routing for 1B users issuing 5B route requests per day. The interview centerpiece is the routing engine: how Dijkstra is too slow on a continent-scale graph and how Contraction Hierarchies (CH) precompute shortcuts so the live query is logarithmic. We cover the tile pyramid (zoom 0-20, ~1 trillion possible tiles at zoom 20), how live traffic from 100M Android phones updates edge weights every minute, and how to keep navigation latency under 1 second when re-routing.

design-google-maps
case-study
ride-sharing-and-maps
google-maps
graph-algorithms
dijkstra
a-star
contraction-hierarchies
routing-engine
map-tiles
tile-rendering
real-time-traffic
cdn
geospatial
h3-hex-grid
system-design
advanced
premium

584

10

Hard