Solved Test for Algorithms and Data Structures | CP SC 212, Exams of Algorithms and Programming

Material Type: Exam; Class: ALGS/DATA STRUCTURES; Subject: COMPUTER SCIENCE; University: Clemson University; Term: Fall 2005;

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-xfr
koofers-user-xfr 🇺🇸

5

(2)

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 212-302 Name: Answer Key
Test #3, Part B April 20, 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) Consider the graph represented by adjacency matrix M1. Then answer the questions on the
right. The choices (T/F/N) stand for true, false, or not applicable.
2. (10) Consider the
graph represented by the
adjacency list shown in
L2. Apply Dijkstra’s
algorithm to the graph.
Put the final values
produced by the algorithm in the table on the right. Start with node C.
3. (5) Consider graph G3. Give a topological sort of the graph. Put your answer in the space on the
right.
___________________________________________
4. (5) Consider the following Huffman Code: a=110, e=01, t=10, s=111, space=00 and the
same characters in Morse Code: a=.-(dot dash), e=.(dot), t=-(dash), s=...(dot dot
dot). Calculate the number of bits required to represent each of the messages below using each of the
codes.
Number of bits using code
message Huffman Morse
“taste tests tease sate settee” ________ ________
(5) If a message has xa a’s, xe e’s, xt t’s, xs s’s, and xsp spaces, give a formula representing the number of
bits required by each of the codes.
Huffman:
dv pv
A ____ ____
B ____ ____
C ____ ____
D ____ ____
E ____ ____
F ____ ____
____ (a) (T/F/N) The graph is connected.
____ (b) (T/F/N) The graph is strongly connected.
____ (c) What is the outdegree of the node with the greatest outdegree?
____ (d) (T/F/N) Node A is adjacent to all other nodes?
____ (e) (T/F/N) The graph is a complete graph.
____ (f) (T/FN) The graph is directed.
____ (g) (T/F/N) The graph is weighted.
____ (h) (T/F/N) There exists a path of length 25 between nodes B and C.
____ (i) What is the cost of a minimum spanning tree of the graph?
____ (j) What is the cost of the shortest path between node C and node E?
P -> T -> Y Z -> P
Y -> T -> W Q -> L
X -> Y -> W L -> T
W -> L -> Q T = null
pf3
pf4

Partial preview of the text

Download Solved Test for Algorithms and Data Structures | CP SC 212 and more Exams Algorithms and Programming in PDF only on Docsity!

CPSC 212-302 Name: Answer Key

Test #3, Part B April 20, 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) Consider the graph represented by adjacency matrix M1. Then answer the questions on the right. The choices (T/F/N) stand for true, false, or not applicable.
  2. (10) Consider the graph represented by the adjacency list shown in L2. Apply Dijkstra’s algorithm to the graph. Put the final values produced by the algorithm in the table on the right. Start with node C.
  3. (5) Consider graph G3. Give a topological sort of the graph. Put your answer in the space on the right. ___________________________________________
  4. (5) Consider the following Huffman Code: a=110, e=01, t=10, s=111, space=00 and the same characters in Morse Code: a=.-(dot dash), e=.(dot), t=-(dash), s=...(dot dot dot). Calculate the number of bits required to represent each of the messages below using each of the codes. Number of bits using code message Huffman Morse “taste tests tease sate settee” ________ ________ (5) If a message has xa a ’s, xe e ’s, xt t ’s, xs s ’s, and xsp spaces , give a formula representing the number of bits required by each of the codes. Huffman: dv pv A ____ ____ B ____ ____ C ____ ____ D ____ ____ E ____ ____ F ____ ____ ____ (a) (T/F/N) The graph is connected. ____ (b) (T/F/N) The graph is strongly connected. ____ (c) What is the outdegree of the node with the greatest outdegree? ____ (d) (T/F/N) Node A is adjacent to all other nodes? ____ (e) (T/F/N) The graph is a complete graph. ____ (f) (T/FN) The graph is directed. ____ (g) (T/F/N) The graph is weighted. ____ (h) (T/F/N) There exists a path of length 25 between nodes B and C. ____ (i) What is the cost of a minimum spanning tree of the graph? ____ (j) What is the cost of the shortest path between node C and node E? P -> T -> Y Z -> P Y -> T -> W Q -> L X -> Y -> W L -> T W -> L -> Q T = null

Morse:

(10) Genetic Algorithms. Consider the following chromosome representing a solution to the traveling salesman problem. Evaluate the tour cost using the adjacency matrix shown on the left. Note that a solution to the traveling salesman problem requires that the salesman returning to the starting city. 0 1 2 3 4 5 6 7 0 0 2 5 8 1 3 2 6 chromosome: 1 3 0 5 8 1 3 2 6 5 2 3 7 1 4 0 6 tour cost: _____ 2 2 5 0 1 3 2 6 3 3 3 4 1 0 3 5 1 6 4 8 4 5 8 0 3 2 6 5 3 3 7 8 1 0 5 6 6 3 9 6 8 1 3 0 6 7 6 4 5 8 8 3 7 0 Now use the chromosomes to generate two offspring using one-point crossover. The crossover point is marked below. 1 2 4 5 0 | 3 7 6 offspring #1: _________________________ 3 5 6 2 1 | 7 4 0 offspring #2: _________________________

  1. Weiss, p. 277. Consider the following array a[] representing a disjoint set of 10 nodes. i : 0 1 2 3 4 5 6 7 8 9 a[i]: -1 -1 -1 -1 -1 -1 -1 -1 -1 - Use the union method on the left to execute the union operations shown on the right. public void union ( int root1, int root 2) { if (s[root2] < s[root1]) s[root1] = root2; else { if (s[root1] == s[root2]) s[root1]--; s[root2] = root1; } // else } // union union(3,4); union(2,5); union(1,7); union(1,3); union(0,2); union(1,2); union(8,9); union(1,8);
  2. (10) Apply Kruskal’s algorithm to graph G below. Draw the final spanning tree produced by the algorithm in the space on the right. Graph G5 (undirected graph) M F K E H G N P R T M 4 5 6 F 2 1 3 K 5 3 E 4 2 3 H 1 5 4 G including 6 4 N symmetric 2 P edges 7 R 2 T minimum spanning tree cost: ______
  3. (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 5. When given a choice of nodes to visit, visit the nodes in increasing order. Graph G6 (directed graph) 1 2 3 4 5 6 7 8 9 10 11 1 1 2 3 1 1 1 4 1 1 5 4 6 6 2 7 7 1 1 8 1 9 10 7 1 11 1

union-by-height

  1. M1 = 0 1 0 1 M2 = 1 0 1 1 M4 = 3 2 2 3 1 0 0 0 0 1 0 1 1 2 1 2 1 1 0 0 1 1 0 1 2 2 2 3 0 0 1 1 1 1 1 1 3 3 2 4