Question: Section 5.5 provides an asymptotic analysis for the worst-case cost of function buildHeap. Give an exact worst-case analysis for buildHeap. 5.5 Heaps and Priority Queues

Section 5.5 provides an asymptotic analysis for the worst-case cost of function buildHeap. Give an exact worst-case analysis for buildHeap.

5.5 Heaps and Priority Queues There are many situations, both in real life and in computing applications,

case. However, there is always the possibility that the BST will become unbal- anced, leading to bad

import java.lang. Comparable; /** Max-heap implementation */ public class MaxHeap

/** Return position for parent */ public int parent (int pos) { assert pos > 0: "Position has no parent";

5.5 Heaps and Priority Queues There are many situations, both in real life and in computing applications, where we wish to choose the next "most important" from a collection of people, tasks, or objects. For example, doctors in a hospital emergency room often choose to see next the "most critical" patient rather than the one who arrived first. When scheduling programs for execution in a multitasking operating system, at any given moment there might be several programs (usually called jobs) ready to run. The next job selected is the one with the highest priority. Priority is indicated by a particular value associated with the job (and might change while the job remains in the wait list). When a collection of objects is organized by importance or priority, we call this a priority queue. A normal queue data structure will not implement a prior- ity queue efficiently because search for the element with highest priority will take (n) time. A list, whether sorted or not, will also require (n) time for either in- sertion or removal. A BST that organizes records by priority could be used, with the total of n inserts and n remove operations requiring (n log n) time in the average

Step by Step Solution

3.41 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The buildheap method in the provided MaxHeap class implements the heap construct... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Practical Introduction To Data Structures Questions!