# Heaps
**URL:** https://thecodex.expert/coding/data-structures/heaps/
**Type:** data-structure | **Confidence:** high | **Verified:** 2026-06-01

## CANONICAL DEFINITION
A heap is a complete binary tree stored as an array satisfying the heap property — each node >= its children (max-heap) or <= (min-heap) — providing O(1) find-max and O(log n) insert and extract.

## COMPLEXITY
- find_max: O(1)
- insert: O(log n)
- extract_max: O(log n)
- build_heap: O(n)
- space: O(n)

## REQUIRES
data-structures/arrays, concepts/recursion

## ENABLES
algorithms/sorting/heapsort

## SOURCES
- CLRS 4th ed. Ch.6
- Williams 1964 CACM 7(6)
- Fredman & Tarjan 1987 JACM 34(3)
- Python heapq docs

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