NetworkFlow NP Merged
NetworkFlow NP Merged
≥ c(A, B) − m4
1 2
Similarly you have a min cut of capcity k, and edges in the cut must all have capacity 1, which 6. • We construct the chains as follows:, if ri is matched with lj , we are sure that i ≤ j, so we
are edges of type v1 v2 . We just delete all such vertices v, which would definitely disconnect s and place i just before j in the chain decomposition, and we do this for every single matching.
t. Is this a well defined chaining? Well ri can be matched with only 1 node, so it won’t be
placed before 2 different j’s. Similar lj is paired with only 1 ri so its previous element is
5. Say we have TAs T1 , . . . , Tn . And courses C1 , . . . , Ck each demanding d1 , . . . , dk TAs. All Ti ’s and well defined. So at the end of this process how many chains do we get? Initially before
Cj ’s will be nodes of our graph. We draw a directed edge from Ti to Cj with capacity 1 if TA Ti chaining up anything, all n elements are kind of like in different chains. Each matching we
is eligible to take course Cj and its flow value will indicate if Ti is assigned course Cj . We connect see, we connect 1 chain to another and reduce the number of chains by 1. So if we have k
Cj to a sink t with an edge of capacity dj , and its flow will denote the number of TAs assigned matchings, we’ll have n − k chains. If ri is never matched, it isn’t before any j so it will be
to that course. We draw an edge from source s to Ti with capacity 1 to make sure that the TA a maximal element in a chain. Similarly if lj is never matched, it won’t be after any i so it
takes maximum 1 course1 , and its flow value denotes if the TA has been selected for some course. is a minimal element in a chain.
And that’s it, we check the max flow from s to t and check if it’s equal to d1 + · · · + dk . This is
possible if and only if every Cj t edge had flow dj , and this is only possible if we found dj edges to • We just do the same thing backwards. If i is placed directly before j in a chain, we’ll match
Cj with flow value 1 coming from different TAs. Converse is easy to show, if we have a suitable ri with lj . Why this is a matching, is because i can be directly before a unique j and j can
TA allocation we can construct a flow equal to d1 + · · · + dk . only be directly after a unique i. The number of ri ’s which aren’t matched are basically
the number of minimal elements, which are the number of chains = k. So the number of
matches is n − k.
• Now that we’ve shown that decomposition into to k chains iff matching of size n − k, a
maximal matching will correspond to a minimal chain decomposition. A maximal matching
of size n − k means we can find a chain decomposition of size k, and this is minimal as if we
find one smaller than k, we’ll also be able to find a matching greater than n − k, which is a
contradiction.
7. Let (A, B) be some cut with capacity n − k. What we are first going to do is to modify our cut
by adding more nodes to A, without increasing the capacity. Suppose i < j i.e. li rj is an edge,
with li ∈ A and rj ∈ B. We will just move rj to A from B. How does our cut capacity change?
We will gain the edge rj t but we are at least losing 1 edge, which is li rj itself. So overall our cut
capacity can’t really increase. We just keep doing this, add as many rj ’s as we can, until none of
the li rj edges are part of the cut. Now we claim that, the set of i such that li ∈ A and ri ∈ B
Let (A, B) be the minimum cut of this graph. Let X, X 0 be the TA’s in A, B respectively. And is an antichain. Can i, j in this set be comparable? If i < j, li rj will be an edge. We know
Y, Y 0 be the courses in A, B respectively. We are going to prove that Y 0 is a set of courses for li ∈ A, rj ∈ B. But we just extended A such that none of these are part of the cut, so this isn’t
which the total number of TAs eligible for them is less than the demand. Let’s see what all edges possible. Now what’s the size of our antichain? Let’s think about the cut capacity which is the
are in the cut. Firstly there are edges from s to all of X 0 , so the capacities sum to |X 0 |. Then number of edges in the cut. li , rj type edges aren’t part of the cut, so only possibilities are s, li ,
there arePedges from X to Y , we don’t know how many, and there
0
are edges from Y to t which and ri , t type edges. The only i for which neither of them are an edge in the cut is if li ∈ A and
sum to i|Ci ∈Y di . Let’s think about how many TAs in X and X 0 are suitable for courses in Y 0 . ri ∈ B, which is exactly the elements which aren’t in our antichain. What about the case where
So for each TA in X suitable for some course in Y 0 there will at least be 1 edge from the TA both are in the cut? Doesn’t matter, we are just saying there is at least 1 of these edges for every
to Y 0 . So we can say number of edges from X to Y 0 is ≥ number of TA in X eligible for Y 0 . i which isn’t in our antichain i.e capacity is at least n− (number of elements in antichain). We
And trivially, number of TAs eligible for Y 0 in X 0 ≤ |X 0 |. Now we are going to combine all these also have the fact that capacity is atmost n − k. So in the end we get an antichain of size at least
results. k.
This actually proves Dilworth’s theorem, as the number of chains we can partition into is exactly
c(A, B) = maxf low <
X
di equal n − maxf low = n − mincut. Say the number of chains is k, then the maxflow, and mincut
i
is equal to n − k And if the mincut is equal to n − k, we can find an antichain of size at least
X X X X X n − (n − k) = k. We can’t do better than k, else we’ll pick 2 elements in the same chain.
ce + ce + ce < di + di
e:s→X 0 e:X→Y 0 e:Y →t i|Ci ∈Y i|Ci ∈Y 0 8. We first reverse all the edges of a graph i.e. we draw a directed edge from i to j if j is a prerequisite
for i. We also give it a capacity of ∞. The motivation for this is like follows, as we are reducing
X X X
|X 0 | + |{e : X → Y 0 }| + di < di + di
i|Ci ∈Y i|Ci ∈Y i|Ci ∈Y 0 this question to a mincut question, we want to make sure that none of these edges are in the cut
X else we choose a project without its prerequisite, and infinite capacity edges won’t ever be part of
|X 0 | + |{e : X → Y 0 }| < di the mincut. Now we add a source s and a sink t. If pi is positive we connect s to i with capacity
i|Ci ∈Y 0
pi . If pi is negative we connect i to t with capacity −pi . Because of the infinite edges we know
that the mincut will satisfy precedence constraints.
Since the first term is ≥ number of TAs in X 0 eligible for Y 0 , and second term is ≥ number of
TAs in X eligible for Y 0 , in the end we the fact that total number of TAs eligible for Y 0 is less
than demand of TAs for Y 0 .
1
KarGo
3 4
Network Flow
1. • Don’t know, we know that vertex cover without the word ‘minimum’ is in NP, but there’s
no clear way to show that a particular k is minimum, how would you even give a proof that
there is no vertex cover of size k − 1 without brute force.
• Yes, this is in NP. We can actually just solve this problem in Polynomial time, as done in
Q4 in Network Flow. So to verify that the answer is k, we just solve it using our network
flow algorithm and check if we also get k.
• Don’t know, there’s no clear way to prove that 2 programs are the same itself.
• Don’t know, even though a proof could be just 2 inputs where the programs give differ-
ent outputs, verifying this will take exponential time, either because the inputs could be
exponentially large, or the program could take exponential time itself.
• Don’t know. If we have some n ‘for all’s, we could have 2n different choices of variables for
which we have to verify the formula as true, so a brute force proof will take exponential time.
There is also no clear way to provide a shorter proof in general, for any boolean formula.
Now let’s look at a random cutP(A, B) and try to see what is its capacity. There are (s, i) type 2. We claim that a set is a vertex cover if and only if its complement (all vertices outside our set) is
edges, whose sum is basically i∈B,pi >0 csi . There are also (i, t) type edges whose sum will be an independent set. If S is a vertex cover, for every edge uv, either u ∈ S or v ∈ S. So there’s no
edge uv where both u ∈ S c and v ∈ S c . But this is just saying S c is an independent set. Now for
i∈A,pi <0 cit . No infinite type edges will be there in any A which satisfies precedence constraints.
P
The total capacity is hence the converse, if S is independent, there is no edge uv such that both u ∈ S and v ∈ S. But this
means for every edge, either u ∈ S c or v ∈ S c , which is just saying S c is a vertex cover. So if we
want to check if we have an independent set of size k, we just need to check if we have a vertex
X X
c(A, B) = csi + cit
i∈B,pi >0 i∈A,pi <0
cover of size n − k. This is because if there is an independent set of size k, the complement set
X X will have size n − k which is a vertex cover. And if we don’t have an independent set of size k,
= pi + −pi we can’t have a vertex cover of size n − k, else by our equivalence we can find an independent set
i∈B,pi >0
X X
i∈A,pi <0
X of size n − (n − k) = k.
= pi − pi − pi
i,pi >0 i∈A,pi >0 i∈A,pi <0 3. The idea is like this, we keep the elements of our sets as edges, since if we want to cover all edges
X X it becomes equivalent to covering all elements of our sets. So our universe is going to be the set
= pi − pi
of all edges. And selecting a vertex should be equivalent to selecting some set right, so each set
will just be set of all edges incident on our vertex. Now we claim that we have a vertex cover of
i,pi >0 i∈A
size k if and only if we have a set cover of size k. But this is obvious right, we just select the
The first term is a constant no matter what A is, so if we minimize the cut, we maximize pi ,
P
i∈A corresponding sets we made for the vertex cover. Since every edge is incident with some vertex,
which is exactly what we want.
every element is in some set. Similarly if we have a set cover of size k, we have a vertex cover of
9. We want a conservative estimate i.e we want the maximum number of tigers that we’re sure have size k. Since any element is in some set, the corresponding edge is incident with some vertex.
to exist. Experts have distinguished many li ’s and rj ’s, but any pair which isn’t represented by
4. For the load balancing problem, one machine is going to get some subset of {t1 , . . . , tn }, and the
an edge could potentially be the same. Since we want to give a conservative estimate, we try to
other machine Pwill get the Prest of the elements. P Let the subset of loads be S. The loads in each
maximise the pairings. First what we do is complement the edges i.e. connect li ’s and rj ’s which
machine are i|ti ∈S ti and i|ti ∈S i|ti ∈S ti . Both of these should be at most T , from
P
t = t −
the experts aren’t sure are different. And then find the largest matching possible (can be done / i i i
which we get the following inequalities, i|ti ∈S ti ≤ T , and i|ti ∈S ti ≥ i ti − T . The terms on
P P P
by max flow). Our answer is basically k + m + n − (maximum number of matchings), as each
the RHS of each inequality are constants no matter what S is. So we can see that this is now
matching will decrease the answer from k + m + n by 1.
very similar to the knapsack problem. So our motivation will be like this, we are going to make
sure W1 , W2 add to sum of all the weights (by adding a new weight w0 ), so that we can reduce to
load balancing. So let’s do that.
Let w0 be such that i wi + w0 = W1 + W2 i.e. w0 = W1 + W2 − i wi , we are adding this new
P P
weight to our list of weights, and are now going to do load balancing with T = W2 . If we have a
solution for this, choose the set of loads which don’t have w0 , and call this set S. We know that
i|wi ∈S i ≤ T = W2 , now let’s write the inequality for the other set.
P
w
5 1
Now we have to bring in the clauses. We add a node for each clause, and need to make sure it is
X
0 visited only if the clause is satisfied. Let’s say our first clause C1 is x1 ∨ x2 ∨ ¬x3 . So whenever
wi + w ≤ T = W2
x1 is true i.e we move left to right in row 1, we should be able to visit C1 . So what we do is add
an edge from 1 in row1 to C1 , and an edge from C1 to 2 in row 1. So instead of going straight
i|wi ∈S
/
from 1 to 2, we can divert to C1 and come back. Since we have ¬x3 , we need to be able to visit
X X X
wi − wi + W1 + W2 − wi ≤ W2
i i|wi ∈S i C1 while going from right to left. So we add an edge from 2 in row 3 to C1 , and an edge from C1
to 1 in row 3. We’re only going to use the first and second nodes in each row for C1 , these are
X
W1 ≤
i|wi ∈S
allocated for C1 . Similarly third and fourth nodes are for C2 , fifth and sixth nodes are for C3 .
Why are we keeping different nodes for each clause? This is because the same assignment can
So this subset satisfies the knapsack constraints. The converse is also easy to show i.e. if a subset make multiple clauses true, maybe even all clauses so we want to have the option of allowing an
satisfies the knapsack constraints, it’s going to satisfy the load balancing constraints, by just assignment to visit any number of clauses while moving along the row. Below is how the graph
going backwards. We already know the subset without w0 has a sum ≤ W2 , now for the subset will look after filling everything for C1 , and also we have the full graph if C2 is ¬x2 ∨ x3 ∨ x4 , and
with w0 . C3 is x1 ∨ ¬x2 ∨ x4 .
X
wi ≥ W1
i|wi ∈S
X X X
wi + wi + W2 ≥ W1 + W2 + wi
i|wi ∈S i|wi ∈S
/ i|wi ∈S
/
X X
wi + W2 ≥ W1 + W2 + wi
i i|wi ∈S
/
X X X
W2 ≥ W1 + W2 − wi + = w0 + wi
i i|wi ∈S
/ i|wi ∈S
/ After Clause 1 Final Graph
5. Each variable in our formula φ can be a variable in our linear equations. If x1 , . . . , xn are the
variables, we put the constraints 0 ≤ xi ≤ 1 to ensure each variable is 0 or 1. Now how do Now if we find a Hamiltonian cycle in the graph, we can easily find out the assignment which
we write clauses? Take the clause x1 ∨ ¬x2 ∨ x4 . To satisfy this clause we need at least one of works. Just see in which direction we move in each row, and correspondingly assign each variable.
x1 , ¬x2 , x4 to be 1. This can be actually represented as x1 + (1 − x2 ) + x4 ≥ 1. So we’ll have This will satisfy the assignment as the Hamiltonian cycle visits every clause, meaning at least
2n + k different linear inequalities (n for all xi ≥ 0, n for all xi ≤ 1, k for each clause). one variable assignment is there to make every clause true. Similarly, if we have a satisfying
assignment we’ll definitely have a Hamiltonian cycle. We can find out in which direction to move
6. We’d like to create a graph where there’s a cycle corresponding to all of the 2n possible assignments through each row from the assignment. Since the assignment is satisfying, there will be at least
to variables x1 , . . . , xn . How we do this is as follows, we make a path for each xi , which can be 1 variable assignment making each clause true, and whatever that is, we can take a detour there
traversed forwards and backwards. If moving from left to right, it’s like assuming xi is 1, and and visit that clause. Since we allocated different sections for each variable connecting to each
right to left denotes assigning xi as 0. We will have connecting edges to move from 1 variable clause, this is feasible.
to the next, and one source and sink vertex. The length of each path is going to be twice the
number of clauses (we’ll see why we need this length later, just assume we choose some random
length for now). Assume we have 4 variables, x1 to x4 .
In the above graph, there will be 24 Hamiltonian cycles, because for each row, we can either go
left to right, or right to left. We can’t backtrack on any path because each vertex has to be visited
exactly once, and each can correspond to some assignment.
2 3