CS 4521 Fall Semester, 2009

20 Points

**
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:

- BINOMIAL-LINK
- MAKE-BINOMIAL-HEAP (a constructor in C++)
- BINOMIAL-HEAP-MERGE
- BINOMIAL-HEAP-UNION
- BINOMIAL-HEAP-INSERT
- BINOMIAL-HEAP-MINIMUM
- BINOMIAL-HEAP-EXTRACT-MIN

- unlinking the node with minimum key from a linked list
- reversing a linked list

You can use a modified version of the command interpreter
for binary heaps (in Assignment 4); as in that assignment,
** i**,

+-----------------------------------------------------------------+ |# construct empty heap (this is already done in the command interpreter) | | |# 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 extract mins 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 extract mins 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 an extract min from empty heap | |Heap Empty | | | |# quit | +-----------------------------------------------------------------+

ShowHeap( x, depth ) if ( sibling[x] != NIL ) then |> Do sibling list first ShowHeap( sibling[x], depth ) |> May have to print a blank line here if ( ( child[x] != NIL ) or ( p[x] = NIL ) ) then print key[x] shifted 6*depth + 4 spaces |> First key on a line if ( child[x] = NIL ) print a blank line |> Special case else print key[x] shifted 6 spaces, then a blank line |> Last key on line if ( child[x] != NIL ) then |> Take care of children last ShowHeap( child[x], depth + 1 )And

ShowBinomialHeap(H) print "Stucture of binomial heap (rotated 90 degrees ccwise):" if ( head[H] = NIL ) then print "Empty heap" else ShowHeap( head[H], 0 )You may have to adjust the formatting to get good looking output.

** Helpful code: **
Here is a
.h file for the Binomial Heap (BHeap) class
** binomheap.h**.
and skeleton code for the BHeap class implementation

Also hand in the following:

- Well-documented code for both your command interpreter and your heap operations, in separate modules.
- Pseudocode for your BINOMIAL-HEAP-EXTRACT-MIN.