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

  1. Select Min Heap or Max Heap mode
  2. Enter a number and click Push to add elements (max 15 elements)
  3. Click Pop to remove the root element
  4. Watch the animations to see how comparisons, swaps, and removals work
  5. Click Clear to reset and start over
0 / 15

Tree View

Array View