Question: The operations on a priority queue are to add an item to the queue and to remove the largest item. Sometimes, it is required to
The operations on a priority queue are to add an item to the queue and to remove the largest item. Sometimes, it is required to be able to change the priority of an item in the queue. (This does not really apply to a priority queue of numbers. It applies when the queue holds complex objects and the priority is only one property of the objects. For example, consider a priority queue of jobs waiting for run time on a computer. The priority of a job might change while it is in the queue.) list. How would a changePriority operation be implemented in that case? What is the "Big-Theta" run time of the operation? (This is trivial.) b) Suppose that the priority queue is implemented as a sorted list, sorted by priority. How would a changePriority operation be implemented in that case? What is the "Big-Theta" run time of the operation? c) Now suppose that the priority queue is implemented by a heap-which it should be, of course, for efficiency. If you simply change the priority of an item in the heap, the resulting data structure might not satisfy the heap property. Explain how to implement a changePriority operation for a priority queue implemented as a heap. Give a clear and complete explanation or write out an explicit algorithm. What is the "Big-Theta" run time of the operation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
