A Min Heap always keeps the smallest element at the root, making it ideal for quickly accessing the smallest item in a changing dataset.
A Max Heap always keeps the largest element at the root, which is useful when you want to quickly access or remove the largest item.
Insert 7 Insert 3 Insert 5 Insert 1 Print heap
After inserting 7, 3, 5, and 1, the Min Heap reorganizes to keep the smallest element (1) at the root, followed by 3, 5, and 7 in heap order.
Insert 2 Insert 9 Insert 4 Insert 6 Print heap
After inserting 2, 9, 4, and 6, the Max Heap reorganizes to keep the largest element (9) at the root, followed by 6, 4, and 2 in heap order.
To maintain the median, use a Max Heap for the lower half (to get the largest of the smaller numbers) and a Min Heap for the upper half (to get the smallest of the larger numbers). This allows quick median calculation.
