Docsity

CS170 First Midterm Exam September 1999, Exams of Algorithms and Programming

Toggle sidebar
bg1
~
CS170 First Midterm 23 Sep 1999
NAME:
TA:
Key (see below):
Be clear and concise. You may use the number of points assigned to each problem as a
rough estimate for the number of minutes you want to allocate to the problem. The total
number of points is 80.
This exam is closed book/closed computer, but you are allowed one sheet of paper
(2 sides) for notes to use during the exam. You are allowed to use, without proof, any
results proven in class, lecture notes, homework, or the book, but you must state clearly
what result you are using.
We are no longer allowed to post grades using SIDs, because of privacy rulings.
So we ask you to pick a key that we will use to post your grades on-line. Pick something
you can remember, that does not identify you personally, and that is very likely to be
unique. Try adding the last 3 digits of your SID to guarantee uniqueness.
CS170First MidtermJ3 Sep 1999
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download CS170 First Midterm Exam September 1999 and more Exams Algorithms and Programming in PDF only on Docsity!

~ CS170 First Midterm 23 Sep 1999

NAME:

TA:

Key (see below):

Be clear and concise. You may use the number of points assigned to each problem as a rough estimate for the number of minutes you want to allocate to the problem. The total number of points is 80. This exam is closed book/closed computer, but you are allowed one sheet of paper (2 sides) for notes to use during the exam. You are allowed to use, without proof, any results proven in class, lecture notes, homework, or the book, but you must state clearly what result you are using. We are no longer allowed to post grades using SIDs, because of privacy rulings. So we ask you to pick a key that we will use to post your grades on-line. Pick something you can remember, that does not identify you personally, and that is very likely to be unique. Try adding the last 3 digits of your SID to guarantee uniqueness.

  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 paths from S.
  1. ( 25 points ) Let G = (V, E) be a directed graph where every edge e has a weight w(e), which may be positive, negative, or zero. The benefit of a path consisting of edges e1, e2, ... e k is defined as min 1 ≤ i ≤ k w(e i ).

Give an algorithm which computes the maximum benefit path from a given vertex s to another vertex f. For example, if there are two paths from s to f , where Path 1 has edge weights -1, -2, -3 and Path 2 has edges weights -4, 10, 20, then Path 1 has benefit -3 and Path 2 has benefit -4, so Path 1 has the maximum benefit: -3 = max(-3,-4). Your algorithm should be as efficient as possible.

A. Brief description or pseudocode

B. Justification of correctness.

C. Running time and justification. You may refer to analyses done in class without proof.

  1. ( 15 points )

True or false? No explanation required. except for partial credit. Each correct answer is worth 1.5 points, but 1.5 points will be subtracted for each wrong answer, so answer only if you are reasonably certain.

(a) n 2+sin^ n = O( n^2 )

(b) Dijkstra’s algorithm can fail if there are zero edge weights along with positive ones.

(c) Let G be an undirected, weighted graph. Running an MST algorithm on each biconnected component of G, and then adding the bridge edges to the set of MSTs of each biconnected component, results in a combined MST for the whole graph.

(d) Let G = (N,E) be an undirected graph. Let N = N 1 ∪N 2 be a partition of N into nonempty disjoint subsets, and G i the graph consisting of N i and all edges from E with both endpoints in N i. Let T i be an MST of G i. Then one can construct an MST T of G by connecting T 1 and T 2 by the shortest edge connecting N 1 and N 2.

(e) , if r > 0 and s > 0.