1501midterm Practice Questions KEY
1501midterm Practice Questions KEY
KEY
1/4
1. ( 12 points ) Consider using Huffman encoding to compress the following string:
“DONTTELLMEILLTELLYOU”.
Show the following:
ANSWER:
20
12
4 4
6
2 2 2
T E L O D N M I Y U
3 3 6 2 1 1 1 1 1 1
2/4
2. ( 14 points ) Consider the alphabet {A, B, E, N}.
Construct a de la Briandais trie over this alphabet containing the following words:
Be sure to make the details clear, such as how complete keys are differentiated from prefixes,
and how references are organized in the node.
ANSWER:
Either of these two would be a valid solution:
value
null
next
B N
value
value
null null
next
next
E A A
value
value
value
null null null
next
next
next
E A N E B
value
value
value
value
value
next
next
next
next
N N
value
value
True True
next
next
3/4
B N
E A A
E A N E B
^ N N ^ ^ ^
^ ^
i. Show the state of an array-backed min heap after inserting the following numbers in the
order shown.
14, 5, 7, 3, 15, 1
ii. Show the state of the array-backed heap after performing one removal.
iii. Show the state of the array-backed heap after performing a second removal.
ANSWER:
Operation
Inserts 1 5 3 14 15 7
Remove (1) 3 5 7 14 15
Remove (3) 5 14 7 15
4/4