Professional Documents
Culture Documents
Islamabad Campus
Department of Computer Science
Question # 3
a) Place the words
Old programmers never die
They just lose their memories
In the order in which they appear, in a Max heap and Min Heap. Show your work step by step
b) List the order in which the nodes are processed using pre-order, in- order, and post- order traversal of Max
heap and Min heap constructed in part (a
c) Delete the node representing the word “old” from Max heap and Min heap constructed in part a)
d) Insert new word “young” in Max heap and Min heap resulting in part c). Show your work step by step
e) Sort the Max heap and Min heap using heap sort. Show your work step by step.
Question # 4
a) Create a Huffman tree to determine the binary codes for each character in the following text:
Old programmers never die
They just lose their memories
Character Frequency Huffman Code
A. We use Huffman's algorithm to obtain an encoding of alphabet {a, b, c} with frequencies fa , fb , fc.
In each of the following cases, either give an example of frequencies (fa , fb , fc) that would yield the
specified code, or explain why the code cannot possibly be obtained (no matter what the frequencies
are).
(a) Code: {0, 10, 11}
(b) Code :{ 0, 1, 00}
(c) Code: {10, 01, 00}
B. Under a Huffman encoding of n symbols with frequencies f1; f2; ……… ; fn, what is the longest a codeword
could possibly be? Give an example set of frequencies that would produce this case.
C. Consider the following 21 character message that consists of 3 a’s, 7 c’s, 6 t’s, and 5 g’s:
aaccccacttgggttttccgg
Are the following 43 bits a possible Huffman encoding of the message above?
0000001111000101010010010010101010111001001
Justify your answer as concisely and rigorously as possible.(No need to draw the Huffman tree)
character code
a 00
b 01
c 101
d x10
e yz1
Where x, y, z are in {0,1}. Determine x, y and z so that the given code is a prefix code
E. Write a frequency list that the Huffman code of this frequency would deterministically create the
following structure.