Array Resizing
If implemented with an array, pushing when `top == capacity - 1` triggers a resize. A new array of size `2 * capacity` is allocated, old elements are copied over, and the old array is freed.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Instead of being bound by a fixed array size, a dynamic stack resizes itself automatically during runtime, preventing Stack Overflow errors during normal pushes.
If implemented with an array, pushing when `top == capacity - 1` triggers a resize. A new array of size `2 * capacity` is allocated, old elements are copied over, and the old array is freed.
A Linked List implementation of a stack is naturally dynamic! Every `push` allocates a new Node dynamically from the heap, and every `pop` frees it. It never "resizes" an array, but uses exactly O(N) memory at all times.
Dynamic Arrays offer better cache locality and less memory overhead per item (no next pointers), but occasionally suffer O(N) resize latency. Linked Lists have strict O(1) latency but poorer cache performance.