Data Structures
- Lists, trees, graphs as shapesnot yet tested
- FIFO queues vs LIFO stacksnot yet tested
- Bits, bytes, CPU, RAM, storagenot yet tested
- Binary and hexadecimal encodingnot yet tested
In 1953, an IBM researcher named Hans Peter Luhn had a deceptively simple idea. Instead of hunting through a list to find something, why not compute where it should be from the thing itself? A function turns the key straight into an address, so a lookup that would have meant scanning a million entries becomes, on average, a single step. Luhn's hash table is the invention that, more than any other, separates fluent programming from clumsy programming. It belongs to a small family of organizing shapes — lists, trees, graphs, heaps, stacks, queues — that a programmer chooses among before writing a line of logic. As Niklaus Wirth put it in a title that became a slogan, Algorithms + Data Structures = Programs: the algorithm is what to do, the structure is what to do it on.
The shapes are few because each answers one question well and pays for it somewhere else. An array gives instant access to any element by its position but is slow to grow in the middle; a linked list is the exact reverse. A hash table finds things in a single average step but scatters them across memory. A tree keeps its data sorted, so that a search cuts the problem in half at every step — which is why nearly every database and filesystem is a tree underneath. A graph models anything defined by its connections: a social network, the web, a tangle of software dependencies. The lesson beneath all of them is that how the data is laid out matters more than almost any other decision a programmer makes. The same task can run a thousand times faster or slower depending only on the structure holding the data, and when a program crawls, the cure is usually not a cleverer algorithm but a better-shaped container. Two forces govern the choice. One is the old trade of speed against memory — a hash table is fast but hungry, while a leaner structure buys back space by tolerating the occasional wrong answer. The other is the hardware itself: a modern processor reads memory in a straight line about a hundred times faster than it jumps around, so a plain array will often beat a theoretically superior structure riddled with scattered pointers, whatever the abstract analysis promises.