1/52
Loading...
📦📦 Original Array
Here is the array to sort. We will interpret it as a "logical tree" and build a heap.
🔒
Loading...
Here is the array to sort. We will interpret it as a "logical tree" and build a heap.
Represent a heap (complete binary tree with parent ≥ children) in an array, build a max-heap, then move the root to the end repeatedly to get ascending order.
[41, 36, 79, 9, 16, 25, 72]
[9, 16, 25, 36, 41, 72, 79]
Build a max-heap, send the root to the end repeatedly, and the array becomes ascending.
Heap Sort is a sorting method that organizes an array into a special tree-like structure called a "heap". A heap is a complete binary tree where parents are always greater than or equal to their children. By repeatedly taking the largest value from the top (root) and moving it to the back, the entire array becomes sorted.