Colors: Green = Top, Gray = Empty
Stack is a linear data structure that follows the LIFO (Last-In, First-Out) principle. Elements are added and removed from the same end, called the top of the stack.
Key Characteristics:
Operation | Time Complexity | Space Complexity |
---|---|---|
Push | O(1) | O(1) |
Pop | O(1) | O(1) |
Peek | O(1) | O(1) |
Is Empty | O(1) | O(1) |
Traversal | O(n) | O(1) |
Strengths:
Limitations: