Instructions
Problem 1:   Priority Queue and Heap  Sort
Problem 2:   Sorting Algorithms Detective
5.3.5

Assignment 11

Goals:
  • Learn to implement a priority queue and heapsort algorithm.

  • Explore the time compexity of sorting algorithms.

Instructions

The names of the classes must be exactly the same as specified. The same is the case for the names and types of the fields within the class, as well as the order in which they are defined and listed as the constructor arguments. This allows us to design our own Examples class that tests your program.

Make sure you follow the style guidelines that WebCAT enforces. For now the most important ones are: using spaces instead of tabs, indenting by 4 characters, following the naming conventions (data type names start with a capital letter, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment by the deadline using the Web-CAT submission system. You may submit as many times as you wish. Be aware of the fact that close to the deadline the WebCAT system may slow down to handle many submissions - so try to finish early.

With each homework you will also submit your log file named pair-user1-user2.txt where you replace user1 and user2 with the usernames of the two partners.

On top of both files you will have five lines of comments as follows:

// assignment 11

// partner1-last-name partner1-first-name

// partner1-username

// partner2-last-name partner2-first-name

// partner2-username

(In the text file you do not need the two slashes)

There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with the feedback for each problem wou work on.

The three submissions will be organized as follows:

Due Date: Wednesday, April 2nd, 11:59 pm.

Problem 1: Priority Queue and HeapSort

Your job is to design a priority queue using the heap algorithm. You then use this to implement the heapsort algorithm and add it to a collection of algorithms to be evaluated for time-complexity.

The descrioption of this assignment is written in a tutorial style - so you can recall the lecture details.

If it helps you, draw the picture of the tree and manipulate stickies or pieces of paper to see how the algorithms for inserting and deleting nodes work.

Typically, we represent this heap as an ArrayList<T> with the first item (at index 0) unused (maybe null).

Heapsort

Now implement a simple variant of heapstort as follows:

In the class HeapSort implement the method

public ArrayList<T> heapsort(ArrayList<T> alist, Comparator<T> comp)

that consumes the ArrayList to be sorted} and a Comparator. In the first step just insert the given data into a new PriorityQueue, one item at a time.

In the second step, the remove the data from your PriorityQueue and insert them into the resulting ArrayList, one at a time.

If you just add each item at the end, you will end up with a list ordered in descending order.

Note: This is a simplified heapsort - real heapsort does not need additional space and results in a correcly ordered list.

Problem 2: Sorting Algorithms Detective

Finish the Lab 11 work on measuring time spent of different sorting algorithms and finding out from the timing and test behavior which algorithms could exhibit the observed behavior.

As it says in the lab description:

Run the program a few times with small data sizes, to get familiar with what it can do. Then run experiments and try to answer the following questions: