Step 1: Add 5 to max heap (smaller half)
MaxHeap: [5] ↑top
MinHeap: []
Why: Start by putting first number in smaller half
Step 2: Add 3 to max heap, then balance by moving max from max heap to min heap
MaxHeap: [3] ↑top
MinHeap: [5] ↑top
Why: Keep smaller half max heap larger or equal size than min heap
Step 3: Add 8 to min heap, then balance by moving min from min heap to max heap
MaxHeap: [5, 3] ↑top
MinHeap: [8] ↑top
Why: Balance heaps so size difference is at most 1
Step 4: Add 9 to min heap, no balancing needed
MaxHeap: [5, 3] ↑top
MinHeap: [8, 9] ↑top
Why: Heaps sizes are now equal
Step 5: Add 1 to max heap, no balancing needed
MaxHeap: [5, 3, 1] ↑top
MinHeap: [8, 9] ↑top
Why: Max heap can be one larger than min heap
Step 6: Add 6 to min heap, no balancing needed
MaxHeap: [5, 3, 1] ↑top
MinHeap: [6, 8, 9] ↑top
Why: Heaps are balanced with sizes equal
Result: MaxHeap: [5, 3, 1] ↑top
MinHeap: [6, 8, 9] ↑top
Median after each insertion: 5, 4, 5, 6.5, 5, 5.5