Nothing special here. It’s just a blog post for summarising my algorithm learning course. Probably this was taught in the University but I don’t remember anything, I have no idea about its definition and applications until I take this course. Part 1 here Binary Heap & Heapsort Summary - Part 1 - Binary Heap
The Idea
Heapsort has two phases: build a max-heap from the array, then repeatedly remove the maximum to
fill the array from the back. We use the array S O R T E X A M P L E (N = 11) as the example.
S O R T E X A M P L E"] --> B["Max-heap
X T S P L R A M O E E"] --> C["Sorted array
A E E L M O P R S T X"]
- Start with array of keys in arbitrary order
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Key | S | O | R | T | E | X | A | M | P | L | E |
- Create a max-heap with all N keys
- Repeatedly remove the maximum key (in place) to create a sorted array
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Key | A | E | E | L | M | O | P | R | S | T | X |
