# Stacks
## Data Structures — The Codex Coding
**URL:** https://thecodex.expert/coding/data-structures/stacks/
**Type:** data-structure | **Confidence:** high | **Last verified:** 2026-06-01

## CANONICAL DEFINITION
A stack is a linear data structure that enforces last-in, first-out (LIFO) access — elements are inserted (pushed) and removed (popped) only from one end (the top) — providing O(1) push, pop, and peek.

## COMPLEXITY
- push: O(1)
- pop: O(1)
- peek: O(1)
- search: O(n)
- space: O(n)

## REQUIRES
data-structures/arrays, data-structures/linked-lists

## ENABLES
algorithms/searching

## COMMONLY CONFUSED WITH
Java Stack class is deprecated (use ArrayDeque); call stack is literally a stack data structure; Python list is a valid stack but deque is more explicit

## SOURCES
- CLRS 4th ed. §10.1
- JVM Specification §2.6
- Knuth TAOCP Vol.1 §2.2.1
- Python collections.deque docs

*The Codex Coding — thecodex.expert/coding/ — Free forever — Mumbai, India*
