Homework Solution

Priority Queues

Problems to be Submitted (20 points)

  1. (5 points)

    tree

  2. (2 points)

    tex2html_wrap1365

  3. (5 points)

    We will highlight the downheap bubbling which took place at each stage.

    Here is the original heap:

    tabular15

    After first call to removeMin() (which removes '3'):

    tabular73

    After second call to removeMin() (which removes '6'):

    tabular146

    After third call to removeMin() (which removes '8'):

    tabular276

    After fourth call to removeMin() (which removes '9'):

    tabular406

    After fifth call to removeMin() (which removes'11'):

    tabular536

  4. (8 points)

    The encoded message is: congratulations. get coding.

    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
          

Last modified: Thursday, 19 November 2015