Be sure you are acquainted with my collaboration policy and my late policy, both found on the main course webpage.
Clarification: For question 2, use a min-heap.
insert(3)
insert(4)
insert(1)
insert(8)
removeMin()
insert(2)
insert(10)
insert(5)
removeMin()
removeMin()
removeMin()
removeMin()
removeMin()
removeMin()
PriorityQueue
class, implemented as a heap, that stores ints and has the following methods: void insert(int n)
, int removeMin()
, and boolean isEmpty()
. Implement a method called "heapSort" that takes an array of integers and returns an array containing the same values in sorted order (from least to greatest). This should be done using the PriorityQueue
class and should have a run-time of O(n*log(n)). Explain why it has this run-time.
The method signature will look like this:
public int[] heapSort(int[] arr) {...}
(Note: if you want to check your algorithm, you are free to implement the PriorityQueue
class. Alternatively, you can test it out using Java's built in PriorityQueue, though the method names will differ.)
To hand in your program, copy your answers (stored in a text file) into the following directory:
/p/course/cs367-ealexand/handin/login-name/H5
Use your actual CS login name (not your UW NetID!) in place of login-name.
You should write this assignment up by yourself. If you share ideas with anyone, be sure to cite them.