Respuesta :
The operation of build-heap on heap array {12, 5, 13, 3, 11, 15} is max-heapify(heap, 3); max-heapify(heap, 2); max-heapify(heap, 1).
What is heap-array?
- Heap-array is an array structure that is designed to store data in a specific order, such that any element can be quickly retrieved or removed in a constant amount of time.
- It is implemented using a binary tree, where the value of each node is greater than or equal to the values of its children.
- To build a heap-array, first build a binary tree from the given array elements. Then, for each node in the tree, compare the value of the node with the values of its children.
- If the parent node is greater than or equal to both of its children, then the node is in the correct position and can be left as is. If the parent node is less than either of its children, then the two nodes must be swapped.
- After all nodes have been compared and swapped, if necessary, the heap-array is complete.
Step 1:
The first step is to start at the bottom of the heap array and work upwards. The index at the bottom of the heap array is 6. We will start at index 6 and call max-heapify.
Step 2:
Now, we will apply max-heapify to index 6. This will compare the element at index 6 (15) with its parent node at index 3 (13). Since 15 is greater than 13, max-heapify will swap the two elements. The resulting heap array is {12, 5, 15, 3, 11, 13}.
Step 3:
Now, we will move up to index 3 and call max-heapify. This will compare the element at index 3 (15) with its parent node at index 1 (12). Since 15 is greater than 12, max-heapify will swap the two elements. The resulting heap array is {15, 5, 12, 3, 11, 13}.
Step 4:
Now, we will move up to the top of the heap array at index 1 and call max-heapify. This will compare the element at index 1 (15).
To learn more about heap-array refer to:
https://brainly.com/question/29567727
#SPJ4