List representations
Introduction / Definition
Lists can be represented by arrays or linked nodes. Arrays provide fast indexed access and good locality. Linked lists provide flexible node insertion when a node location is known. The representation affects complexity and memory usage.
Syntax / Structure / Formula
Array: [a0,a1,...]; Linked: Node(value,next)
Detailed Explanation
Array-based lists use contiguous storage, while linked lists connect nodes through references. The abstract list interface can hide this difference.
Example
Example: ArrayList is convenient for frequent indexed reads.
Output / Result
Index access is typically O(1) for an array-backed list.
Important Points / Notes
- Array access is typically O(1).
- Linked traversal to position i is O(n).
Mini Practice Question
Which representation suits frequent random access?