/ THE IDEA
An address is a number identifying a memory location. In a fixed-entry-size array, the location of entry i is the starting location plus i times the entry size. The first entry is numbered zero in our example. No earlier entries must be read to calculate the address of a later one. A singly linked list has records called nodes, each holding a value and the address of the next node. Knowing the first node does not reveal where the tenth is stored. You must follow the chain. Once a particular node is already known, inserting immediately after it can change a few links without shifting every later value.
THE FORMAL IDEA
array address(i) = base + i×s
| Addresses count bytes here; base = address of the first entry; i = zero-based entry number; s = bytes per entry; a byte is a unit of stored data, here eight choices each read as 0 or 1. | | A linked list has no corresponding direct-address formula from i alone. Its next-node addresses supply the route one step at a time. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Toy array: base = 1000; s = 4 bytes. Entry 3 starts at 1000+3×4 = 1012. Toy linked list: node 0 → node 1 → node 2 → node 3 requires three link follows from the first node. Change only the requested entry to 7: array address = 1028. The linked-list route now needs seven link follows, even though the position calculation for the array stays short.
|
The numbers are invented memory labels, not addresses to inspect. The changed position lengthened the linked route but did not require reading the array’s earlier entries. This is the structural reason for different access costs, independent of the playlist’s visual appearance.
/ SO WHAT?
Insertion changes the comparison. Inserting a new first entry in a packed array may require moving the existing entries to make room. A linked list can create a new head node pointing at the old head. However, “insert quickly” assumes you already know the insertion point; finding a position can consume the very traversal time the slogan leaves out.
ONE CAVEAT |
| Real dynamic arrays reserve extra capacity, and arrays can store addresses rather than the full objects. Memory layout and caching affect stopwatch time. This comparison concerns basic packed arrays and singly linked nodes, not every language’s object named “list”. |
KEEP THIS
Arrays calculate a position directly; linked lists reach a position through connections, trading easy jumps for flexible local rearrangement.
|
NEXT: Why a falling object can stop speeding up
|