
CPSC 212-1 Name: _______________________
Test #3 August 2, 2004
Closed books. Closed notes. Calculators OK. 105 points. 90 minutes. Weight of each question in
parentheses. Please use a pencil.
1. a) (5) Given the following frequency counts of the letters listed, develop a Huffman Code for each
of the letters. Show how you arrived at your answer.
letter: a b c d e f g
frequency: 5 8 14 6 2 11 10
letter: a b c d e f g
Huffman Code: _____ _____ _____ _____ _____ _____ _____
b) (2) Given the following Huffman Code, draw the Huffman tree from which it was generated.
letter: a b c d e f k
Huffman Code: 001 01 10 00000 0001 11 00001
c) (3) Using the Huffman Code in part b) above, decode the following String:
0100010000000011000001000100000
2. (10) Write a non-recursive segment of pseudo-code for breadth-first search. (Note: Your pseudo-code
should contain enough detail for a CPSC 212 student to be able write Java code directly from it.) Put your
answer on the back of this sheet. The signature of the method is shown below:
void bfs (Vertex v);
3. Consider the graph represented by the following adjacency matrix:
M: 0 1 0 1 1 0 a) (5) Draw the graph: 0 1
0 0 1 0 1 0
1 0 1 0 0 1
0 1 0 0 1 0 2 4
0 0 0 1 0 1 3
1 0 1 0 1 0
5
b) (4) Draw the equivalent adjacency list.
c) (3) Conduct a depth-first search of the graph, starting with node 3. Visit the nodes in preorder (i.e.,
“visit when you push”).
d) (3) Conduct a breadth-first search of the graph, starting with node 4.
4. (10) Consider the graph G1 shown on the diagram page. Then answer the questions below.
____ (a) (T/F) The graph is strongly connected.
____ (b) What is the indegree of node B.
____ (c) What is the cost of the shortest path between nodes E and D?