What a data structure actually is

A layout for data, plus the operations that layout makes cheap.

A data structure is two things at once: a layout for data in memory, and the set of operations that layout makes cheap. The second half is the one people forget, and it is the half that matters.

Take a phone book. As a plain list in the order people signed up, adding a name is instant and finding one means reading every line. Sorted by surname, adding a name means shifting everything after it, but finding one takes about twenty comparisons out of a million entries. Same data, same information — a different layout, and the costs move.

The trade is always the same shape

Every structure buys speed on some operations by paying for it on others, or by spending memory:

const list = [3, 1, 2];
list.push(4);          // cheap: write at the end
list.includes(4);      // expensive: look at every element

const set = new Set([3, 1, 2]);
set.add(4);            // cheap
set.has(4);            // cheap: hashes straight to the slot
                       // paid for with extra memory and no ordering

There is no structure that is best at everything. Choosing one is choosing which operations you want to be fast.

What this means in real code

Most performance bugs in application code are not exotic algorithmic failures. They are a find inside a loop over an array that should have been a map lookup — an accidental quadratic, written by someone who reached for the first structure that came to mind.

The skill this course builds is not memorising implementations. It is looking at a problem, naming the operations it performs most, and picking the structure whose costs match.

Before the next lesson

Open something you have written recently and find one loop that searches a list. Ask what structure would have turned that search into a single step.