TOPIC

Arrays

Contiguous memory: O(1) access, but inserts/deletes shift neighbours.

WHY DID WE NEED ARRAYS?

THE WALLA program with only single variables (x, y, z…) cannot hold a THOUSAND marks or a MILLION pixels — you can't name a box per value.

THE IDEAPut values in one contiguous block and reach any of them by INDEX: address = base + i × size. One name, n values, O(1) access to any of them.

A row of numbered lockers: locker #42 is one step away, but adding a locker in the middle means shifting every locker after it.

Choose a category