I was working with algorithms and specifically heapsort. From my understanding the heapsort algorithm involves preparing the list by first turning it into a max heap.
Turning my
[2, 8, 5, 3, 9, 1]
Into
[9, 8, 5, 3, 2, 1]
With heapsort I am supposed to swap 9 with 1. But by looking at the array straight after max heaping, i see a sorted list in decreasing order. Why is swapping required when the list is already sorted in decreasing order?
This was just thoughts I had after watching: https://www.youtube.com/watch?v=2DmK_H7IdTo