Lab 11: Heaps
CS 241: Data Structures, Fall 2007


Due Date: Thursday Dec 6

Goals for this assignment are to:

Reading

Read Chapter 14.1 (pp 369-377)

Directions

  1. Read through the heap code given in the text (chp 14.1) so that you understand what it is doing.

  2. Beginning with your SortAnimation project from the earlier labs, complete the HeapSort.java code roughly basing it on the code in the text. You will need to do some modification so that it fits the SortAnimation program. For example, some of the differences are

  3. Watch the animation - does it behave the way you expect?

  4. HeapSort works by first building a heap. In order to see the heap's structure, add the following two functions (similar to what you wrote for the binary search tree):

    1. printHeap: print the heap as a tree using the parenthesis notation.
    2. printTree: print the heap as a tree on its side.
  5. Apply these two functions after the heap is created but before the sorting takes place. Print the results to the outTA textArea as shown in the image above. Note, the heap is displayed in 3 formats: 1) as an array, 2) in parenthesis notation, and 3) as tree on its side. Use this output to check that your heap code works, i.e. check that each node of your heap satisfies the heap property. Where is the largest item in the array?

Evaluation

By no later than Thursday Dec 6, you should zip together your project, including a jar files, and email the code as an attachment to gorr@willamette.edu. Place CS241 Lab 11 in the subject line.

Demonstrate your the heap animation before the end of the classes.


[top]  [Schedule]  [Home]