Lesson 032

Stack Operations

Push · Pop · Peek

1:00

How a stack's three O(1) operations — push, pop, and peek — work, when they fail, and where they power real programs.

By the end, you can

  • Explain the LIFO property and why all access happens at the top.
  • Trace the exact state of a stack after any sequence of push, pop, and peek operations.
  • Write or explain the push, pop, and peek algorithms including their guard conditions.
  • State what `top` holds for an empty stack and derive the size from `top`.
  • Distinguish underflow from overflow and identify the correct guard for each.
  • Give the time complexity of push, pop, peek, and isEmpty, and explain why they are O(1).
  • Contrast array-backed and linked-list-backed stacks and their trade-offs.
  • Describe how the call stack, balanced-bracket checking, undo systems, and DFS each rely on the push/pop pattern.
Up next in Linear Data Structures
Questions or feedback?