🎯 Objective: physical organisation of data in memory ➔ where the bytes sit; its one intrinsic operation is access.
📦 Core Components:contiguous (array) vs linked (Node/LinkList) — opposite strengths.
⚡ Key Constraint: same ADT on different layouts differs in constants + cache locality even at identical Big-O.
📝 Core
1. The Data Structure (Layout, Access)
Definition ➔ physical organisation of data in memory — about layout, not meaning.
One operation ➔ intrinsic op is access; prototype = Array (Data Structure) (O(1) index access).
Richer behaviour ➔ push/search/sort are algorithms layered on by an ADT, not properties of the layout.
2. Contiguous-vs-Linked Dichotomy
Contiguous (array) ➔ O(1) random access (address arithmetic), cache-friendly, but fixed-size + O(n) middle insert.
Linked (nodes) ➔ O(1) insert/delete given position, grows freely, but O(n) access + cache-hostile.
Inheritance ➔ higher structures inherit this (array vs linked Stack (ADT); open-addressing vs chaining Hash Table).
⚙️ Core Implementation
🔹 The native access operation
O(1) array access by address arithmetic
element = array[2] # address = base + 2 * slot_size -> O(1), the native op
💡 Common Mistake:Cache locality is a first-order cost the RAM model hides ➔ a contiguous scan and a linked scan can both be O(n) yet differ by an order of magnitude (each cache miss ~100× a hit) — see RAM model.
When It Flips: layout ≠ ADT — the same ADT on different structures differs in real-world performance even at identical Big-O (cache + constants). Trees/graphs extend the linked layout to multi-child pointer nodes.
📊 Exam Execution Trace
Manual Execution Trace
Array index → address consequences:
Step / State
Property
Consequence
0 (Init)
—
—
1
sequential addresses
index → address is one arithmetic op
2
equal-sized slots
O(1) access to any element
3
contiguity
good spatial locality / cache
4
fixed size
growth ⟹ reallocation
Applied Exercise
Problem: Explain why two O(n) scans (array vs linked) differ in wall-clock time.
Derivation Proof / Hand-Calculation Walkthrough:
array scanlinked scan∴same O(n):sequential cache lines⇒few misses:pointers scattered⇒many misses(∼100× each),order-of-magnitude wall-clock gap (hidden by RAM model)
Final Extracted Output: identical Big-O, very different constants — the memory hierarchy is the hidden variable.
🧠 Active Recall
Contrast contiguous and linked data structures across access, insertion, and cache behaviour.