Exam 3 with Solution - Algorithms Data Structure | CP SC 212, Exams of Algorithms and Programming

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

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-cqu
koofers-user-cqu 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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?
pf3

Partial preview of the text

Download Exam 3 with Solution - Algorithms Data Structure | CP SC 212 and more Exams Algorithms and Programming in PDF only on Docsity!

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?

____ (d) (T / F / NA, i.e., not applicable since graph is strongly connected) The graph is weakly connected. ____ (e) (T/F) The graph is a complete graph.

  1. Consider the following linear orderings of graph nodes of G2 (on diagram page). (a) D A G E F C H B I (b) A D E F C H G B I (c) A D E G F B C H I (5) Which of the following is true? Circle only one answer. Only (a) is a topological sort. Only (b) is a topological sort. Only (c) is a topological sort. Both (a) and (b) are topological sorts. Both (a) and (c) are topological sorts. Both (b) and (c) are topological sorts. All three are all topological sorts. None of the above (5) Give one other topological sort of graph G2: _____________________________
  2. (10) Insert the following values into a Skew minHeap. Draw the final heap in the space below. If you need more space, use the back of this sheet. 24 36 45 12 9 16 47 21 16 15 23 46 39
  3. (10) Merge the two binomial queues in Figure 6.59. Draw the merged binomial queue below. 8.. (10) Which of the following trees are binary heaps? If you decide that a tree is not a binary heap, explain why not.
  4. (10) Insert the following values into a Leftist maxHeap. Then answer the questions following: 24, 36, 19, 35, 14, 7, 11, 46 _____ (a) What is the value of the rightmost leaf? _____ (b) What is the parent of node 35? _____ (c) What are the children of node 14? Write null for each null child. _____ (d) Of all nodes with only one child, which node has largest value? _____ (e) What is the height of the tree?
  5. (10) Write a recursive method that returns the sum of all positive values contained in the nodes. That is, if the value in a node is negative or zero, ignore it. int sumPositives(Node t) { } // sumPositives