â 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â