What is the "Is Full" Operation?
isFull tells you whether a stack has run out of room to accept another push. It only really matters for a fixed-capacity stack like an array-backed one; a linked-list stack can just keep allocating nodes, so it rarely needs this check.
How It Works
- Returns true if the stack cannot accept more elements.
- Returns false if the stack can accept more elements.
- For dynamic stacks (no fixed size), this operation typically always returns false.
- Often used with Push operations to prevent stack overflow.
Consider a stack with a maximum capacity of 3 elements. The dashed outlines are the slots still free — isFull() is just asking whether any are left:
Empty — two slots free, so a push is safe
Partly filled — one slot still free
Every slot taken — the next push would overflow
Note that the check never looks at the values themselves — it only compares the size against the capacity, which is why it costs O(1) no matter how large the stack is. A dynamic stack has no fixed capacity to compare against, so its isFull() simply always returns false.
Time and Space Complexity
Here's the time and space complexity analysis for stack operations:
- Fixed-size Stack:
- Time Complexity: O(1)
- Space Complexity: O(1)
- Dynamic Stack:
- Time Complexity: O(1)
- Space Complexity: O(1)
Common Use Cases
- Preventing stack overflow in memory-constrained systems.
- Implementing bounded buffers or fixed-size caches.
- Memory management in embedded systems.
- Validating stack capacity before push operations
The Is Full operation is crucial when working with fixed-size stacks to prevent overflow errors. While not needed for dynamically-sized stacks, it's an essential safety check in many system-level implementations.