Binary Heap & Priority Queue
A binary heap stores a complete binary tree compactly in a flat 0-indexed array with zero pointers, supporting O(1) min/max peek, O(log n) push/extract, and O(n) bottom-up Floyd heapify.
Technical Reference & Equations
- 0-Indexed Array Navigation:
\mathrm{parent}(i) = \left\lfloor \frac{i - 1}{2} \right\rfloor, \quad \mathrm{left}(i) = 2i + 1, \quad \mathrm{right}(i) = 2i + 2(Eliminates pointer overhead while preserving spatial cache locality.) - Heap Order Invariant:
A[\mathrm{parent}(i)] \le A[i] \;(\text{Min-Heap}), \quad A[\mathrm{parent}(i)] \ge A[i] \;(\text{Max-Heap})(Restored via Sift-Up on insertion and Sift-Down after extracting index 0.) - Floyd Bottom-Up Build-Heap Complexity:
T_{\text{build}}(n) = \sum_{h=0}^{\lfloor \log_2 n \rfloor} \left\lceil \frac{n}{2^{h+1}} \right\rceil O(h) = O(n)(Most nodes sit near the leaves and sift down at most 0 or 1 levels.)
View full Data Structures & Algorithms Formula Sheet | Constants Table
Related Data Structures Calculators
- Sorting Algorithm Visualizer: Step through Quick, Merge, Insertion, Selection, and Bubble Sort with comparison and swap counters.
- AVL Self-Balancing Tree & Rotations: Insert and delete keys with live per-node balance factors, heights, automatic LL/RR/LR/RL rotations, and a step-by-step rotation audit log.
- Dijkstra Shortest Path: Edit edge weights on a network graph and watch Dijkstra’s shortest-path tree update.
- Minimum Spanning Tree (Kruskal & Prim): Step through Kruskal Union-Find edge sorting and Prim cut-frontier expansion on weighted undirected graphs with cycle rejection tracking.
- Binary Search Tree Visualizer: Insert, delete, and search nodes on a live binary search tree with in-order, pre-order, and post-order traversals.
- Hash Table & Collision Resolution Simulator: Compare Linear Probing, Quadratic Probing, Double Hashing, and Separate Chaining with live load factor, probe sequences, and clustering metrics.