2023 Spring Final
2023 Spring Final
Final
Name: Targaryen
SID: 0123456789
Exam Room:
Rules and Guidelines
1 SCCs (8 points)
Execute a DFS on the directed graph shown below starting at node A and breaking ties alphabetically.
A F J
B C D E
G H
2
Final P. Raghavendra & J. Wright
2. In the DFS execution from above, mark the following edges as as T for Tree, F for Forward, B for Back
and C for Cross.
Edge Type
A→C
F→J
H→J
E→H
3. List the strongly connected components of the above graph in some linearized order. (Note that the
number of SCCs is possibly smaller than the number of rows provided in the table below)
SCC no. Vertices in the component
1
10
4
SID: Final P. Raghavendra & J. Wright
Construct the Huffman code for the alphabet A, B, C, D, E, F, with the following frequencies.
Letter A B C D E F
Frequency 100 30 1 29 40 50
5
Final P. Raghavendra & J. Wright
3 6
S 3 T
5 3
1. Write the linear program corresponding to the maximum flow problem from S to T.
6
SID: Final P. Raghavendra & J. Wright
2. Write the dual to the above linear program. (The dual linear program corresponds to the minimum
cut problem.)
7
Final P. Raghavendra & J. Wright
C1 C2 C3
R1 1 2 3
R2 2 3 1
R3 3 1 2
The row-player goes first, and the column player goes second. The row player is trying to maximize their
payoff, which is specified by the entries of the matrix.
The value of the game is the expected payoff of the row-player when both players use optimal mixed strate-
gies.
Mark the following statements as true or false (each subpart is independent of the others).
1. If the column player is restricted to the three pure strategies {(1, 0, 0), (0, 1, 0), (0, 0, 1)}, row player’s
expected payoff doesn’t change.
hTrue hFalse
2. If the row player is restricted to the three pure strategies {(1, 0, 0), (0, 1, 0), (0, 0, 1)}, column player’s
payoff doesn’t change.
hTrue hFalse
3. Suppose we modify the game to include an additional row (so the resulting matrix is a 4 × 3 payoff
matrix). Then the value of the game can possibly both increase or decrease depending on the entries
of the new row.
hTrue hFalse
Write a linear program to find the optimal mixed strategy for the row-player.
8
Final P. Raghavendra & J. Wright
5 Median (4 points)
Suppose we ran quickselect (the randomized divide and conquer algorithm for finding the k-th smallest
element of an array) on the following array to find it’s median.
3 8 4 12 1 9 4 6 5
1. Specify which elements should be picked as pivots at each step in order to maximize the runtime of
this algorithm. Write the numerical value of the elements, not their indices. You might not need to fill
all boxes provided.
2. Specify which elements should be picked as pivots at each step in order to minimize the runtime of
this algorithm. Write the numerical value of the elements, not their indices. You might not need to fill
all boxes provided.
10
SID: Final P. Raghavendra & J. Wright
A 2 D
3
C
11
SID: Final P. Raghavendra & J. Wright
1. Suppose T(n) = 2T(n/4) + n2 then T(n) = (write the tightest possible bound)
2. If T(n) = 2T(n/4) + n2 log8 n then T(n) = (write the tightest possible bound)
3. An n-vertex directed acyclic graph can have as many as ( ) directed edges, while
4. Suppose A, B, C, D, E are five vertices that are part of a large directed graph. Here are the pre and post
values of these vertices in a DFS traversal. The traversal was carried out in an unknown order, not
necessarily lexicographical.
Node pre post
A 20 30
B 10 80
C 50 54
D 90 100
E 93 97
Then,
(a) There is necessarily no directed path from A to C in the graph.
hTrue hFalse
hTrue hFalse
hTrue hFalse
hTrue hFalse
13
Final P. Raghavendra & J. Wright
5. Let ω = e2πi/16 be the 16th root of unity. Suppose the Fourier transform of a vector ( p0, p1, . . . , p15) is
The following points are some of the feasible solutions of a linear program.
(0, 0), (0, 10), (5, 8), (10, 10), (10, 0), (5, 2)
For each of these points indicate whether they are necessarily feasible, necessarily infeasible or neither.
(a) (0, 5)
hnecessarily feasible hnecessarily infeasible hneither
7. The dynamic programming based algorithm for edit distance between two strings x[1, . . . , m] and
8. Suppose we run the distinct elements algorithm on a stream s1 , . . . , sm . Assume that the algorithm
uses a hash-function h that is perfectly random.
If there is only one distinct element in the stream, what is the probability that the algorithm outputs
an estimate > 99?
9. Suppose we run the distinct elements algorithm on a stream s1 , . . . , sm . Assume that the algorithm
uses a hash-function h that is perfectly random.
If there are 100 distinct elements in the stream, what is the probability that the algorithm outputs an
estimate < 9?
10. Suppose we pick a hash function h : {0, 1. . . . , p − 1} → {0, 1, . . . , p − 1} from a pairwise independent
hash family. What is the probability that h(2) = (h(1) + 2)modp?
14
Final P. Raghavendra & J. Wright
Let S1 , S2 , S3 denote the first 3 sets picked during an execution of the greedy algorithm for Set Cover prob-
lem.
Suppose the size of the universe is 24 and the sizes of the unions of sets are as follows
|S1 | = 12
|S1 ∪ S2 | = 15
|S1 ∪ S2 ∪ S3 | = 17
2. The greedy algorithm will necessarily pick at least sets before termination.
16
SID: Final P. Raghavendra & J. Wright
hT hF hP = NP hP ̸= NP
hT hF hP = NP hP ̸= NP
hT hF hP = NP hP ̸= NP
hT hF hP = NP hP ̸= NP
hT hF hP = NP hP ̸= NP
hT hF hP = NP hP ̸= NP
17
SID: Final P. Raghavendra & J. Wright
19
Final P. Raghavendra & J. Wright
Consider a directed graph G = (V, E) with positive weights c(i, j) on its edges.
Given a path P = v0 → v1 . . . → vk , the discounted cost of the path is the sum of lengths of all but the the
longest edge. Formally,
!
k −1
cost( P) = ∑ c ( v i , v i +1 ) − max c(vi , vi+1 )
i
i =0
(It is the sum of cost of all the edges - maximum cost edge)
Devise an algorithm to compute the smallest discounted cost path from a vertex s to vertex t. Give a succinct
and precise description of your algorithm. Proof of correctness and run-time analysis are not necessary. The
runtime of your algorithm should be O((|V | + | E|) log |V |).
20
Final P. Raghavendra & J. Wright
1. TriClique: Given a graph G = (V, E), a subset S ⊂ V of vertices is called a clique, if every pair of
Proof. It is clear that the TriClique problem is in NP. Now we will use a polynomial time reduction to show
that the problem is indeed NP-complete.
22
SID: Final P. Raghavendra & J. Wright
2. Set Ordering:
Input: A family of subsets S1 , . . . , Sn of {1, . . . , m}.
Solution: An ordering of the sets so that consecutive sets in the ordering have intersection exactly
one. Formally, an ordering of the sets is given by a permutation π : [n] → [n], so that for each
i ∈ {1, . . . , n − 1}, |Sπ (i) ∩ Sπ (i+1) | = 1.
Proof. It is clear that the Set-Ordering problem is in NP. Now we will use a polynomial time reduction to show
that the problem is indeed NP-complete.
23
SID: Final P. Raghavendra & J. Wright
In the lecture, we have seen the Floyd-Warshall algorithm for computing distances between every pair of
vertices in an input graph. The Floyd-Warshall algorithm is a dynamic programming based algorithm with
runtime O(n3 ) In this question, we will devise a simpler dynamic programming based algorithm for all
pairs shortest paths, with a slightly worse runtime.
Given an input graph G = (V, E) with positive edge weights wij for each edge (i, j). Consider the following
sub-problem:
D [i, j, t] = length of the shortest path from i to j with at most 2t hops
(Here ”hop” refers to the number of edges on the path).
2. Write pseudocode for the algorithm to compute all-pair distances, including the initialization.
1. What are the variables of the linear program? (Write out succinctly and precisely, the intended mean-
ing of the variables in your linear program)
27
Final P. Raghavendra & J. Wright
4. Describe a rounding scheme to obtain a {0, 1}-solution from the optimal solution to the above linear
program.
5. Briefly justify why the rounding scheme produces a solution to the Triangle Removal problem.
28