Graph
Nodes and edges for modeling networks, dependencies, and paths between things.
- 1 Lesson
Dry-run engine
Breadth-First Search
A graph in memory is just an array of neighbour lists — BFS reads them level by level.
- Input · Start
- bfs(A)
- Output · Visit order
- Press play to run it
How it works
Dequeue the front node, then scan its adjacency list and enqueue every neighbour not yet visited. Marking on enqueue guarantees each node enters the queue exactly once.
adjacency_list[6]
- curr—
- Queue[A]
- Visited{A}
- Order—
The graph lives in memory as an adjacency list: one array of neighbours per node. BFS enqueues A and marks it visited at distance 0.
1 / 7
Course Contents
Related courses
- ArraysContiguous, indexable memory — the foundation almost every other data structure builds on.12 lessons · 16 problems
- StringsCharacter arrays with their own set of classic patterns — two pointers, sliding window, and more.19 lessons · 19 problems
- Linked ListNodes linked one direction by pointers instead of contiguous memory.4 lessons · 12 problems
