Tags

Shortest Path

Shortest Path

2 lessons
5 problems
1 question bank
5 community items

shortest-path

Data Structures

1 lesson

Weighted Graph Representation

Intermediate

45 min

2 prereqs

Highways have lengths in kilometers, flights have ticket prices in dollars, and network links have latencies in milliseconds. Treating any of those graphs as unweighted throws away the only information that matters for the question you actually care about (the shortest, cheapest, or fastest route), which is exactly the gap a **Weighted Graph** representation closes by attaching a number to every edge. This lesson covers three representations: a weighted adjacency list backed by arrays of `{node, weight}` pairs, a weighted adjacency matrix where `matrix[u][v]` is the edge cost (and infinity for non-edges), and a weighted edge list that stores `(u, v, weight)` triples. You will analyze the space and time trade-offs, see why Dijkstra wants the adjacency list, why Floyd-Warshall wants the matrix, and why Kruskal wants the edge list, and you will represent both directed and undirected weighted graphs correctly in each format. In **Graphs: Representation Basics**, you stored connectivity (whether an edge exists) using the same three shapes; the weighted version simply replaces a boolean or membership check with a numeric value. **Hash Map (Dictionary) Basics** is what makes the adjacency list work: a vertex maps to its neighbor-and-weight list in expected `O(1)`, the same way the unweighted version did. With weights in the picture, the algorithms track unlocks shortest-path and minimum-spanning-tree algorithms that read the weight on every edge during their core inner loop.

Not Started

0%

Weighted Graphs
Graph Representation
Adjacency List
Adjacency Matrix
Graphs
Data Structures
Intermediate
Premium
Shortest Path

Algorithms

1 lesson

Advanced Graph Algorithms (Network Flow)

Advanced

80 min

1 prereq

Two seemingly different problems, the maximum amount of water you can push from a source to a sink through a network of capacitated pipes, and the minimum total capacity you must remove to disconnect the sink from the source, turn out to have the same answer for every graph. The max-flow min-cut theorem ties them together, and once you accept it a surprising number of optimization problems (image segmentation, project selection, bipartite matching) collapse into max-flow instances. **Advanced Graph Algorithms (Network Flow)** introduces the algorithms that compute that maximum flow. You will work through the Ford-Fulkerson method built on augmenting paths and the residual graph, the BFS-based Edmonds-Karp variant with its `O(V * E^2)` guarantee, and Dinic's algorithm which uses level graphs and blocking flows to reach `O(V^2 * E)`. The lesson then turns to maximum bipartite matching (Hungarian and Hopcroft-Karp), applications like airline scheduling and image segmentation, and a first look at minimum-cost flow. In **Graph Algorithms (Advanced)**, you handled MST, all-pairs shortest paths, and SCCs on edge-weighted graphs. Network flow keeps the weighted-edge model but flips the question from "shortest" to "highest throughput." Next, **String Algorithms** turns to pattern matching, the implicit automaton of a regular expression.

Not Started

0%

Algorithms
Graphs
Network Flow
Ford-Fulkerson Algorithm
Bipartite Matching
Shortest Path
BFS
Advanced
Premium

Practice Problems

5 problems

Swim in Rising Water

Not Started
Hard

Given an n x n grid of elevations, find the minimum time t at which you can swim from the top-left to the bottom-right corner.

Graphs
BFS
Binary Search
Heap
Shortest Path
Advanced

691

15

Word Ladder

Not Started
Hard

Given a begin word, end word, and a dictionary, find the length of the shortest transformation sequence where each step changes exactly one letter.

Graphs
BFS
Shortest Path
Word Ladder
Strings
Advanced

1.1k

19

Cheapest Flights Within K Stops

Not Started
Medium

Find the cheapest price to fly from a source to a destination with at most k intermediate stops, given a list of flights with prices.

Graphs
Bellman-Ford Algorithm
BFS
Shortest Path
Weighted Graphs
Directed Graphs
Dynamic Programming
Intermediate

250

3

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

Snakes and Ladders

Not Started
Medium

Given a Snakes and Ladders board, find the minimum number of dice rolls to reach the final square from square 1.

Graphs
BFS
Shortest Path
Simulation
Intermediate

920

27

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