Codele / Data structures
Choosing the right structure
You now know many ways to keep data. Pick what you need, and watch a short chain of questions lead to the structure that fits.
- Start with the need, not the structure: how will the data be added, found and taken out?
- By name: a dictionary. Newest first: a stack. Oldest first: a queue. Most urgent first: a heap.
- Sorted and fast to search: a binary search tree. Each thing only once: a set.
- A plain list works for small jobs, but it must check every item to find one, so it slows as data grows.
- Ask “what is the one thing I do most?” The answer usually points to the right structure.
Loading the playable lesson…