Sei sulla pagina 1di 3

CS 224 Problem Set 4 Solutions

Fengning (David) Ding Collaborated with David Liu, Albert Wu, Nithin Tumma
October 15, 2014
1 Problem 1
We know that if x
i
> 0, c
i
/ (A
T
)
i
y c
i
, so c
i
/x
i
(A
T
)
i
yx
i
c
i
x
i
for x
i
0. Hence, c
T
x y
T
Ax.
Moreover, we know that if y
i
> 0, b
i
A
i
x b
i
, so y
i
A
i
x b
i
y
i
for y
i
0. Hence, y
T
Ax b
T
y. We
conclude that c
T
x b
T
y.
2 Problem 2
2.1 Part a
Our dual problem is to maximize D(T) = (n k)

T
t=1

t

T
t=1

i=r(t)
y
t
i
, given the constraints
t

Y
t,r(t)
+
t
r(t)

t1
r(t)
0 for all 1 t T and
t
y
t
i
+
t
i

t1
i
0 for all 1 t T and i = r(t).
2.2 Part b
We build up our dual solution in the following manner (the primal solution is maintained as described in the
problem statement). Basically, the variable
t
i
= 1 when page i is marked at time t. Moreover,
t
= 1 when
we clear all the mark bits in the cache at time t. We will just set Y
t,r(t)
to whatever number that causes the
constraint to be satised.
Now we will show how y
t
i
is set. There are two distinct cases. In the rst case, we dont clear the marked
bits at time t, and in the second case, we clear everything. Note that in the rst case,
t
i

t1
i
= 0 for
i = r(t), since if
t1
i
= 1,
t
i
= 1 since we did not unmark, and if
t1
i
= 0, then
t
i
= 0 since we did not
access page i at time t. Hence, if just set y
t
i
= 0, then
t
y
t
i
+
t
i

t1
i
= 00+0 0, so we get a feasible
solution. The dual cost D(t) does not change at all at time t.
In the second case,
t
i

t1
i
= 1 for every page i in cache, and
t
= 1. Hence, if we set y
t
i
= 0 for the
pages in cache, the constraint

t
y
t
i
+
t
i

t1
i
= 1 0 1 0
is satised. For every page not in the cache and not equal to r(t),
t
i

t1
i
= 0, so if we set y
t
i
= 1, the
constraint becomes

t
y
t
i
+
t
i

t1
i
= 1 1 + 0 0.
Hence, (n k)

t
=1

t
increases by n k, and

t
=1

i=r(t)
y
t
i
increases by n k 1 (since there are
n k 1 elements not in the cache and not equal to r(t)). We conclude that D(t) increases by 1.
It is clear now that this procedure gives feasible dual and primal solutions. Moreover, since D(t) increases
by 1 when we clear all the marks, D(t) must equal the number of times we cleared marks by time t. The
total number of evictions, that is, the primal cost, is then at most kD(t) + k, since this is the total number
of marks that could have accumulated given D(t) cleaning cycles. Since kD(t) + k k(OPT(t) + 1), this
scheme gives a k-optimal algorithm.
1
3 Problem 3
3.1 Part a
The primal problem is: minimize

c
u
x
u
, given that x
u
+ x
v
1 for all edges (u, v), and x
u
0.
The dual problem is: maximize

y
e
, given that

eu
y
e
c
u
for all vertices u and y
e
0. For notation,
let us write (u) =

eu
y
e
.
3.2 Part b
Our algorithm is the following. In the beginning, set all y
e
= 0. As long as there is an edge e = (u, v) where
(u) < c
u
and (v) < c
v
, we increase y
e
until at least one of the two constraints is tight. Then, we set
x
u
= 1 for (y) = c
u
(if both constraints are tight, we set x
u
and x
v
both to 1). At the end, we take the
vertices with x
u
= 1 into our cover.
We shall rst prove that this solution gives feasible primal and dual solutions. Clearly, the dual is feasible:
each y
e
belongs to exactly two of the (u) and (v), and so increasing y
e
only aect these two sums. But
we increase y
e
only until one of these sums becomes tight.
Now we show that the primal is feasible. Indeed, by construction, (u) = c
u
i x
u
= 1. Hence, since
(u) = c
u
or (v) = c
v
for every edge (u, v) at the termination of our algorithm, x
u
or x
v
is at least 1, so
x
u
+ x
v
1.
Finally, we show that this algorithm is 2-optimal. Indeed, suppose x
u
> 0. Then, (u) = c
u
, so
c
u
/ (u) c
u
for = 1. Moreover, 1 x
u
+ x
v
for = 2, since x
u
, x
v
1. Hence, by using
approximate complimentary slackness, we get that the algorithm is = 2 optimal.
4 Problem 4
4.1 Part a
Consider the graph with three vertices A, B, C, with an edge from A to B of length 1, an edge B to C
with length 1, and an edge A to C of length 2. Then, if f
AC
= x, from the constraints, f
AB
= 2 x and
f
AC
= 1 x, so the cost is 2f
AC
+ f
aB
+ f
AC
= 3. Hence, every ow from A is optimal in this graph, and
in particular, we can take x =
1
2
.
4.2 Part b
We can rewrite the linear program as min

L(e)f
e
, given Bf , Bf , and f 0. Now, B has n
rows (where n was the number of vertices), so we have 2n dual variables y
n
and z
n
. Hence, the dual problem is
to maximize
T
y
T
z with the constraint that B
T
yB
T
z L(e). If we write out what and B represent,
we get: maximize (n 1)(y
s
z
s
)

v=s
(y
v
z
v
) (where s is the source) given y
u
z
u
y
v
+ z
v
L(e)
for all edges e = (u, v).
Let
u
= z
u
y
u
. We can reformulate the dual as: maximize

u
(
u

s
) given
v

u
L(e).
4.3 Part c
We build up our primal and dual solution as follows. Initialize all the f
e
to 0 and
s
= 0. When Dijkstras
algorithm modies its estimate of the distance d(u) of a node u from the source s, we set
u
= d(u). When
Dijkstras algorithm is about to consider the node u at the top of the heap, we consider the path Dijkstras
algorithm nds (we can for example keep some metadata for each node to keep track of where the nodes
estimate of distance came from) and increase f
e
by 1 for every edge along the path.
We prove that this solution is feasible. Clearly, the primal solution is feasible: we make n 1 rounds of
increments, so the total outow of the source vertex is n 1. Moreover, each vertex is the nal destination
of a shipment in exactly one such round of increments. If a vertex is not the nal destination of a shipment,
2
then every unit that enters the vertex through some edge will leave it by some other edge, so the total number
of units that accumulate at that vertex is not modied (i.e., the constraint for that vertex is unchanged).
Hence, each vertex other than the source receives exactly one unit.
Now we show that the dual solution is feasible, i.e.,
v

u
+L(e). To see this, notice that when we take
a vertex u out of the heap,
u
can no longer change. All vertices that have not been removed from the heap
must have
v

u
at all times afterwards. Hence, if we take v out before u,
v

u
<
u
+ L(e), and if we
take v out after u,
v

u
+L(e), since in Dijkstras algorithm, we would have set
v
to be the minimum of

u
+ L(e) and some other distance.
Now, we show that the dual and primal costs are equal, which would imply that the primal cost is
optimal. Indeed, when we construct the primal solution, we increase the ow along the edges in the path
that Dijkstras algorithm uses to compute
u
. Along each edge, the cost increases by L(e), so by denition of

u
and the Dijkstra path, the primal cost increases by
u
. Hence, the total primal cost is

u
=

s
,
which is the dual cost.
5 Problem 5
I spent 10 hours on this pset. I spent less than an hour on problem 1, 1 hour on problem 4, 3 hours on
problem 3, and 5 hours on problem 2.
3

Potrebbero piacerti anche