Data Structures, Explained
You can already write code. You can loop over things, store a value in a variable, call a function. But somewhere along the way someone said "use a hash map here" or "that should be a set," and it landed like a foreign language - you nodded, picked whatever you already knew, and moved on. That works right up until the day your program crawls to a halt and you have no idea why.
Here's the secret: you don't need to memorize a textbook of exotic structures. In everyday code you reach for the same three or four containers over and over. Once you understand what each one is actually doing under the hood - not the formal definition, the working picture - choosing between them stops being a guess and becomes obvious. That's the whole goal of this guide.
We'll keep the examples in Python because it's readable, but every idea here exists in every language
(JavaScript calls a map an Object or Map, Java calls it a HashMap, and so on). The container has
different names; the mental model is identical.
How to read this
- Want it to finally make sense? Read in order - each phase builds the picture one container at a time, and the last phase ties them together into a decision you can make in seconds.
- Just need to pick one right now? Jump to Phase 3: Choosing the Right One and use the decision questions and the comparison table near the top.
The phases
- Arrays & Lists - Ordered Collections - an indexed, ordered sequence: what's cheap (grabbing item #5, adding to the end) and what quietly costs you (inserting in the middle).
- Maps & Sets - Lookup by Key - dictionaries (key → value, near-instant lookup) and sets (a bag of unique things), plus a gentle picture of the "hashing" trick that makes them fast.
- Choosing the Right One - a practical decision guide and a side-by-side table of what's fast vs slow for each, so the next time someone says "use a map" you'll already know why.
This guide stays on the containers you use daily. Deeper structures (trees, graphs, queues, stacks) and the formal math of why operations are fast - Big-O notation with proofs - live in a future performance guide. We'll point at that idea here, but only as intuition, never as homework.