notesonly.in

One notebook for every subject — open it anywhere.

Log in

Heaps and heap operations

Data Structures · Engineering

Study notes

Build a max-heap from [4, 10, 3]: 4 root, 10 left child violates heap, swap to get 10 root with 4 left, then add 3 as right child of 10. Extract-max returns 10, moves 3 to root, and since 3 < 4, swaps to restore: heap becomes [4, 3]. Heapsort repeats extract-max for sorted output.

← Back to topics for Engineering