04 Try it yourself Interactive
Both pictures below are the same numbers, however many you load. The indigo ring is the value being moved right now; amber is the parent or child it is being compared against; rose means those two are swapping this step; green means that value has found its place. Watch the array row on every swap — one level of movement in the tree is always two cells trading places, and the index moves by i → (i-1)/2 going up, i → 2i+1 or 2i+2 going down. Switch to the second tab to empty the heap again.