Computer Network Homework Help
Computer Network Homework Help
Solution: True. This graph only contains one cycle, which can be
found by a DFS. Just remove the heaviest edge in that cycle.
(a) Draw the shortest path from Boston to New York in the
following graph if m = ∞. Charging stations are marked as
circles.
Solution:
(b) Draw the shortest path from Boston to New York in the
following (identical) graph if m = 100.
Solution:
(c) Give an algorithm to solve the problem. For full credit, your
algorithm should run in O(V E + V 2 log V ) time.
For the second step, we build a graph G" with vertex set C. For
every pair of vertices u and v in the new graph G" , draw an edge
between u and v with weight δ(u, v) if δ(u, v) ≤ m and ∞ otherwise.
Now, run Dijkstra’s algorithm on G" between Boston and New York
to get the shortest path. (Note that New York and Boston have
charging stations and so are vertices in the graph G" ).
You have N psets due right now, but you haven’t started any of
them, so they are all going to be late. Each pset requires di days to
complete, and has a cost penalty of ci per day. So if pset i ends up
being finished t days late, then it incurs a penalty of t · ci. Assume
that once you start working on a pset, you must work on it until you
finish it, and that you cannot work on multiple psets at the same
time.
For example, suppose you have three problem sets: 6.003 takes 3
days and has a penalty of 12 points/day, 6.046 takes 4 days and has
a penalty of 20 points/day, and 6.006 takes 2 days and has a
peanlty of 4 points/day. The best order is then 6.046, 6.003, 6.006
which results in a penalty of 20 · 4 + 12 · (4 + 3) + 4 · (3 + 4 + 2) =
200 points.
(a) First look at the special case where the maze is just a
single path of length |E| from s to t, and all the edges have
capacity 1 (see below). Exactly how many nights are required
for the teens to escape?
Solution: |E| + m − 1 or |V | + m − 2. Em or V m will get partial
credits.
(b) The general case is more complex. Assume for now that we
have a “magic” algorithm that calculates whether the teens can
all escape using ≤ k nights. The magic algorithm runs in
polynomial time: kα T(V, E, m) where α = O(1). Give an
algorithm to calculate the minimum number of nights to
escape, by making calls to the magic algorithm. Analyze your
time complexity in terms of V , E, m, α, and T(V, E, m).
(c) Now give the “magic” algorithm, and analyze its time
complexity. Hint: Transform the problem into a max-flow problem
by constructing a graph G" = (V " , E" ) where V " = {(v, i) | v ∈ V, 0 ≤
i ≤ k}. What should E" be?
Solution: Model this as a max flow problem. Construct a graph G"
= (V " , E" ) where V " = {(v,i) | v ∈ V, 0 ≤ i ≤ k}. For all 0 ≤ i ≤ k−1,
connect (v, i) to (v, i+1) with capacity ∞ (or m); this represents
teens can stay at a vertex for the night. For every edge (u, v) in the
original graph, connect (u, i) to (v,i + 1) with capacity c((u, v)); this
represents c((u, v)) teens can travel from u to v in a night. The
new source s" is the vertex (s, 0) and the new sink t " is the vertex
(t, k − 1). If the max flow from s" to t " is no less than m, then
people can escape within k nights.
Runtime: Both of the following are accepted.
There are V = O(kV " ) vertices and E" = O(k(V + E)) edges in G" .
Applying Edmonds-Karp algorithm, the total time complexity is
O(V E"2) = O(k3V (V + E)2). If using Ford-Fulkerson runtime, notice
that we can actually stop if the max flow reaches m. So at most m
iterations are needed. Runtime can be O(m(V " + E" )) = O(mk(V +
E)).
Common mistake 1: connect (v, i) to (u, i) instead of (v, i) to (u, i +
1).
Common mistake 2: no edge from (v,i) to (v, i + 1).
Finally, run max flow from s to t, and find f. If |f| = m, return that
person i will drive on day j if the edge (pi, dj ) has non-zero flow. If
|f| < m, then return no valid assignment.
G" always has a cycle of length 3 - (u1, u2, u3). For any Hamiltonian
Path P in G, (u2, u3, u1, P) is a Hamiltonian Path in G" . For any
Hamiltonian Path P" in G" , P" must be of the form (u2, u3, u1, P),
where P is a Hamiltonian path for G. Thus in all cases, solving B(G" )
is equivalent to solving Hamiltonian Path for G.