Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 2100
Data Structures

Michael Goldwasser

Fall 2015

Dept. of Math & Computer Science

Homework Assignment 07

Priority Queues and Huffman Codes

Contents:


Overview

Topic: Priority Queues and Huffman Codes
Related Reading: Ch. 7.1-7.3 of the text and Huffman decoding project description
Due: Wednesday, 18 November 2015, 10:00am

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


Collaboration Policy

For this assignment, you must work individually.

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


Problems to be Submitted (20 points)

Preface: Our text describes priority queues as structures with (key,value) pairs as elements. For simplicity, this homework will only pay attention to the key.

  1. (5 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 8.3 as a guide for style (but ignoring values), draw the heap that 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 7.3.5 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 8.3.2. Please draw the contents of an array which represents the tree T you gave in your answer to Problem A.

  3. (5 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!

  4. (8 points)

    The following binary string represents an encoded message using the format described in the upcoming decode programming assignment (for the sake of typesetting, we are breaking up the display to have 24 bits per line, but you should assume they are contiguous).

    000100111010010011011100
    100110011110011011110000
    100110010010011011001001
    100001010011010011000100
    000001001100011100010111
    000110000000010011001010
    100111010101001110010100
    111001111000110010101111
    101001000111101000110010
    001010011001111111110110
    110101110100010111100011
    100001010001010110111100
          

    Decode this message by hand and submit a picture of the Huffman tree as well as the decoded message.


Extra Credit

  1. (2 points)

    Creativity Exercise C-8.13 of the text.


Michael Goldwasser
CSCI 2100, Fall 2015
Last modified: Saturday, 14 November 2015
Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit