Question: In class, we discussed the priority queue ( PQ ) ADT implemented using min - heap. In a min - heap, the element of the
In class, we discussed the priority queue PQ ADT implemented using minheap. In a minheap, the element of the heap with the smallest key is the root of the binary tree. On the other hand, a maxheap has as root the element with the biggest key, and the relationship between the keys of a node and its parent is reversed of that of a minheap. We also discussed an arraybased implementation of heaps.
In this programming assignment, your task is to implement your own adaptable and flexible priority queue AFPQ ADT using both min and maxheap. The specifications of the AFPQ are provided in the following. the heaps must be implemented from scratch using an array that is dynamically extendable. You are not allowed to use any list including arraylist tree, vector, or heap implementation already available in Java. You must not duplicate code for implementing min and maxheaps ie the same code must be used for constructing min or max heaps. Hence think of a flexible way to parameterize your code for either min or max heap
The priority queue is also adaptable meaning that any key or value of any entry of the priority queue can be modified, where the entry object is passed as a parameter. An entry can also be removed from anywhere in the priority queue. The following are the access methods of the AFPQ ADT:
removeTop: removes and returns the entry object a key, value pair with the smallest or biggest key depending on the current state of the priority queue either Min or Max
insert kv : Insert kv which is a keyk valuev pair to the priority queue, and returns the corresponding entry object in the priority queue.
top: returns the top entry with the minimum or the maximum key depending on whether it is a Min or Maxpriority queue, without removing the entry.
remove e: Removes entry object e from the priority queue and returns the entry
replaceKey ek : replace entry es key to k and return the old key.
replaceValue ev : replace entry es value to v and return the old value.
toggle transforms a min to a maxpriority queue or vice versa.
state : returns the current state Min or Max of the priority queue.
isEmpty: returns true if the priority queue is empty.
size : returns the current number of entries in the priority queue
You have to submit the following deliverables:
a Pseudo code of your implementation of the AFPQ ADT using a parameterized heap that is implemented using extendable array. Note that Java code will not be considered as pseudo code. Your pseudo code must be on a higher and more abstract level.
b Tight bigOh time complexities of toggle remove e replaceKey e k and replaceValue ev operations, together with your explanations. These methods should be as efficient as possible.
c Well documented Java source code with different but representative examples demonstrating the functionality of your implemented ADT. These examples should demonstrate all cases of your ADT functionality eg all operations of your ADT, several cases requiring automatic array extension, sufficient number of down and upheap operations,
changing keys, and removing entries from anywhere of heap
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
