Read sections 7.1-7.6 in chapter 7 of the textbook Explorations in Computing and chapter 3 of Blown To Bits. Because of its timing this homework covers 3 different topics: data structures that we did not cover in ps6, data representation and some Boolean logic and logic gates. Therefore, it is worth 14 points as opposed to 10 points. You have a long time to complete it but we advise you to start early so that you have enough time to think about each question and ask questions to course staff if needed.
59 24 35 78 61 42 90 88 15 57
vertices = ["New York", "Pittsburgh", "Los Angeles", "Dallas", "Atlanta"] edges = [ [∞, 5, 2, 6, 1], [5, ∞, 8, ∞, 3], [2, 8, ∞, 7, 4], [6, ∞, 7, ∞, 9], [1, 3, 4, 9, ∞] ]
01000011
11000011
10000000
Once you decode the word, you can use RubyLabs to check your answer:
>> include BitLab => Object >> f = read_frequencies(:hafreq) => {"K"=>0.106, "W"=>0.009, "L"=>0.044, ... } >> tree = build_tree(f) => { 1.000 { 0.428 { 0.195 { ... } } } } >> hc = assign_codes(tree) => {"K"=>001, "W"=>110010, "A"=>10, ... } >> encode(INSERT_YOUR_ANSWER_HERE, tree) => 0001011000111110000100110
See sections 7.4 and 7.5 for more information on how to build a Huffman tree, and how to encode and decode messages using RubyLabs.
(NOTE: Be sure you understand what each of the steps are doing above. Read through the relevant sections for a thorough explanation and try out the tutorial in the textbook for yourself.)
A 0000 U 0100 L 1000 W 1100 E 0001 ' 0101 M 1001 I 0010 H 0110 N 1010 O 0011 K 0111 P 1011
Go to Popular Hawaiian Words and Phrases and scroll down to the vocabulary list at the end. Find a word that would be longer if encoded with the Huffman tree than with the 4-bit fixed-width code above. (Hint: look at words that use lots of low-frequency letters.) Give the encoding using the Huffman tree and the 4-bit fixed-width code above to justify your answer.
(X and Y) or (Y and (not Z)) (not (X or (not Y))) and Z
i = 0 sum = 0 while i != 10 do sum = sum + i i = i + 1 end
We can also write this code equivalently using an until loop:
i = 0 sum = 0 until i == 10 do sum = sum + i i = i + 1 end
Use DeMorgan's Law to convert the following while loops to equivalent until loops.
while (x >= 40) and (y < 68) do ... end
while (a != 15) or (b == 110 and c <= 112) do ... end