Data Structures19 sections · 729 units
Open in Course

Vocabulary - Stack

Last in, first out

A stack is a Last-In-First-Out (LIFO) data structure. Think of a stack of plates: you add plates to the top and remove plates from the top.

Three operations:

  • Push: add an element to the top
  • Pop: remove and return the top element
  • Peek (or top): view the top element without removing it

All three operations are O(1)O(1). You never access elements in the middle directly.