Stack (LIFO)

Last In First Out (LIFO) - Elements are added and removed from the top

Max:
Speed:
Element
Top
New/Rear

Push (Add to Top)

Add element to top - O(1)

Pop (Remove from Top)

Remove and return top element - O(1)

Peek (View Top)

View top element without removing - O(1)

Query Operations

About Stack

LIFO Principle: Last In, First Out - the most recently added element is removed first.

Time Complexity:

  • Push: O(1)
  • Pop: O(1)
  • Peek: O(1)

Use Cases: Function call stack, undo/redo, expression evaluation, backtracking