Min-heap: offer [35, 20, 50, 10, 40, 5] one at a time ===================================================== offer(35) placed at index 0 [35] reached the root [35] offer(20) placed at index 1 [35, 20] parent a[0]=35 > 20 swap 1 <-> 0 reached the root [20, 35] offer(50) placed at index 2 [20, 35, 50] parent a[0]=20 <= 50 stop offer(10) placed at index 3 [20, 35, 50, 10] parent a[1]=35 > 10 swap 3 <-> 1 parent a[0]=20 > 10 swap 1 <-> 0 reached the root [10, 20, 50, 35] offer(40) placed at index 4 [10, 20, 50, 35, 40] parent a[1]=20 <= 40 stop offer(5) placed at index 5 [10, 20, 50, 35, 40, 5] parent a[2]=50 > 5 swap 5 <-> 2 parent a[0]=10 > 5 swap 2 <-> 0 reached the root [5, 20, 10, 35, 40, 50] final array : [5, 20, 10, 35, 40, 50] java.util.PriorityQueue shows: [5, 20, 10, 35, 40, 50]