3.2.1 · D1Linear Data Structures

Foundations — Array — static, dynamic; cache locality; amortized O(1) append

1,895 words9 min readBack to topic

Before you can derive anything in the parent note, you need to fully own every word and symbol it throws at you. This page builds each one from nothing. Read top to bottom — each block earns the next.


1. Memory, address, and the base

Picture memory as a ruler laid flat: position 0, 1, 2, 3, … going right forever. When we say a piece of data "lives at address 1000", we mean it sits at the 1000th tick on that ruler.

Figure — Array — static, dynamic; cache locality; amortized O(1) append

Why the topic needs it: the parent's headline formula starts from . Without a fixed starting tick, "element " has no meaning — you need a place to start counting from.


2. Element size and "same type"

Picture each array element as an identical box of width ticks on the memory ruler. Same width, no gaps.

Figure — Array — static, dynamic; cache locality; amortized O(1) append

Why the topic needs it: is the step between neighbours. It appears in the address formula () and again in the cache formula ().


3. The index and counting from 0

Why the topic needs it: the range and the term "index" appear in the array definition, in arr[5], and in every trace.


4. — how many elements

Why the topic needs it: "O(1) regardless of n" is the punchline of array access. And is the yardstick every cost is measured against (O(1), O(n), O(n^2)).


5. Multiply and add → the address formula

Now that , , and exist as pictures, the parent's formula reads itself:

Figure — Array — static, dynamic; cache locality; amortized O(1) append

6. size vs capacity

Two counts that look alike but mean different things — the parent leans on both.

Picture a row of 8 reserved boxes where only the first 3 hold values: , . The 5 trailing boxes are real memory, just empty.


7. Growth factor

Why the topic needs it: whether append is O(1) amortized or O(n) amortized depends entirely on being multiplicative (, a factor) versus additive (+1, a constant). This one choice is the hinge of Section 3.


8. Big-O notation: , ,

Figure — Array — static, dynamic; cache locality; amortized O(1) append

Why the topic needs it: every claim in the parent is a Big-O claim — access , resize , bad growth .


9. Amortized cost

Why the topic needs it: " amortized append" is the parent's central, most-misunderstood claim.


10. The geometric series

Why the topic needs it: this is the engine of the amortized proof — total copy work comes straight from this sum. More at Geometric Series.


11. Cache line

Picture the memory ruler chopped into fixed 64-tick chunks; touching any tick loads its entire chunk.

Why the topic needs it: = elements per fetch is the parent's cache-locality formula. Contiguity means those neighbours are the very ones you'll read next. Background: CPU Cache and Memory Hierarchy.


Prerequisite map

Memory as numbered slots

Base address B

Element size s

addr i = B + i times s

Index i counting from 0

Count n

Big-O growth shapes

O of 1 access

size and capacity

Append operation

Growth factor g

Geometric series

Amortized cost

Cache line L

ARRAY topic

Each box on the left is defined on this page; together they feed the parent topic on the right.


Equipment checklist

You are ready for the parent note when you can answer each without peeking:

What does the base address represent?
The memory address of the array's first element (box 0).
What is the element size and why must it be constant across the array?
Bytes each element occupies; constant lets you compute box positions by multiplying instead of walking.
Starting index of an array, and why?
0 — so box sits at with no correction term.
What is ?
The number of elements currently stored; valid indices .
State the address formula and read it in words.
: start at base , skip boxes of width .
Difference between size and capacity?
size = boxes filled; capacity = boxes reserved; capacity size.
What is the growth factor and which value must it beat?
The multiplier for a new block on resize; it must be (multiplicative), e.g. 2, not additive +1.
What do , , mean as shapes?
Flat, straight line, steep upward curve of work versus .
Define amortized cost in one sentence.
Total cost over many operations divided by the number of operations, spreading rare expensive steps over cheap ones.
Value of ?
, which is less than .
What is a cache line and how many elements fit per fetch?
A ~64-byte chunk loaded at once; elements per fetch.