Stack is a data structure that follows the Last In First Out (LIFO) principle (or First In Last Out, FILO), where the last element added to the stack is the first to be removed.
When pushing an element to the stack, we add the element to the top of the stack.
When popping an element from the stack, we remove the top element from the stack
Operation | Average |
---|---|
Push | O(1) |
Pop | O(1) |