{
  "schema_version": "1.0",
  "codex": "thecodex.expert/coding",
  "type": "data-structure",
  "slug": "data-structures/stacks",
  "name": "Stacks",
  "section": "Data Structures",
  "canonical_definition": "A stack is a linear data structure that enforces last-in, first-out (LIFO) access \u2014 elements are inserted (pushed) and removed (popped) only from one end (the top) \u2014 providing O(1) push, pop, and peek.",
  "complexity": {
    "push": "O(1)",
    "pop": "O(1)",
    "peek": "O(1)",
    "search": "O(n)",
    "space": "O(n)"
  },
  "confidence": "high",
  "last_verified": "2026-06-01",
  "source_count": 4,
  "url": "https://thecodex.expert/coding/data-structures/stacks/",
  "concept_relationship": {
    "requires_first": [
      "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": [
    {
      "num": 1,
      "citation": "CLRS 4th ed. \u00a710.1",
      "tier": 1
    },
    {
      "num": 2,
      "citation": "JVM Specification \u00a72.6",
      "tier": 1
    },
    {
      "num": 3,
      "citation": "Knuth TAOCP Vol.1 \u00a72.2.1",
      "tier": 1
    },
    {
      "num": 4,
      "citation": "Python collections.deque docs",
      "tier": 1
    }
  ]
}