CPSC 212-302 Test Part B Solutions, Exams of Algorithms and Programming

Solutions to part b of test 3 for cpsc 212-302 computer science class. It includes answers to questions related to graphs, topological sort, huffman tree, kruskal's and prim's algorithm, and depth-first and breadth-first search. Students are advised to use these solutions as study notes and to understand the thought process behind each answer.

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-6ta
koofers-user-6ta 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 212-302 Name: _____________________________
Test #3, Part B April 26, 2006
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) How many edges does an undirected complete graph with N nodes have? Be precise. Your answer
should be expressed in terms of N. The graph is undirected so edge (u,v) = (v,u) is counted only once.
Explain clearly how you arrived at your answer (you will get at most one point credit if all you give me is
your final answer).
2. (10) Apply Dijkstra’s algorithm to graph G1. Put the final values produced by the algorithm in the table
below. Start with node 4.
dv pv G1:
0 ____ ____
1 ____ ____
2 ____ ____
3 ____ ____
4 ____ ____
5 ____ ____
3. (5) Topological Sort. Consider graph G2. Which of the following is not a topological sort of G2? Mark
each with an “X”.
___ PAMONBCKHJIGFKDE
___ APBCDMLONHJIFGKE
___ PONABMLCDHIJGFKE
___ ABPMONCDHJILKGFE
___ POANBMHGCLJIFKDE
pf3
pf4

Partial preview of the text

Download CPSC 212-302 Test Part B Solutions and more Exams Algorithms and Programming in PDF only on Docsity!

CPSC 212-302 Name: _____________________________

Test #3, Part B April 26, 2006

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) How many edges does an undirected complete graph with N nodes have? Be precise. Your answer

should be expressed in terms of N. The graph is undirected so edge (u,v) = (v,u) is counted only once.

Explain clearly how you arrived at your answer (you will get at most one point credit if all you give me is

your final answer).

2. (10) Apply Dijkstra’s algorithm to graph G1. Put the final values produced by the algorithm in the table

below. Start with node 4.

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

3. (5) Topological Sort. Consider graph G2. Which of the following is not a topological sort of G2? Mark

each with an “X”.

___ PAMONBCKHJIGFKDE

___ APBCDMLONHJIFGKE

___ PONABMLCDHIJGFKE

___ ABPMONCDHJILKGFE

___ POANBMHGCLJIFKDE

4. (a) (7) Consider the following frequency table. Draw the Huffman Tree. Recall that when merging two

subtrees, the root with the smaller frequency should go on the left.

a 5 e 10 t 9 s 6 r 4 m 3 sp 12

(b) (3) Use your tree to decode the message: 01111000101101111 _________________________

5. (10) Apply Kruskal’s algorithm to graph G5 below. Draw the final spanning tree produced by the

algorithm in the space on the right. Show clearly how you arrived at your answer!

6. (10) Apply Prim’s algorithm to graph G5 above. Start with node 1. Draw the final table in the space

provided.

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