Can both insert and findMin be implemented in constant time?
Read moreTextbook Solutions for Data Structures and Algorithm Analysis in Java
Question
8 A min-max heap is a data structure that supports both deleteMin and deleteMax inO(logN) per operation. The structure is identical to a binary heap, but the heaporderproperty is that for any node, X, at even depth, the element stored at X issmaller than the parent but larger than the grandparent (where this makes sense),and for any node X at odd depth, the element stored at X is larger than the parentbut smaller than the grandparent. See Figure 6.57.a. How do we find the minimum and maximum elements?b. Give an algorithm to insert a new node into the min-max heap.c. Give an algorithm to perform deleteMin and deleteMax. d. Can you build a min-max heap in linear time?e. Suppose we would like to support deleteMin, deleteMax, and merge. Propose adata structure to support all operations in O(logN) time.
Solution
The first step in solving 6 problem number 18 trying to solve the problem we have to refer to the textbook question: 8 A min-max heap is a data structure that supports both deleteMin and deleteMax inO(logN) per operation. The structure is identical to a binary heap, but the heaporderproperty is that for any node, X, at even depth, the element stored at X issmaller than the parent but larger than the grandparent (where this makes sense),and for any node X at odd depth, the element stored at X is larger than the parentbut smaller than the grandparent. See Figure 6.57.a. How do we find the minimum and maximum elements?b. Give an algorithm to insert a new node into the min-max heap.c. Give an algorithm to perform deleteMin and deleteMax. d. Can you build a min-max heap in linear time?e. Suppose we would like to support deleteMin, deleteMax, and merge. Propose adata structure to support all operations in O(logN) time.
From the textbook chapter Priority Queues (Heaps) you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution