Structures
Eight ways to keep things, drawn so you can poke them.
1 of 8
The array
A row of numbered drawers: you can open any one at once, but a new thing near the front makes the rest move up.
- find : every one
- add : every one
- remove : every one
2 of 8
The linked list
A chain of notes, each saying where the next one is, so adding at the front is quick but reaching the end means walking.
- find : every one
- add : about the same, whatever the size
- remove : every one
3 of 8
The stack
A pile of plates where you only ever touch the top one, so every move takes a single step.
- find : about the same, whatever the size
- add : about the same, whatever the size
- remove : about the same, whatever the size
4 of 8
The queue
A line at a counter where people join at the back and leave from the front, each in two quick steps.
- find : about the same, whatever the size
- add : about the same, whatever the size
- remove : about the same, whatever the size
5 of 8
The hash table
A coat check that works out each coat's hook from the coat itself, so you can go straight to it.
- find : about the same, whatever the size
- add : about the same, whatever the size
- remove : about the same, whatever the size
6 of 8
The search tree
A guessing game made into a shape: at each number you go left for smaller and right for bigger.
- find : a few
- add : a few
- remove : a few
7 of 8
The heap
A ladder of matches where the smaller number always wins, so the smallest of all waits at the top.
- find : about the same, whatever the size
- add : a few
- remove : a few
8 of 8
The graph
A map of stations and lines, where a ripple from one station finds the shortest way to all the others.
- find : every one
- add : about the same, whatever the size
- remove : about the same, whatever the size
The dots: one is about the same, whatever the size; two is a few steps; three is every one, with 8 things inside.