Binary heap implementation | Data Structures | San Diego State University

For this assignment, you will write one implementation of a Priority Queue. For this ADT, removal operations always return the object in the queue of highest priority that has been in the queue the longest. That is, no object of a given priority is ever removed as long as the queue contains one or more object of a higher priority. Within a given priority FIFO order must be preserved.

Your implementation will be:

1. BinaryHeap

The implementation must have identical behavior, and must implement the PriorityQueue interface (provided). The implementation must have two constructors, a default constructor with no arguments that uses the DEFAULT_MAX_CAPACITY constant from
the PriorityQueue interface, and a constructor that takes a single integer parameter that represents the maximum capacity of the priority queue.

The PriorityQueue interface follows:

/* The PriorityQueue ADT may store objects in any order. However,

  • ** removal of objects from the PQ must follow specific criteria. The
  • ** object of highest priority that has been in the PQ longest must be
  • ** the object returned by the remove() method. FIFO return order
  • ** must be preserved for objects of identical priority. **
  • ** Ranking of objects by priority is determined by the Comparable<E>
  • ** interface. All objects inserted into the PQ must implement this ** interface.
    package data_structures;
    import java.util.Iterator;
    public interface PriorityQueue<E extends Comparable <E>> extends Iterable<E> { 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<E> iterator();


Thus, your project will consist of the following files. You must use exactly these filenames.

  • The ADT interface (provided above)
  • The binary heap implementation.
    Additional Details:
  • 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. Accordingly, the ordered array implementation must use binary search where possible, such as the contains(), the delete(E obj) method and also to identify the correct insertion point for new additions. For binary heap implementation, both insert() and remove() must be O(log n).
  • By convention, a lower number=higher priority. If there are five priorities for a given object, 1 .. 5, then 1 is the highest priority, and 5 the lowest priority.
  • You BinaryHeap must be stable – able to determine the oldest entry among those with identical priority.
  • You may not make any modifications to the PriorityQueue interface provided.
  • You may import java.util.Iterator, and java.util.NoSuchElementException only. If you feel that you need to import anything else, let me know. You are expected to write
    all of the code yourself, and you may not use the Java API for any containers.
  • Your code must not print anything.
  • Your code should never crash, but must handle any/all error conditions gracefully. i.e. if the user attempts to call the clear() method on an empty PQ, or remove an item from an empty PQ, the program should not crash. Be sure to follow the specifications for all methods.
  • You must write generic code according to the interface provided. You may not add any public methods to the implementations, but you may add private ones, if needed.

I only need the one Binary Heap java file (or code)

Punctual Essays
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.


Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.


Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.


Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.


Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.