Question

In: Computer Science

Suppose you have a min-heap in an array a[] where: ● The root isstored at...

Suppose you have a min-heap in an array a[] where: ● The root is stored at index 1 ● There are 15 elements (in a[1]...a[15]) ● There are no duplicates (this is not true in general for heaps; but assume it is true for this problem). Fill in the blanks in the statements below; the resulting statement must be true for any heap obeying the above properties.

There are/is at least ____6_______ elements in the
heap that are/is larger than a[3] "


"There are/is at least ____________ elements in the
heap that are/is smaller than a[5] "


"There are/is at most ______________ elements in
the heap that are/is smaller than a[13] "


"There are/is at most _______________ elements in
the heap that are/is larger than a[15] "

Solutions

Expert Solution

In a Min-Heap both children of a root node contain larger value than their parent / root node. This property must be maintained in the entire heap.

There are/is at least 6 elements in the
heap that are/is larger than a[3] "

The elements are a[6], a[7], a[12], a[13], a[14], and a[15].


"There are/is at least 2 elements in the
heap that are/is smaller than a[5] "

The elements are a[1] and a[2].


"There are/is at most 7 elements in
the heap that are/is smaller than a[13] "

The elements can be a[1], a[3], a[6], a[7], a[12], a[14], and a[15].


"There are/is at most 1 elements in
the heap that are/is larger than a[15] "

The element can be a[14].


Related Solutions

Let's suppose that you have a binary min-heap with S elements. Please write an an algorithm...
Let's suppose that you have a binary min-heap with S elements. Please write an an algorithm that will find all the elements that are in the heap that are smaller than a given value X. Please make sure that the time complexity of the algorithm that you propose has to be O(K), where is the number of elements smaller than X that is in the heap. Please type answer if you can
In this programming project, you will be implementing the data structure min-heap. You should use the...
In this programming project, you will be implementing the data structure min-heap. You should use the C++ programming language, not any other programming language. Also, your program should be based on the g++ compiler on general.asu.edu. All programs will be compiled and graded on general.asu.edu, a Linux based machine. If you program does not work on that machine, you will receive no credit for this assignment. You will need to submit it electronically at the blackboard, in one zip file,...
Suppose H is a binary min-heap with n nodes, Prove the following facts: Any algorithm that...
Suppose H is a binary min-heap with n nodes, Prove the following facts: Any algorithm that must nd the maximum key of the heap must search all of the leaf nodes.
How to write Prim's Algorithm with min-Heap and adjacency Lists?
How to write Prim's Algorithm with min-Heap and adjacency Lists?
write a function that determines if a given vector of integersis a min–heap. By default,...
write a function that determines if a given vector of integers is a min–heap. By default, a vector is asemi–heap satisfying the heap structure propertybut not the heap order property.InputThere is an unknown number of integer data that will be provided from standard input. Each line of input represents the contents of a vector. We do not know how many lines of input there are.1 2 3 4 55 4 3 2 11 9 2 13 10 5 3 15...
Recall that an array could be a convenient way of storing the elements of a Heap....
Recall that an array could be a convenient way of storing the elements of a Heap. Give a Pseudocode that determines whether an array H[1..N] is indeed a Heap, i.e., it’s elements satisfy the Heap property.
This problem requires you to use a heap to store items, but instead of using a key of an item to determine where to store the item in the heap
This problem requires you to use a heap to store items, but instead of using a key of an item to determine where to store the item in the heap, you need to assign a priority (key) to each item that will determine where it is inserted in the heap 7a) Show how to assign priorities to items to implement a first-in, first-out queue with a heap. 7b) Show how to assign priorities to items to implement a first-in, last-out stack with...
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
One way to remove an object from a binary min heap is to decrease its priority...
One way to remove an object from a binary min heap is to decrease its priority value by 1 and then call deleteMin. An alternative is to remove it from the heap, thus creating a hole, and then repair the heap. Write pseudocode for an algorithm that performs the remove operation using the alternative approach described above. Your pseudocode should implement the method call remove (int index), where index is the index into the heap array for the object to...
Related to HeapSort (a) Construct a heap for the following array of numbers:         8 1 2...
Related to HeapSort (a) Construct a heap for the following array of numbers:         8 1 2 3 5 6 4 7 10 9       Show the array after the insertion of each element into the heap. (b) Use your heap to sort the array. Show the resulting heap after the extraction of each maximum.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT