Heap
Document last modified:
Number each node with the array index it would have if it were stored in an array as a heap.
Reorganize the tree using the Build_Max_Heap algorithm.
Draw the reorganized tree below using the provided unlabeled tree.
Build_Max_Heap (A)
1
heap-size[A] ← length[A]
forall j; i<j≤length[A];
A[ j ] ≥ A[Left( j )] && A[ j ] ≥ A[Right( j )]
2
for
i ← ⌊length[A]/2⌋
downto
1
do
3
Max_Heapify (A, i)
#1 Solution
#3 Solution
Reorganize the array using the Build_Min_Heap algorithm.
Solution