Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, you will write one more implementations of a Priority Queue. You will write a binary heap implementation. Your heap implementation must have

For this assignment, you will write one more implementations of a Priority Queue. You will write a binary heap implementation. Your heap implementation must have identical behavior, and must implement the PriorityQueue interface.The implementation must have two constructors -- use the DEFAULT_MAX_CAPACITY in the interface for one constructor and take a size parameter for the second.

Additional Deteails:

Each method must be as efficient as possible. That is, a O(n) is unacceptable if the method could be written with O(log n) complexity. Both insert and remove must be O(log n)

Your BinaryHeap must be stable--able to determine the oldest entry among those with identical priority.

Your iterator must be fail-fast.

PriorityQueue ADT:

package data_structures; import java.util.Iterator; import java.util.NoSuchElementException; public interface PriorityQueue> extends Iterable { public static final int DEFAULT_MAX_CAPACITY = 1000; // Inserts a new object into the priority queue. Returns true if // the insertion is successful. If the PQ is full, the insertion // is aborted, and the method returns false. public boolean insert(E object); // Removes the object of highest priority that has been in the // PQ the longest, and returns it. Returns null if the PQ is empty. public E remove(); // Deletes all instances of the parameter obj from the PQ if found, and // returns true. Returns false if no match to the parameter obj is found. public boolean delete(E obj); // Returns the object of highest priority that has been in the // PQ the longest, but does NOT remove it. // Returns null if the PQ is empty. public E peek(); // Returns true if the priority queue contains the specified element // false otherwise. public boolean contains(E obj); // Returns the number of objects currently in the PQ. public int size(); // Returns the PQ to an empty state. public void clear(); // Returns true if the PQ is empty, otherwise false public boolean isEmpty(); // Returns true if the PQ is full, otherwise false. List based // implementations should always return false. public boolean isFull(); // Returns an iterator of the objects in the PQ, in no particular // order. public Iterator iterator(); } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

Why has Negotiating Women, Inc. focused its attention on women?

Answered: 1 week ago