- A Max Heap Is Useful To Implement Another Data Structure Priority Queue Where You Can Always Have The Highest Priority 1 (60.48 KiB) Viewed 24 times
A max heap is useful to implement another data structure Priority Queue, where you can always have the highest priority
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
A max heap is useful to implement another data structure Priority Queue, where you can always have the highest priority
A max heap is useful to implement another data structure Priority Queue, where you can always have the highest priority value at the root of the heap, so that the system can easily gain access to the most imminent task at a time. In case we want to force the system to handle a certain task sooner, we might need to increase a certain value inside the max heap while still maintaining the max heap property. For this reason we may introduce the Heap-Increase routine, which is defined as: Heap-Increase (A, i, k) Given a max heap array A (of size n), we increase the value A by k. A. How would you heapify the now changed heap array after A becomes larger? How would you mitigate potential violations? Complete your implementation of Heap-Increase using the following pseudocode template. (3pts) B. And what is the *tightest* Big-O-of-n time complexity of this Heap-Increase routine? (2pts) Hints: Recall the strict premise in order to apply Max-Heapify and how we do Build-Heap from ground up. Heap-Increase (A, i, k). A = // Then? A+k; //assuming k is always positive