Assignment 10 -- Due Monday, November 28
CS 4521 Fall Semester, 2005
20 Points

Topic: Implementation of Binomial Heaps

The assignment consists of writing code and demonstrating binomial heap operations as described in Chapter 19 of the text. Implementing binomial heaps will require coding the operations:

Of these, the only algorithm not in the text is BINOMIAL-HEAP-MERGE, which you wrote in a previous assignment (the decrease-key and delete operations are not required). On page 468, for BINOMIAL-HEAP-EXTRACT-MIN the text assumes, but does not provide, algorithms for: For the former, BINOMIAL-HEAP-MINIMUM on page 462 is a good model, but you must provide the latter. If you don't already have working implementations of these LL-operations, then you should probably test them thoroughly in isolation before using them in BINOMIAL-HEAP-EXTRACT-MIN.

You can use a modified version of the command interpreter for binary heaps (in Assignment 4); as with that assignment, c creates a heap (i.e. calls MAKE-BINOMIAL-HEAP), and d deletes the minimum key (i.e. calls BINOMIAL-HEAP-EXTRACT-MIN); the merge and union operations are tested indirectly. In addition, you need to write the routine Show-Binomial-Heap which displays the binomial heap structure graphically (see below), rotated 90 degrees as usual.

Test Example

The test files are the same as for binary heaps. Here is the correct output for heaptest2:
+-----------------------------------------------------------------+
|# create empty heap						  |
|								  |
|# insert 20 keys						  |
|								  |
|# show heap structure						  |
|								  |
|Structure of binomial heap (rotated 90 degrees counterclockwise):|
|								  |
|    1     2							  |
|                                                                 |
|          3     4						  |
|								  |
|          5     6                                                |
|						                  |
|                7     8					  |
|								  |
|          9     10                                               |
| 						                  |
|                11    12					  |
|								  |
|                13    14                                         |
|					                          |
|                      15    16					  |
|								  |
|								  |
|    17    18                                                     |
|							          |
|          19    20						  |
|								  |
|								  |
|# do 10 deletes (extract minimums) with print key flag off	  |
|								  |
|# show heap structure						  |
|								  |
|Structure of binomial heap (rotated 90 degrees counterclockwise):|
|								  |
|    13    14                                                     |
|							          |
|          15    16						  |
|								  |
|          17    18                                               |
|						                  |
|                19    20					  |
|								  |
|								  |
|    11    12							  |
|								  |
|								  |
|# do 10 deletes (extract minimums) with print key flag on	  |
|								  |
|Minimum extracted: 11                                            |
|Minimum extracted: 12                                            |
|Minimum extracted: 13                                            |
|Minimum extracted: 14                                            |
|Minimum extracted: 15                                            |
|Minimum extracted: 16                                            |
|Minimum extracted: 17                                            |
|Minimum extracted: 18                                            |
|Minimum extracted: 19                                            |
|Minimum extracted: 20                                            |
|								  |
|# show heap structure (should be empty)			  |
|								  |
|Structure of binomial heap (rotated 90 degrees counterclockwise):|
|								  |
|								  |
|								  |
|# do a delete from empty heap					  |
|Heap Empty							  |
|								  |
|# quit								  |
+-----------------------------------------------------------------+

Displaying The Structure Of A Binomial Heap

Use recursion to display a binomial heap rotated 90 degrees. Since a binomial heap is a linked list of binomial trees, you can recurse through the list until you hit NIL, then print individual binomial trees as you return from each level of the recursion -- this will print them in correct order. Here is the rough idea, using three routines:
   Show-Binomial-Heap(H)
      depth <- 0
      Process-Siblings-Backwards(head[H],depth)

   Process-Siblings-Backwards(x,depth)
      if x not = NIL then
         Process-Siblings-Backwards(sibling[x],depth)
         Show-Binomial-Tree(x,depth)

   Show-Binomial-Tree(x,depth)
      ... you write this ...
Hint: in Show-Binomial-Tree, compute the number of spaces to shift to the right based on depth and print x's key value, then call Process-Siblings-Backwards to handle x's children (which are also in a linked list). You will probably need to print blank "spacing" lines in one or more of the procedures.

What To Hand In

Hand in typescripts like the one given above for the test files: Identify them clearly and draw in the links between nodes printed by your Show-Binomial-Heap operation.

Hand in well-documented code for both your command interpreter and your heap operations, in separate modules. Provide pseudocode for your auxiliary LL-UNLINK-MIN and LL-REVERSE algorithms used in BINOMIAL-HEAP-EXTRACT-MIN. Also provide pseudocode for your Show-Binomial-Tree algorithm.


Page URL: http://www.d.umn.edu /~ddunham/cs4521f05/assignments/a10/assignment.html
Page Author: Doug Dunham
Last Modified: Tuesday, 15-Nov-2005 16:56:00 CST
Comments to: ddunham@d.umn.edu