CS 170, Midterm 1, Fall 1999
CS 170, Fall 1999
Midterm 1
1. (15 points)
We are running one of these three algorithms on the graph below, where the algorithm has
already "processed" the bold-face edges. (Ignore the directions on the edges for Prim's and Kruskal's
algorithms.)
●
Prim's for the minimum spanning tree, starting from S.
●
Kruskal's for the minimum spanning tree.
●
Dijkstra's for shortest path from S.
Which two edges would be added next in Prim's algorithm? Be sure to indicate the order in which they
are added.
Answer: First (A,B) is added and then (C,F).
Which two edges would be added next in Kruskal's algorithm? Be sure to indicate the order in which
they are added.
Answer: First (F,G) is added and then (A,B).
At this point in the running of Dijkstra's algorithm, S has been taken off the top of the heap and marked.
Which four vertices would be marked next in Dijkstra's algorithm, i.e. deleted from the top of the heap?
Be sure to indicate the order in which they are deleted. Which final edges would Dijkstra's algorithm
choose as part of the shortest path to these vertices (i.e. which edge connects to this vertex as part of the
shortest path from S)?
Answer: (1) C is marked, with edge (S,C). (2) A is marked, with edge (S,A).
(3) D is marked with edge (S,D). (4) F is marked with edge (C, F).
2. (25 points)
Let G = (V, E) be a directed graph where every edge E has weight w(E), which may be
positive, negative, or zero. The
benefit
of a path consisting of edges E1,E2,.
..Ek is defined as min( w(Ei)
for 1<=i<=k ).
Give an algorithm which computes the
maximum benefit
path from a given vertex s to another vertex f.
file:///C|/Documents%20and%20Settings/Jason%20Raft.
..-%20Fall%201999%20-%20Demmel%20-%20Midterm%201.htm (1 of 4)1/27/2007 5:32:58 PM