Arrays & Lists

Difficulty
Importance

The problem

Most real data isn't a single value but a sequence of them — a list of users, a row of pixels, a queue of tasks. Arrays and lists give a way to store, index, and iterate over an ordered collection of values as a single unit.

Why now

Types and values gives us individual values; variables gives us a name for one value at a time. Neither explains how to hold an arbitrary, ordered many — that requires a new structure that combines indexing (a function from position to value) with contiguous or linked storage.

Mental model

An array is a function from index to value, made concrete: array[i] is exactly evaluating that function at i. Fixed-size, contiguous arrays give O(1) access because the position IS the address (a direct computation, no searching); linked lists trade that for O(1) insertion by chaining nodes instead.

Requires

Helps

Unlocks

Related

Used in

Projects

  • Implement a fixed-size array-backed stack (push/pop) and a singly linked list, then benchmark random access on each
  • Write your own map/filter/reduce from scratch using only a for-loop and an array

Examples

  • users[3] retrieves the 4th element by direct address computation — O(1), not a search
  • A linked list node { value, next } trades direct indexing for cheap insertion anywhere

Resources

Mastery checklist