Node

Context: FIT1008_MOC · the atomic unit of a Linked Node Data Structure · used by LinkList · generalises to Binary Tree/graphs

Quick Revision

  • 🎯 Objective: hold one item + a link to the next node ➔ the building block of non-contiguous chains.
  • 📦 Core Components: singly / doubly / circular / XOR variants ➔ item ref + link refs.
  • ⚡ Key Constraint: create/splice at a held node, but to reach index (no random access) + pointer overhead.

📝 Core

  • Compositionone item + a link to the next node ➔ chaining builds a list ending in None.
  • Enables ➔ a Linked Node Data Structure — no contiguous block like an Array (Data Structure).
  • GeneralisesBinary Tree (two links), graphs (many links); reaching node is , no base + i*size arithmetic.

2. Node Variants

  • Singly ➔ one forward link ➔ minimal memory, no backward walk, predecessor.
  • Doublyprev+next delete-given-node + backward walk, extra pointer.
  • Circular ➔ last→head ➔ round-robin iteration.
  • XORprev XOR next in one field ➔ space hack that breaks GC.
  • Cost per node ➔ 1 item ref + link refs ➔ heavy for tiny payloads; scattered allocation hurts cache locality.

⚙️ Core Implementation

🔹 Node and a chain

⚖️ Core Decision Matrix

VariantLinksBuysCosts
Singlynextminimal memoryno backward walk, predecessor
Doublyprev+next delete-given-node, bidirectionalextra pointer, double updates
Circularlast→headround-robin iterationtermination care
node vs array slotpointerflexible growth, splice access, poor cache

When It Flips: splice/relink at a held node vs to reach an arbitrary position, plus per-node pointer overhead and poor locality — arrays win on access + cache, nodes win on growth + splicing.

📊 Exam Execution Trace

Manual Execution Trace

Reaching the 3rd node (index 2):

Step / StateCurrentHop cost
0 (Init)head (item 1)
1head.link (item 2)
2head.link.link (item 3)
totalindex 2

Applied Exercise

Problem: Show why index access is , not . Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: no address arithmetic ⟹ traversal is the only route ⟹ — also why Binary Search can’t run on a linked list.

🧠 Active Recall