Question

In: Computer Science

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.

Solutions

Expert Solution

Answer: If we go by the Brute Force Approach We can check all the nodes in the min heap to get the maximum element. Note that this approach works on any binary tree and does not makes use of any property of the min heap. It has a time and space complexity of O(n). Since min heap is a complete binary tree, we generally use arrays to store them, so we can check all the nodes by simply traversing the array. If the heap is stored using pointers, then we can use recursion to check all the nodes.

Alternatively the min heap property requires that the parent node be lesser than its child node(s). Due to this, we can conclude that a non-leaf node cannot be the maximum element as its child node has a higher value. So we can narrow down our search space to only leaf nodes. In a min heap having n elements, there are ceil(n/2) leaf nodes. The time and space complexity remains O(n) as a constant factor of 1/2 does not affect the asymptotic complexity.

Hence any algorithm that must nd the maximum key of the heap must search all of the leaf nodes.


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
How to write Prim's Algorithm with min-Heap and adjacency Lists?
How to write Prim's Algorithm with min-Heap and adjacency Lists?
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...
a tree is binary, if every node has at most two children nodes. prove that the...
a tree is binary, if every node has at most two children nodes. prove that the maximum of nodes in a binary tree of height h is 2^(h+1)-1
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 theheap that are/is larger than a[3] ""There...
10) A binary tree with N nodes is at least how deep? How deep is it...
10) A binary tree with N nodes is at least how deep? How deep is it at most? 12) A Binary Search Tree is a binary tree with what additional property? 13) Beginning with an empty binary search tree, insert the following values in the order given. Draw the tree at each step of the process. 1 10 5 20 22 7 14) Now delete the value 10 from the tree in question 13. Show each of two possible configurations...
Write a O(n) method valuesInLevelOrder() that returns a list of the nodes of a binary tree...
Write a O(n) method valuesInLevelOrder() that returns a list of the nodes of a binary tree in level-order. That is, the method should return the root, then the nodes at depth 1, followed by the nodes at depth 2, and so on. Your algorithm should begin by putting the tree root on an initially empty queue. Then dequeue a node, add it to the output, and enqueue its left and right children (if they exist). Repeat until the queue is...
(Lower bound for searching algorithms) Prove: any comparison-based searching algorithm on a set of n elements...
(Lower bound for searching algorithms) Prove: any comparison-based searching algorithm on a set of n elements takes time Ω(log n) in the worst case. (Hint: you may want to read Section 8.1 of the textbook for related terminologies and techniques.)
Prove and give a counterexample: If N ⊲ G and G ⊲ H, then N ⊲...
Prove and give a counterexample: If N ⊲ G and G ⊲ H, then N ⊲ H. Please write an explanation with some details
Prove the following: When replacing the key in a node of a heap with a key...
Prove the following: When replacing the key in a node of a heap with a key that is greater than one, or greater than both, of its children, then sifting that node down (trading places with its smallest child) until it is less than all of its children will produce a heap.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT