← Lab

ðŸ§ą Array — capacity, size, amortized growth

A dynamic array is a fixed capacity buffer + a size. push is O(1) until full, then it doubles and copies (O(n)) — amortized O(1). Watch the buffer grow.

capacity
4
size
3
load
0.75
wasted slots
1
buffer[4] — filled + spare capacity
3
0
1
1
4
2
3
what just happened (say it out loud)

Run an operation to see it step by step.

ė‚Žėƒ: a dynamic array is contiguous memory, so index access is O(1) pointer math; growth costs an O(n) copy but doubling makes it amortized O(1). It doesn't shrink on pop.
â–ķ deep-dive videos — “dynamic array amortized analysis resize”