AiTechWorlds
AiTechWorlds
Insert and extract-min on a binary min-heap with sift-up/sift-down animation and a synced array + tree view.
import heapq
heap = []
heapq.heappush(heap, v) # min-heap push
smallest = heapq.heappop(heap) # extract-minA binary heap is a complete binary tree stored in an array, where each parent satisfies the heap property: every parent is ≤ its children, so the minimum is always at the root. Insert and extract both run in O(log n); reading the root is O(1). Heaps power priority queues and Heap Sort.
| Peek root | O(1) |
| Insert / Extract | O(log n) |
| Build heap | O(n) |
The Heap Visualizer lets you insert and extract from a binary min-heap and watch the sift-up and sift-down operations that restore the heap property. A binary heap is a complete binary tree stored in an array where every parent is smaller than its children (min-heap), so the minimum is always at the root. Insert and extract both run in O(log n); reading the root is O(1). A synced array view shows the underlying storage.
Insert values
Type a number and click Insert to append it and sift it up, or click Random for a sample heap.
Extract the min
Click Extract Min to remove the root and watch the last element sift down.
Compare views
Watch both the tree view and the array view update together.
Read the code
See heap push code in C++, Java, Python, or JavaScript and copy it.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.