Chapter 1 of 10All chapters
Chapter 1 of 10
Why structure matters
The same data, very different costs.
Choose by operation
Every structure is fast at some operations and slow at others. Picking one means deciding which operations you do most: lookup, insert, delete, or walking in order.
- Ask what the code does a thousand times, not what looks tidy.
- Changing the structure often beats optimising the algorithm around a bad one.
Memory counts
Two structures with identical complexity can differ tenfold in practice, because contiguous memory suits how processors read ahead. Arrays beat linked lists far more often than the theory suggests.