Lessons · Mazes and maps
Mazes and maps: queues, stacks and graphs
Find a way from home (⌂) to school (★). Squares wait in line to be explored. Whether that line is a queue or a stack changes everything. Map apps use the same idea to plan your route.
Press play to start.
- Wall
- Waiting (number = place in line)
- Exploring now
- Already explored
- Route
Try it offline ·
- You need
- Time
Think about it
Draw your map here
Prints just this card, on one page.
Queues and stacks, everywhere
- Queue: first in, first outThe line at a shop, songs waiting to play, pages waiting at a printer. Breadth-first search uses one.
- Stack: last in, first outA pile of plates, the "undo" button, the back button in a web browser. Depth-first search uses one.
- Graph: dots and linesEach square is a dot (a node), joined to its neighbours by lines (edges). Roads, friendships and the internet are all graphs.