2021 Spring Final
2021 Spring Final
Final
• The exam has 6 questions, is worth 100 points, and will last 180 minutes.
• The questions start with true/false and short answer, and end with long answer. The problems may
not necessarily follow the order of increasing difficulty.
• Good luck!
CS 170, Spring 2021 Final A. Chiesa & J. Demmel
(a) In a zero-sum game, it’s possible for Player 2 to give Player 1 an advantage by announcing her strategy
prior to the game.
(b) In a zero-sum game, it’s possible for Player 2 to give Player 1 an advantage by announcing an optimal
Player 2 strategy prior to the game.
(c) Suppose the SCC algorithm on some graph returns the SCCs in the order: {G, H, I, J, K, L}, {D}, {C,
F}, {B, E}, {A}. Then, it is guaranteed that in the first DFS (the one done on G R ), Postorder(H) >
Postorder(D).
(d) There exists an algorithm using O(log n) space to compute the mean of a stream of n integers, each in
[0, n].
(e) If you find a polynomial time algorithm for an NP problem, then you’ve proved P = NP.
(f) If you find a polynomial time algorithm for an NP-complete problem, then you’ve proved P = NP.
(g) Consider h1 ( x ) = x and h2 ( x ) = 1 + ( x (mod 4)), both from {1, 2, . . . , 24} to itself. Then H = { h1 , h2 }
is universal.
(h) There is guaranteed to exist an O(n3 ) solution to the Vertex Cover problem if P = NP.
(i) Suppose that a Monte-Carlo algorithm A exists for a problem which always runs in time T (n) returns
a correct answer with probability 12 . Then there exists a Las-Vegas algorithm that solves the problem
in expected time 2T (n). (Assume a correct answer can be verified in constant time.)
2
CS 170, Spring 2021 Final A. Chiesa & J. Demmel
3
CS 170, Spring 2021 Final A. Chiesa & J. Demmel
(a) Describe your subproblems, the corresponding recurrence relation / base cases, and in what order to
compute them. Also state how to compute the maximum possible coolness of the party from your
subproblems.
(b) Give a runtime analysis for your algorithm in terms of N (the number of Dunder Mifflin employees).
(a) Give a reduction from RHP to RHC which has runtime polynomial in |V | and | E|. Justify correctness.
Hint: Given an RHP instance G, consider adding a dummy vertex d.
(b) Give a reduction from RHC to RHP which has runtime polynomial in |V | and | E|. Justify correctness.
Hint: Given an RHC instance G, consider duplicating a vertex in G and also adding dummy vertices s, t.
(c) Show that RHP is NP-Complete. Clearly identify whether you used the reduction in (a) or the reduc-
tion in (b) for your proof – only one of these reductions is relevant for this part.
Note: You may use the fact that RHC is NP-Hard without proof.
4
CS 170, Spring 2021 Final A. Chiesa & J. Demmel
(a) Given G, H and s1 , . . . , sn , reduce the problem of whether non-intersecting paths to hideouts exist for
Robin’s band to the max-flow problem from class.
(b) Prove the correctness of your reduction.
Note: You may use without proof the fact that an integer max-flow exists if all capacities are integers.
(c) Give a runtime analysis of the pre-processing step in your reduction, in terms of |V | and | E|.
6 K-Paths (12pts)
Suppose T is a rooted tree (not necessarily binary) and k is an integer. Your first task is to devise an algorithm
to compute the largest possible set of non-intersecting directed k-paths.
• A directed k-path is a path in the tree of exactly k edges that goes strictly upwards (i.e. always from
child to parent) in the tree, i.e. no path contains two children of the same node. Directed k-paths do
not have to start at leaves.
• By non-intersecting, we mean that distinct k-paths do not share any vertices.
(a) Describe a greedy algorithm which, given T and k as input, computes the largest possible set of non-
intersecting directed k-paths. Show that your algorithm is correct and analyze its runtime.
(b) Now, suppose that each vertex in T has a reward associated to it and you want to find the set of
non-intersecting directed k-paths which maximizes the sum of the vertex rewards it covers. Draw or
describe a counterexample to show that your greedy algorithm does not work for this problem.
(c) Now suppose each reward is independently drawn uniformly at random from {0, 1, 2, . . . , 10}. Show
that for any given rooted tree, your greedy algorithm achieves an average approximation factor of at
least 21 for the problem in (b). That is, show that
G (r ) 1
Er ≥ ,
M (r ) 2
where G (r ) and M(r ) are respectively the greedy algorithm’s total reward and maximum total reward
for r, a random assignment of rewards for the given tree.
Hint: Let N be the maximum number of non-intersecting k-paths for the given tree. Start by showing that
G (r ) 1
Er ≥ · Er [ G (r )].
M (r ) 10N (k + 1)