14 Heaps-Heapsort
14 Heaps-Heapsort
2 8 1 8
5 8 2
2 2 5 2 1
8 1 8
2 2 5 2 1
8 1 8
2 2 5 2 1
8 1 8
2 2 5 2 1
8 1 8
2 5
4 3
2 5
4 3
4 3
4 3
3 5
3 5
2 5
4 3
2 5
4 3
2 5
2 5
3 5
3 5
3 5
5 2
1 4
1 2
5 4
1 2
5 4
1 2
5 4
10
20 50
40 30
1 2
20 50
3 4
40 30
1 2
20 50
3 4
40 30
10 20 50 40 30
0 1 2 3 4
15 August 2024 OSU CSE 45
At what index in the
array is the left child of 0
the node at index i? 10
1 2
20 50
3 4
40 30
10 20 50 40 30
0 1 2 3 4
15 August 2024 OSU CSE 46
At what index in the
array is the right child 0
of the node at index i? 10
1 2
20 50
3 4
40 30
10 20 50 40 30
0 1 2 3 4
15 August 2024 OSU CSE 47
Resources
• Wikipedia: Heapsort
– https://en.wikipedia.org/wiki/Heapsort
• Wikipedia: Heap (data structure)
– https://en.wikipedia.org/wiki/Heap_(data_structure)
• Big Java (4th ed), Sections 16.8, 16.9
– https://library.ohio-state.edu/record=b8540788~S7