You are on page 1of 3

CS 124

Spring 2015: Quiz 1 Review

2/24/2015

For all problems where you are asked to give an algorithm, you must prove the correctness of your
algorithm and establish the best upper bound that you can give for the running time. You should
always write a clear informal description of your algorithm in English. You may also write pseudocode
if you feel your informal explanation requires more precision and detail. As always, try to make your
answers as clear and concise as possible.
Exercise 1. Give a counterexample to the following statement. Then propose an easy fix.
If f (n) and g(n) are positive functions, then f (n) + g(n) = (min(f (n), g(n))

Exercise 2. Given a directed acyclic graph G = (V, E) and two nodes u, v V , calculate the
number of distinct paths from u to v. (Two paths are considered distinct if they have at least 1
vertex not in common)

Exercise 3. A directed graph G = (V, E) is called semiconnected if for each pair of distinct vertices
u, v V , there is either a path from u to v or a path from v to u. Find an algorithm to determine
whether a directed graph is semiconnected.

Exercise 4. Modify Bellman Ford to set dist[v] = for all vertices v that can be reached from
the source via a negative cycle.

Exercise 5. True or False


If G has a cycle with a unique heaviest edge e, then e cannot be part of any MST
The shortest-path tree computed by Dijkstras algorithm is necessarily an MST.
Prims algorithm works with negative weighted edges.
If G has a cycle with a unique lightest edge e, then e must be part of every MST.

Exercise 6. Given a weighted graph with n vertices and m n + 10 edges, show how to compute a
minimum spanning tree in O(n) time.

You might also like