Graph
Learn what a graph is, how to store and walk one, then master the 12 graph patterns — from flood fill to Dijkstra and Tarjan — through the interview questions asked most.
- 4 Lessons
- 23 Problems
- 55 Illustrations
What you will learn
- What a graph is — vertices, edges, directed, weighted — and why maps, networks and dependencies are all graphs
- How to store a graph as an adjacency list or matrix, and how a grid is a graph in disguise
- BFS and DFS, the two ways to walk any graph, in JavaScript, Python, Java and C++
- How to spot a graph problem and pick the right pattern from its wording
- 12 patterns from easiest to hardest: flood fill, multi-source BFS, cycles, topological sort, union-find, Dijkstra, Bellman-Ford, MST, Floyd-Warshall and bridges
- The graph questions interviews ask most, each with a dry-run simulator
Why this course
Graphs are everywhere: roads between cities, friends in a network, courses that unlock other courses, pages that link to pages. Learn to see a problem as dots joined by lines and a whole family of interview questions becomes the same few moves.
The introduction is short on purpose: what a graph is, how to store it, how BFS and DFS walk it, and how to recognise a graph problem. Every later lesson builds on those four.
Then come 12 patterns, from easiest to hardest — each taught through the interview questions that use it, with code in four languages, the complexity of every approach and a simulator you can step through.
Requirements
- Comfort writing loops, conditionals, functions and recursion in at least one language
- The Queue and Stack courses help: BFS walks a graph with a queue, DFS with a stack
- For the weighted patterns (Dijkstra, Prim), the Heap course explains the priority queue they use
Course Contents
2. Pattern 1 · Traverse and count
3. Pattern 2 · Multi-source BFS
4. Pattern 3 · Start from the border
5. Pattern 4 · Cycles and two-colouring
6. Pattern 5 · Topological sort
7. Pattern 6 · Shortest path with BFS
8. Pattern 7 · Union-Find
9. Pattern 8 · Dijkstra
10. Pattern 9 · Shortest path with a limit
11. Pattern 10 · Minimum spanning tree
12. Pattern 11 · All-pairs shortest paths
13. Pattern 12 · Bridges
Related courses
- QueueFirst-in, first-out — the structure behind task scheduling and breadth-first traversal.4 lessons · 5 problems
- HeapA tree in an array that keeps the smallest (or largest) value on top — the engine behind priority queues, top-k and streaming medians.4 lessons · 14 problems
- Binary TreeHierarchical structures for representing nested relationships and enabling fast search.5 lessons · 16 problems
