Homework 5 - Heaps and Heap Sort
Algorithms I - CSCI 700 - Fall 2010 - Prof. Rosenberg
Due October 14 at 6:30pm
In this assignment, you will write a Heap class and use it to implement HeapSort.
The Heap class must be deﬁned in two ﬁles heap.cc and heap.h or in heap.java.
The Heap class must support, at least, the following functions.
void insert(const int a)
As in Assignment 3, your program will read input from an input ﬁle which contains
one integer per line, and write sorted output to an output ﬁle which contains the same
integers in sorted order. You may use the fileio.h and fileio.cc or fileio.java code
that you wrote for Assignment 3 in this assignment.
Also like Assignment 3, your program should write the number of comparisons made
during the sorting function to standard output.
• A heap.cc and heap.h or heap.java ﬁle which implement the Heap data structure.
• A heapsort.cc or heapsort.java ﬁle which uses the Heap data structure to implement
the heapsort algorithm
• A ﬁleio.cc ﬁleio.h or ﬁleio.java which implement the reading and writing functions
that each of the sorting program will use.
• A plain text README ﬁle describing the heap data structure and heapsort func-
tions including the theoretical and actual number of comparisons required for each
• Run each program on each of the ﬁve sample input ﬁles. In your README ﬁle,
report the number of data points, n, in each ﬁle, as well as the number of comparisons
heapsort uses to sort them.
The program must compile using the following command on a CS network computer.
g++ heapsort.cc fileio.cc heap.cc -o heapsort
javac heapsort.java heap.java filio.java
The program must run using the following command on a CS network computer.
./heapsort input_filename output_filename
java heapsort input_filename output_filename
• 15 points - Compilation Each ﬁle must compile without error or warning into an
executable as described above.
• 15 points - Execution The executable must run without error or warning on valid
input using the command line parameters described above.
• 15 points - README Does your README documentation completely and ac-
curately describe the heap data structure and heapsort algorithm? Does it include
theoretical and actual numbers of comparisons on the 5 sample input ﬁles?
• 10 points - Within Code Documentation Is the code documented for obvious
understanding of the use, preconditions, and postconditions of each function?
• 10 points - Style Are functions and variables given self-explanatory names? Are
functions used to aid intelligibility of the code? Are functions used to reduce repeated
blocks of code? Is indentation, spacing, use of parentheses, use of braces consistent
• 20 points - Correctness Are the insertion, deletion, get and pop functions imple-
• 15 points - Automated Testing There will be ﬁve automated tests. Does the
executable produce correct output for all ﬁve ﬁles?