Assignments | Class Photo | Computing Resources | Course Home | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 180
Data Structures

Michael Goldwasser

Spring 2009

Dept. of Math & Computer Science

Homework Assignment 06

Priority Queues

Contents:


Overview

Topic: Priority Queues
Related Reading: Ch. 7.1-7.3 of the text.
Due: Friday, 24 April 2009, 10:00am

Please make sure you adhere to the policies on academic integrity.


Practice Problems


Problems to be Submitted (20 points)

Preface: In terms of a programming implementation, it is important to keep in mind that items inserted into a priority queue are represented as a (key,element) pair. For simplicity, this homework will only pay attention to the key.

  1. (8 points)

    Assume that we start with an initially empty heap, and that items are inserted with the following sequence of integer keys:

    insert(12), insert(7), insert(14), insert(5), insert(20), insert(11), insert(6), insert(18), insert(8), insert(3), insert(17), insert(13), insert(4), insert(9).
    Using Figure 7.3 as a guide for style, draw the heap which results at the very end of the last operation.

    Note: for this problem we are not requiring you to show any of the work along the way, though you may if you wish. Please do be careful to follow the exact sequence given and to double-check your work.

  2. (2 points)

    Chapter 6.4.1 of the text discusses a vector-based representation of a binary tree T based on a level numbering of the nodes of T. The use of this representation for heaps is discussed further in Chapter 7.3.2. Please draw the contents of an array which represents the tree T you gave in your answer to Problem A.

  3. (10 points)

    Consider the heap given below using the vector-based representation of a binary tree T.

    index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  
    Value   3 6 9 12 8 18 11 20 13 17 24 23 22 15 26 21 25 27 16  

    For this problem, we want you to draw the five heaps which result at the end of each of the following operations. Your answers should also be drawn using the vector-based representation.

          removeMin()
          removeMin()
          removeMin()
          removeMin()
          removeMin()
          

    Note: in your own personal scratchwork, you might convert the heaps to the more natural tree representation, perform the operation, and then convert back to the vector in reporting your answer. However with a bit of practice, you should be able to perform the operations directly on the vector-based representation!


Extra Credit

  1. (2 points)

    Creativity Exercise C-7.15 of the text.


Michael Goldwasser
CSCI 180, Spring 2009
Last modified: Thursday, 14 April 2005
Assignments | Class Photo | Computing Resources | Course Home | Lab Hours/Tutoring | Schedule | Submit