Skip to content

Last updated: 2026-08-08

Ch 8 · The Philosophy of Data Structure Choice ​

Stage: 第一阶 · Foundations (L5 → L4) | Pillar: Systems Thinking

Core Question ​

Which data structure should I use?

Soul Insight ​

The shape of data determines the shape of algorithms. Every data structure is a set of guarantees and a set of costs — it is intuition, not memorization. Once you internalize what each structure promises, the choice becomes obvious.

Concepts ​

StructureGuaranteesCost
ArrayO(1) random accessO(n) insert/delete
Linked listO(1) insert at headO(n) access by index
Hash tableO(1) average lookupNo ordering; collisions
BST / balanced treeO(log n) everythingPointer overhead
HeapO(1) find-min/maxO(log n) insert
GraphArbitrary relationshipsVaries by representation

Practice Anchor ​

Word frequency count — same problem, different structures, measured:

python
# 1. Sorted list: O(n log n) per lookup via binary search
# 2. Hash map: O(1) average
# 3. Trie: O(k) where k = word length — beats hash map for prefix queries

Build all three. Benchmark on 100k-word corpus. Explain the numbers.

Status ​

Existing notes have detailed algorithm content. This chapter reframes selection philosophy not mechanics.

Built as an open learning notebook