Question
1. For the max heap (stored as an array) depicted below, which best describes what happens when 87 is added. 87 is added as a
1. For the max heap (stored as an array) depicted below, which best describes what happens when 87 is added.
87 is added as a child of 17 and then filters up
None of the others
87 replaces 17, which has to be readded
2.What is the worst-case runtime complexity of merging two binary heaps (stored as arrays)? Each heap has N elements.
O(1) link two heaps
O(n log n) Inserting each element of one array into the other.
None of the others
O(log n) Recursively merge heaps
3.
For the max heap (stored as an array) depicted below, what best describes what happens when the maximum is deleted?
91 is removed replaced with 15 (which has to filter down)
91 is removed and its children are merged
91 is replaced with the bigger of its children (and the process repeats at the deleted child)
None of the others
4.For the following code on a max heap (stored as an array), what is the purpose of the code? List any errors. For n elements, the heap is stored at locations A[0] to A[n-1].
boolean mystery ( ) { for (int k=0; k
It performs no useful function.
It inserts an element into a max heap.
It checks to see if the heap is correctly formed. However, it may miss checking the kids of some nodes.
It builds a max heap.
91 52 17 15 34 26 91 52 17 15 34 26
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started