Project 2: Advanced Binary Heap Algorithms

Improving Heap Construction and Heap_Sort Performance

Version 10/01/17

Educational Objectives: After completing this assignment, the student should be able to accomplish the following:

Background Knowledge Required: Be sure that you have mastered the material in these chapters before beginning the assignment:
Iterators, Generic Algorithms, Introduction to Trees, Binary Heaps, and Advanced Heap Algorithms.

Operational Objectives: Implement two new generic heap algorithms fsu::g_heap_repair and fsu::g_build_heap. Move the current implementation of g_heap_sort into the alt namespace and re-implement fsu::g_heap_sort using the new algorithms. Test both versions fsu::g_heap_sort and alt::g_heap_sort using sortspy.cpp and tease out the differences in runtimes, providing details in log.txt.

Deliverables: Three files:

gheap_advanced.h  # fsu::g_heap_sort and alt::g_heap_sort, plus other algorithms
makefile          # builds sortspy.x and hsort.x
log.txt           # your project work log

Procedural Requirements

  1. The official development/testing/assessment environment is specified in the Course Organizer. Code should compile without warnings or errors.

  2. In order not to confuse the submit system, create and work within a separate subdirectory cop4531/proj2.

  3. Begin by copying the entire contents of the directory LIB/proj2 into your cop4531/proj2/ directory. Then copy the file LIB/tcpp/gheap_basic.h into cop4531/proj2/. At this point you should see these files in your directory:

    gheap_basic.h
    hsort.cpp
    ranuint.cpp
    sortspy.cpp
    deliverables.sh
    
  4. Copy gheap_basic.h to gheap_advanced.h and edit to satisfy the requirements for that deliverable.

  5. Test your algorithms thoroughly and put your notes and conclusions into your log.txt.

  6. Submit the assignment using the script LIB/scripts/submit.sh.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit assignments. If you do not receive the second confirmation with the contents of your assignment, there has been a malfunction.

Code Requirements and Specifications

  1. Before starting to code, it's a good idea to review one more time the material on Advanced Heap Algorithms. The theory, algorithms, and code are all discussed there. Your delverable gheap_advanced.h should follow the plan outlined in these notes.

  2. Begin coding by moving the current two versions of heap_sort into the namespace alt, keeping only the prototypes in namespace fsu. You will also need to add the namespace fsu:: resolution to the calls to push_heap and pop_heap. The effect is that the old "fsu::g_heap_sort" is now "alt::g_heap_sort".

  3. Add these algorithm prototypes to namespace fsu (including the requisit template statements):

    g_build_heap(I beg, I end, P& p);
    g_build_heap(I beg, I end);
    g_heap_repair(I beg, I loc, I end, P& p);
    g_heap_repair(I beg, I loc, I end);
    

    so that the totality of prototypes in the file is:

    namespace fsu
    {
      g_push_heap   (I beg, I end, P& p);
      g_pop_heap    (I beg, I end, P& p);
      g_heap_sort   (I beg, I end, P& p);
      g_build_heap  (I beg, I end, P& p);
      g_heap_repair (I beg, I loc, I end, P& p);
    
      g_push_heap   (I beg, I end);
      g_pop_heap    (I beg, I end);
      g_heap_sort   (I beg, I end);
      g_build_heap  (I beg, I end);
      g_heap_repair (I beg, I loc, I end);
    } 
    
    namespace alt
    {
      g_heap_sort   (I beg, I end, P& p);
      g_heap_sort   (I beg, I end);
    }
    

    The implementations for the alt versions should also be already there in the file, where you changed the namespace to include them under alt.

  4. Implement all of the namespace fsu algorithms in the namespace fsu. The implementation for fsu::g_push_heap can be the same as it was in the old version. The new algorithms g_heap_repair and g_build_heap obviously require new implementations, using the ideas outlined above in this document. Finally, g_pop_heap and g_heap_sort require the improved implementations, again as outlined above.

  5. Test your various implementations using the supplied sortspy.cpp. Note that this version of sortspy has the additional feature of checking the results of each sort and reporting the number of order errors in the result. Zero is good. Anything else tells you the "sort" algorithm is misnamed.

  6. Once you are sure you have the implementations correct, begin to pay attention to the comp_count data for the two versions of heap_sort. (Keep observations in your log.) Try to tease out a distinction between the two.

Hints