Docsity

Exam with Answer Key - Algorithms and Data Structures | CP SC 212, Exams of Algorithms and Programming

Toggle sidebar
bg1
CPSC 212-301 Name: Answer Key
Test #3, Part B November 30, 2005
Closed books. Closed Notes. Calculators OK. 85 points. 60 minutes. The weight of each question is
indicated in parentheses. Please use a pencil. If you need more space, use the back of the sheet.
1. (10) Definitions. Consider graph G1. Then answer the following questions.
____ (a) (T/F) The graph is strongly connected. G1:
____ (b)What is the cost of the shortest path between nodes C and E?
____ (c) Which node has the greatest outdegree?
____ (d) A is adjacent to which nodes?
____ (e) (T/F) The graph is a complete graph.
2. (10) Apply Dijkstra’s algorithm to graph G2. Put the final
values produced by the algorithm in the table below.
Start with node 0.
dv pv G2:
0 ____ ____
1 ____ ____
2 ____ ____
3 ____ ____
4 ____ ____
5 ____ ____
3. (10) Consider graph G3. For each of the following sequences of nodes, mark with a “T” those
which represent a topological sort of the
graph and with an “X” those which do not.
_____ (a) A B C D E I G F H G3:
_____ (b) A B C E D I G F H
_____ (c) A B C E D G F I H
_____ (d) A B C E D F I G H
_____ (e) A B C I E G D F H
4. (5) Your friend says that he used the following Huffman Code: a=110, e=01, t=101, s=011
to generate this encoded message: 10111001110101. Can you decode his message? If so, what is his
message? If not, explain precisely why you cannot.
pf3

Partial preview of the text

Download Exam with Answer Key - Algorithms and Data Structures | CP SC 212 and more Exams Algorithms and Programming in PDF only on Docsity!

CPSC 212-301 Name: Answer Key

Test #3, Part B November 30, 2005

Closed books. Closed Notes. Calculators OK. 85 points. 60 minutes. The weight of each question is

indicated in parentheses. Please use a pencil. If you need more space, use the back of the sheet.

1. (10) Definitions. Consider graph G1. Then answer the following questions.

____ (a) (T/F) The graph is strongly connected. G1:

____ (b)What is the cost of the shortest path between nodes C and E?

____ (c) Which node has the greatest outdegree?

____ (d) A is adjacent to which nodes?

____ (e) (T/F) The graph is a complete graph.

2. (10) Apply Dijkstra’s algorithm to graph G2. Put the final

values produced by the algorithm in the table below.

Start with node 0.

dv pv G2: 0 ____ ____ 1 ____ ____ 2 ____ ____ 3 ____ ____ 4 ____ ____ 5 ____ ____

3. (10) Consider graph G3. For each of the following sequences of nodes, mark with a “T” those

which represent a topological sort of the

graph and with an “X” those which do not.

_____ (a) A B C D E I G F H G3:

_____ (b) A B C E D I G F H

_____ (c) A B C E D G F I H

_____ (d) A B C E D F I G H

_____ (e) A B C I E G D F H

4. (5) Your friend says that he used the following Huffman Code: a=110, e=01, t=101, s=

to generate this encoded message: 10111001110101. Can you decode his message? If so, what is his

message? If not, explain precisely why you cannot.

5. (10) Consider the sorted list of edges of graph G5, represented by the ordered pairs below. The

weight of an edge is shown beside each ordered pair. Apply Kruskal’s algorithm using the set of edges

as shown. Draw the final spanning tree produced by the algorithm in the space on the right.

wt(edge) wt (edge) 1 (1,4) 4 (3,4) 2 (4,5) 5 (2,2) 2 (1,5) 5 (1,2) 2 (1,3) 5 (3,5) 3 (2,5) 6 (0,2) 3 (0,1) 6 (0,4) minimum spanning tree cost: ______

6. (10) Consider graph G6. In what order are the nodes of the graph visited in a depth-first preorder

traversal of the graph? Start with node D. When given a choice of nodes to visit, visit the nodes in

alphabetical order.

7. (10) Consider the same graph G6. In what order are the nodes of the graph visited in a breadth-

first search of the graph? Start with node A. When given a choice of nodes to visit, visit the nodes in

alphabetical order.

8. (10) Consider a single-queue, multiple-server event-driven simulation for an airline counter at the

airport. Suggest an appropriate variable type (such as int, float, String, etc.), storage structure (such as

array, arraylist or vector), or data structure to represent each of the following simulation values or

components. Be specific.

event queue _____________________________

airline employees at counter _____________________________

clock (assume seconds) _____________________________

customer queue _____________________________

average queue length _____________________________