Homework 9 Problems
CompSci 161—Spring, 2026—Dillencourt
(Note that there are no problems from the zyBook on this homework assignment.
Problems:
Consider the undirected weighted graph G shown below:
29
B
22
26
19
8
D
E
12
18
7
30
A
14
24
C
15
27
F
G
9
1
H
K
6
11
I
28
3
23
5
J
25
1. Run Dijkstra’s shortest path algorithm on graph G, with start vertex A. Compute the shortest-path
tree (represented by parent pointers) and the length of the shortest path from A to each vertex.
Then answer the following questions.
(a) Draw the shortest-path tree
(b) What is the length of the shortest path from vertex A to vertex D?
(c) What is the parent of vertex D in the shortest path tree?
(d) What is the length of the shortest path from vertex A to vertex G?
(e) What is the parent of vertex G in the shortest path tree?
(f) What is the length of the shortest path from vertex A to vertex J?
(g) What is the parent of vertex J in the shortest path tree?
2. Run the Prim-Jarník minimum-spanning tree algorithm on graph G, with start vertex A. Keep
track of the order in which you add edges to the minimum-spanning tree. Then answer the following
questions.
(a) Draw the minimum spanning tree.
(b) What is the weight of the first edge added to the minimum spanning tree?
(c) What is the weight of the second edge added to the minimum spanning tree?
(d) What is the weight of the fifth edge added to the minimum spanning
(e) What is the weight of the last edge added to the minimum spanning tree?
1
3. Run Kruskal’s minimum-spanning tree algorithm on graph G. Keep track of the order in which you
add edges to the minimum-spanning tree. Then answer the following questions.
(a) Draw the minimum spanning tree.
(b) What is the weight of the first edge added to the minimum spanning tree?
(c) What is the weight of the second edge added to the minimum spanning tree?
(d) What is the weight of the fifth edge added to the minimum spanning
(e) What is the weight of the last edge added to the minimum spanning tree?
2