Homework Solution

Priority Queues

Problems to be Submitted (20 points)

  1. (8 points)

    tree

  2. (2 points)

    tex2html_wrap1365

  3. (10 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


Extra Credit

  1. (2 points)

    Here is a brief explanation. Recursively traverse the tree but only so long as you are at a node which is less than or equal to the given x. If you reach a node which is greater than x, there is no need to traverse deeper in that subtree because all other keys are known to be at least as big as the key at such a node. The overall number of nodes visited will be at most (1+2k), where k is the number of keys actually less than or equal to x.


Last modified: Friday, 29 April 2005