Data Structure

Context: FIT1008_MOC · the physical memory layout beneath an Abstract Data Type (ADT) · the bottom rung of the abstraction ladder · archetype Array (Data Structure)

Quick Revision

  • 🎯 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) ( index access).
  • Richer behaviourpush/search/sort are algorithms layered on by an ADT, not properties of the layout.

2. Contiguous-vs-Linked Dichotomy

  • Contiguous (array) ➔ random access (address arithmetic), cache-friendly, but fixed-size + middle insert.
  • Linked (nodes) ➔ insert/delete given position, grows freely, but 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

⚖️ Core Decision Matrix

Variant / StrategyAccessInsert/delete at positionGrowthCache / Memory Impact
Contiguous (Array (Data Structure)) (shift)fixed (realloc)friendly (spatial locality)
Linked (Node/LinkList) (traverse) (relink)freehostile (pointer chasing)

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 / StatePropertyConsequence
0 (Init)
1sequential addressesindex → address is one arithmetic op
2equal-sized slots access to any element
3contiguitygood spatial locality / cache
4fixed sizegrowth ⟹ reallocation

Applied Exercise

Problem: Explain why two scans (array vs linked) differ in wall-clock time. Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: identical Big-O, very different constants — the memory hierarchy is the hidden variable.

🧠 Active Recall