CS 205 Quiz #8A Nov 20, 2012
NAME: __________________________________________________________________________
RUID:___________________________________________________________________________
Electronic Devices are not permitted during the quiz. These include but are not restricted to calculators,
computers and cell phones.
No communication between students or anyone outside of class is permitted during the quiz.
Textbooks, notes and any other written materials are not permitted during the quiz.
DO NOT OPEN UNTIL
INSTRUCTED TO DO SO
1. For each of the following trees, write True if it is a binary search tree where items are maintained
in alphabetical order. Otherwise, write False.
_____________ a)
_____________ b)
_____________ c)
_____________ d)
2. For each of the following codes, write True if it is a prefix code. Otherwise, write False.
________________ a)
a: 11, e: 00, t: 10, s: 01
________________ b)
a: 0, e: 1, t: 01, s: 001
________________ c)
a: 101, e: 11, t: 001, s: 011, n: 010
________________ d)
a: 010, e: 11, t: 011, s: 1011, n: 1001, i: 10101
3. For each of the following codes, compute the average number of bits to encode a single character if
the character frequencies are as shown. Additionally, specify whether or not the code is a Huffman
code (write True if it is a Huffman Coding, otherwise write False).
a)
code:
frequencies:
a:
10,
a: 0.1,
b:
11
b: 0.9
Average Bits: ____________________
b)
code:
frequencies:
a:
10,
a: 0.2,
b:
Huffman Code: ________________
11,
b: 0.3,
c:
c: 0.5
Average Bits: ____________________
c)
code:
frequencies:
Huffman Code: ________________
a: 110000,
b:
01,
c: 001
a:
b: 0.5,
c: 0.4
0.1,
Average Bits: ____________________
Huffman Code: ________________
4. Consider the following tree rooted at node a.
For each of the blanks below, select the correct visitation order of vertices for the specified type of
traversal.
A) a, b, c, d, e, f, g, h
B) a, b, e, c, d, f, g, h
C) h, g, f, e, d, c, b, a
D) a, e, b, f, d, c, h, g
E) a, b, c, d, e, f, g, h
F) h, g, f, d, c, e, b, a
G) h, g, f, e, d, c, b, a
H) g, h, c, d, f, b, e, a
I) c, b, d, a, f, g, h, e
J) c, d, g, h, b, f, a, e
K) h, g, e, f, a, d, b, c
L) c, d, b, g, h, f, e, a
M) c, d, b, f, g, h, e, a
N) c, b, d, a, e, g, f, h
O) h, g, f, e, d, c, b, a
P) h, f, g, e, a, d, b, c
Q) That type of traversal is impossible for this tree
R) None of the above answers is correct
_____________ i) Preorder Traversal
_____________ ii) Inorder Traversal
_____________ iii) Postorder Traversal
5. Compute the value of each of the following expressions assuming each is in prefix, infix or postfix
notation as indicated. (As in the book, indicates exponentiation.) If the value cannot be
computed due to lack of operators or lack of operands, write Impossible.
_____________ a) Prefix: + - * 2 3 5 / 2 3 4
_____________ b) Prefix: - * / 15 - 7 + 1 1 3 + 2 + 1 1
_____________ c) Infix: ((3 + 1) (4 2)) + ((7 4)/3)
_____________ d) Infix: 5 + ((2 + 7) * ((5 3) 0))
_____________ e) Postfix: 7 2 3 * - 4 9 3 / +
_____________ f) Postfix: 9 3 / 5 + 7 2 - *
Scratch Paper