Min & Max Heaps
What are Heaps?
A heap is a specialized tree-based data structure that satisfies the heap property:
- Min Heap: Every parent node is smaller than its children. The minimum value is always at the root.
- Max Heap: Every parent node is larger than its children. The maximum value is always at the root.
Key Characteristics
- Complete Binary Tree: Heaps are stored as arrays where left child of node at index i is at 2i+1, right child at 2i+2
- Efficient Operations: Both push and pop operations run in O(log n) time
- Real-world Uses: Priority queues, heap sort, Dijkstra's algorithm, event scheduling
Operations
- Push: Add element to the end, then bubble up to maintain heap property
- Pop: Remove root, move last element to root, then bubble down to maintain heap property
How to Use
- Select Min Heap or Max Heap mode
- Enter a number and click Push to add elements (max 15 elements)
- Click Pop to remove the root element
- Watch the animations to see how comparisons, swaps, and removals work
- Click Clear to reset and start over
0 / 15