Graphs, heaps and intervals
Graph search on grids and networks, topological ordering, heaps for top-k and running medians, and sorting-based interval problems.
About 5 hours of study
Learning objectives
- Choose between DFS, BFS and topological sort
- Keep the k best items with a heap
- Merge intervals and count overlaps
Lessons
- 1
Graph patterns
Grids are graphs: counting islands with DFS or BFS, shortest paths in unweighted graphs with BFS, and ordering tasks with topological sort.
- 2
Heaps and intervals
Top-k problems with a heap (heapq), merging overlapping intervals after sorting, and counting meeting rooms by sweeping start and end times.
Module practice
- Connected groupsEasy
- Number of islandsMedium
- Course scheduleHard
- The k-th largest numberEasy
- Meeting roomsMedium
- Merge intervalsMedium
- Running medianHard
Module quiz
‹ Linked lists and treesDynamic programming, backtracking and the mock interview ›