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.
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)
Time Complexity Analysis
Practical Example
Consider a stack with maximum capacity of 3 elements:
Stack: [ ]
isFull() → false
Stack: [5, 3]
isFull() → false
Stack: [7, 3, 5]
isFull() → true
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.