We will highlight the downheap bubbling which took place at each stage.
Here is the original heap:
After first call to removeMin() (which removes '3'):
After second call to removeMin() (which removes '6'):
After third call to removeMin() (which removes '8'):
After fourth call to removeMin() (which removes '9'):
After fifth call to removeMin() (which removes'11'):
The encoded message is:
The tree appears as follows:
Here is a color-coded view of the original input. For the
first portion, the black digits represent the internal and
external nodes, with the red sections the 9-bit data for each
external node. The second portion contains the coded message,
alternating between blue and black at each character break.
000100111010010011011100
100110011110011011110000
100110010010011011001001
100001010011010011000100
000001001100011100010111
000110000000010011001010
100111010101001110010100
111001111000110010101111
101001000111101000110010
001010011001111111110110
110101110100010111100011
100001010001010110111100