You are on page 1of 7

COL352 Homework 5

Release date: May 1, 2021 Deadline: TBD

Read the instructions carefully.

The deadline for this homework will be announced later, and at least one week in advance. The deadline will
be no earlier than May 15, 23:00. However, if your group is not seriously affected by the pandemic
and is in a position to submit early, you are requested to do so. Please bear in mind that since we
have our exam on the last day of the major exam week, the TAs will already be under pressure to grade your
exams in the following week (May 17-23). The incentive for submitting the homework by May 15, 23:00 is
that we will grade it and provide feedback in the next 24 hours (unless we get too many submissions on the
same day). Once your submission is ready to be graded, please ping the instructor and all the
TAs on Teams so that we know we can start grading, and don’t submit thereafter.
1. Let U be a finite set and let S ⊆ 2U be a collection of subsets of U . We say that a set H ⊆ U is a
hitting set of S if for all A ∈ S, we have H ∩ A, or in other words, H intersects every set in S. In the
HittingSet problem, we are given U , S ⊆ 2U , and an integer k as input. We are required to determine
whether there is a hitting set of S having size at most k. Prove that HittingSet is NP-complete.

Showing the problem belongs to NP is easy, as we can non-deterministically pick every possible sub-
set H of U and check if it satisfies the property required for it to be a hitting set of S, by checking in
polynomial time the intersection of H and every subset A of S. We now show the problem belongs
to NP-Hard, and thus by definition of NP-Complete, to NP-Complete as well.

We prove this by reduction of the NP complete problem vertex cover to hitting set.( The ver-
tex cover problem asks for whether there exists a set of vertices S of size ≤ k such that all edges
are incident on atleast one vertice of set S. Consider a graph G = (V,E), and the let m be the no
of edges in graph, and ei = (ui ,vi ) be the edge i of the graph. Consider the vertex cover problem,
where we aim to find if there exists a set of vertices S of size ≤ k such that ∀ i, atleast one of ui
and vi belong to S. Now consider the problem where we have S = {{ui ,vi }m i=1 } as required subset
collection S, U being the vertex set V of the graph. We claim that the problem of finding vertex
cover of size ≤ k on G = (V,E) reduces to finding a hitting set of constructed subset of collection
S over vertex set V of size ≤ k.

In the forward direction, we see that let G= (V,E) have a vertex cover H C of size ≤ k. Then
consider H = C. We see H ∩ {ui ,vi } =
6 ∅, because by definition atleast one vertices for all edge is in
vertex set, and thus C is a solution for hitting problem instance. Similarly for backward direction
we can show that because H ∩ {ui ,vi } =6 ∅, For all edges ei , i ∈ [1..m], atleast one of the 2 vertices
is contained in H, and H is a vertex cover of size ≤ k as well. Hence proben that HittingSet is NP
Complete.

2. Recall that two graphs G = (V, E) and G0 = (V 0 , E 0 ) are called isomorphic if there exists a bijection
h : V −→ V 0 such that for all vertices u, v ∈ V , (u, v) ∈ E if and only if (f (u), f (v)) ∈ E, and such a
bijection is called an isomorphism between G and G0 . In other words, an isomorphism is an adjacency-
preserving bijection. Also recall that a subgraph of a graph G is any graph that is obtained by deleting
some vertices and edges of G. In the SubgraphIsomorphism problem, the input consists of two graphs,
say G and G0 , and we are required to determine whether G0 is isomorphic to some subgraph of G. Prove
that SubgraphIsomorphism is NP-complete.

For, proving SubgraphIsomorphism NP-complete. We need to show that SubgraphIsomorphism is


NP-hard as well as NP.
We will give an algorithm for showing that the problem is NP. Then, we will prove SubgraphIsomorphism
is NP-hard by using karp reduction. Here, we will reduce the CLIQUE decision problem to SubgraphIsomorphism
problem. Also, as we know that if L1 ≤p L2 , and if L1 is NP-Hard, then L2 is NP-Hard as well.
Hence, doing so will prove the NP-Hard part of L2 .
Claim: SubgraphIsomorphism is in NP.
Proof: Define L = {(G1 , G2 )| G1 is isomorphic to some subgraph of G2 }
Consider the following nondeterministic polynomial time algorithm for deciding L
• Non deterministically select a one-one function f from nodes of G1 to nodes of G2
• Now, just iterate on all the nodes of G1 and check that for each edge (u, v) ∈ G1 whether
(f (u), f (v)) ∈ G2 which can be easily done in O(n + m)
Claim: CLIQUE ≤p SubgraphIsomorphism
Proof: Consider the following reduction:
Input: < G, k >

• For SubgraphIsomorphism, Assign G2 = G and G1 be the complete graph of size k.


• Also, we can construct G1 is polynomial time as k ≤ n as clique of size k>n is trivially not
possible. Hence, construction of G1 takes O(k 2 ) time.
Output: (G1 , G2 )

Proof of Correctness: Now, we need to prove that there will exist a CLIQUE of size k in G if and
only if there exists a subgraph in G2 which is isomorphic to G1 .
( =⇒ ) For the first part, suppose there exists a CLIQUE of size k in G, which means there exists
a subgraph of size k in G2 which is complete. However, G1 is also a complete graph of size k and
hence, any one-one mapping of all vertices of G1 to vertices of the CLIQUE of G2 gives a subgraph
in G2 which is isomorphic to G1 .
( ⇐= )Similarly, suppose there exists a subgraph isomorphism from G2 to G1 . However, G1 is a
complete graph which means that the set of k vertices G1 is mapping to is also complete which
implies that they form a CLIQUE of size k for graph G2 . Hence we are done.

3. A dominating set of a graph is a subset D of vertices such that every vertex that is not in D is adjacent
to some vertex in D. The input to the DominatingSet problem is a graph G and an integer k, and the
output is whether G has a dominating set of size at most k. The following algorithm is an attempt of
a Karp reduction from VertexCover to DominatingSet, but contains a minor error. Fix that error and
prove that the modified algorithm is a Karp reduction.
VCtoDS(G, k):
1. Construct a vertex set V 0 by taking the vertex set V of G, and then adding a vertex ve for each
edge e of G.
2. Construct an edge set E 0 as follows. For each edge e = (a, b) of G, add three edges – (a, ve ), (b, ve ),
and (a, b) to E 0 .
3. Return the instance (G0 , k) of DominatingSet, where G0 = (V 0 , E 0 ).

First, we make correction to the minor error in the algorithm. VC and DS differ in their approach
towards isolated vertices. DS takes all isolated vertices in its set (as all non-set vertices must be
adjacent to a set vertex and isolated vertices have to adjacent vertices so necessarily are in the
dominating set) but VC has no necessity to take them thus these isolated vertices are not included
in cover (every edge should have an incidence in cover and isolated vertices have no edge incidence).
So we make the following modification.

Let nI be the number of isolated vertices in G. The last step of the algorithm (step-3) is modified
as :-
3. Return the instance (G0 , k + nI ) of DominatingSet, where G0 = (V 0 , E 0 ).
Now we prove that the modified algorithm is a Karp reduction.

Claim: VC ≤P DS
Proof: We show that G has VC of size k iff G0 has DS of size k + nI .
( =⇒ ) Assume G has VC Vc of size k then we prove that G0 has DS of size k + nI . Let VI be the
set of isolated vertices. We observe that Vd = Vc ∪ VI is DS for G0 and has size atmost k + nI . Note
that all the isolated vertices are accounted for in Vd and each edge (a, b) of G has atleast one of a
or b in Vc thus the triangle a, b, ve is also accounted for in DS of G0 . Thus Vd is DS for G0 and we
are done.
( ⇐= ) Assume G0 has DS Vd of size k + nI then we prove that G has VC of size k. The first
step is to remove isolated vertices from Vd , i.e., we obtain Vc0 = Vd \ VI as we know all isolated are
necessarily in Vd . Thus, |Vc0 | = k. Now for any vertex of the form ve in Vc0 , we remove that vertex
and add either a or b where e = (a, b). To see why such removal is possible, note that ve dominates
a and b and taking either a or b instead of ve gives the same result, i.e., it leaves the domination
invariant. Iteratively performing this removal and addition, we get Vc where no vertex is of the form
ve , i.e., every vertex belongs to the original graph G. We claim that Vc is VC for G. Assume the
contrary that there is some edge e0 = (i, j) not covered by Vc . But ve0 should have been dominated
by Vc0 (due to domination invariance). Thus we have proved that Vc is a valid VC for G and hence
we are done.

Thus the Karp reduction is valid and the algorithm gives us the method to perform reduction
from VC to DS.

4. Recall that a boolean formula is said to be a 3CNF formula if it is an AND of clauses, where each clause
is an OR of at most 3 literals. Let us call a boolean formula a strict 3CNF formula if it is an AND of
clauses, where each clause is an OR of exactly 3 literals derived from 3 distinct boolean variables. In the
Strict3SAT problem, we are given a strict 3CNF formula, and we need to accept it if it is satisfiable,
and reject it otherwise. Prove that 3SAT is Karp-reducible to Strict3SAT.

We need to show that 3SAT ≤P Strict3SAT. As in the previous question, we use Strict3SAT as a
black-box to solve 3SAT. Given below is the algorithm.

3SATtoStrict3SAT(x1 ...xn ,F )
1. Convert 3CNF formula to strict 3CNF formula (more on this below).
2. Solve for the strict 3CNF (with some new variables) using Strict3SAT.
3. Return the answer obtained in previous step as output.

Now we elaborate on how to convert a 3CNF to strict 3CNF by introducing new variables. Let
x1 , x2 , ..., xn be the variables originally present in the formula. Newly introduced variables are de-
noted by yi . There is a need to introduce new variables because we need to convert any 3CNF into
a strict 3CNF. We need to consider 3 cases.
Case 1: Clause has only one literal.
Note that l = (l ∨ yi ∨ yi+1 ) ∧ (l ∨ ȳi ∨ yi+1 ) ∧ (l ∨ yi ∨ ȳi+1 ) ∧ (l ∨ ȳi ∨ ȳi+1 ). So for any single literal
clause, we replace them by the above formula (albeit adding two new variables).
Case 2: Clause has only two literal.
Note that l1 ∨ l2 = (l1 ∨ l2 ∨ yi ) ∧ (l1 ∨ l2 ∨ ȳi ). So two literal can be converted to three literal
conjunction (albeit adding a new variable) by using above formula. So each two literal clause is
replaced by above formula.
Case 3: Clause has three literals.
In this case we don’t need to do anything as the clause already conforms to strict 3CNF form.

Claim: 3SAT ≤P Strict3SAT


Proof: We show that 3SAT(x1 ...xn , F ) is satisfiable iff Strict3SAT(x1 ...xn , y1 ...ym , F 0 ) is satisfiable
(where F 0 is the transformation of F using above method).
( =⇒ ) Assume 3SAT(x1 ...xn , F ) has a satisfiable assignment. Then use this assignment of x1 , x2 , ..., xn
in F 0 and use any assignment of y1 , y2 , ..., ym to get a satisfiable assignment for Strict3SAT(x1 ...xn , y1 ...ym , F 0 ).
This can be seen as simplification of F 0 to F and as F is true then F 0 must also be true.
( ⇐= ) Assume Strict3SAT(x1 ...xn , y1 ...ym , F 0 ) has a satisfiable assignment. Then use the assign-
ments of x1 , x2 , ..., xn (of F 0 ) on 3SAT(x1 ...xn , F ) to get satisfying assignment. This is also due to
simplification of F 0 leads to F so the same x1 , x2 , ..., xn leads to true in both cases.

Thus the Karp reduction is valid and the algorithm gives us the method to perform reduction
from 3SAT to Strict3SAT.

5. The crazy instructor of COL352 has an equally crazy criterion for passing the course. The instructor gives
n homework problems over the semester, and every student gets zero or one mark in every problem. For
a student to pass the course, her/his marks must satisfy all of m constraints specified by the instructor
in the beginning of the semester. Specifically,
Pn a student who gets marks x[1], . . . x[n] passes the course if
and only if for each i ∈ {1, . . . , m}, j=1 A[i][j] × x[j] ≥ b[i]. Here A[i][j] and b[i] are integers specified
in the beginning of the semester.
For example, if m = n = 3 and the constraints are x[1]+x[2]+x[3] ≥ 2, −2x[2] ≥ −1, and −x[1]+3x[3] ≥
1, then a student getting marks x[1] = 0, x[2] = 0, x[3] = 1 fails the course due to violation of the first
constraint, while a student getting marks x[1] = 1, x[2] = 0, x[3] = 1 passes the course.
Given the matrix of integers (A[i][j]) where i = 1, . . . , m and j = 1, . . . , n, and the array b[1], . . . , b[m],
the students would like to know whether it is at all possible to pass the course. That is, they want
Pnaccept the input if and only if there exist x[1], . . . , x[n] ∈ {0, 1} such that for each i ∈ {1, . . . , m},
to
j=1 A[i][j] × x[j] ≥ b[i]. Prove that this task is NP-complete.

Consider LEQ, as the name for above problem. For, proving LEQ NP-complete. We need to show that
LEQ is NP-hard as well as NP.
We will give an algorithm for showing that the problem is NP. Then, we will prove LEQ is NP-hard
by using karp reduction. Here, we will reduce the 3SAT decision problem to LEQ problem. Also, as
we know that if L1 ≤p L2 , and if L1 is NP-Hard, then L2 is NP-Hard as well. Hence, doing so will
prove the NP-Hard part of L2 .

Claim: LEQ is in NP. Pn


Proof: Define L = {(x1 , x2 , ..., xn )| for each i ∈ {1, . . . , m}, j=1 A[i][j] × x[j] ≥ b[i] }
Consider the following nondeterministic polynomial time algorithm for deciding L
• Non deterministically assign each of xi a value of 0 or 1.
• Now, checking for the results will just involve substituting the values to the equations which
will take O(n).
Claim: 3SAT ≤p LEQ
Proof: Consider the following reduction:
Input: A boolean expression of 3CNF form

• Consider the variables z1 , z2 , z3 ...zn in place of x1 , x2 , x3 ..xn


• We will convert each of the clauses to an inequations. Note the following generalization for
which convert the boolean clauses into its equivalent numerical equation. For each xi , Each of
the OR operator will be converted to + operator, each of the xi will be converted to zi and
each of the xi is converted to 1 − zi and the RHS is set as 1.
• For example, xi ∧ xj ∧ xk is converted to zi + (1 − zj ) + zk ≥ 1, Similarly each of the clauses
is converted into inequations. This conversion make sure that if the values of zi are satisfied,
then corresponding xi ’s = zi satisfies the clauses as well and vice versa.
• Finally, P
the matrix A and array b is calculated by converting each of the inequations into the
n
form as j=1 ai × xi ≥ bi . Each of ai ’s are stacked to form matrix A and bi ’s form the b array
and return (A,b).

Output: (matrix of integers A[i][j], array b[i]...b[m])

Proof of Correctness: Now, we need to prove that there will exist a solution for 3SAT if and only if
there exist a solution for LEQ.
( =⇒ ) For the first part, suppose there exists a solution for 3SAT, then there exist a assignment of
xi ’s, we can see the same exact values of zi ’s indeed satisfies the inequations as well because both
of them are equivalent equations. Also, all the xi ’s are boolean, which inturn make sures values of
zi remains binary.
( ⇐= )Similarly, suppose there exists a solution for LEQ, then as both of the equations, inequation
defined by the reduction and clauses represent the same equation which mean that xi ’s with values
zi satisfies all the clauses. Hence we are done.

6. Recall the CircuitSAT problem discussed in class. The input to the problem is a boolean circuit over
variables x1 , . . . , xn , where each input of each gate is a variable, a constant (true or false), or the
output of an “earlier” gate. One gate is designated as the output gate, and we are required to determine
whether there exists a boolean assignment to the variables that makes the output of the circuit true
(a.k.a. satisfying assignment). The CircuitSATSearch problem has the same input as CircuitSAT, but
we are required to output a satisfying assignment if such an assignment exists, and otherwise output
“NO”.
Suppose that you are given a “black box” algorithm B that solves CircuitSAT, that is, given a boolean
circuit as input, the B accepts if the circuit is satisfiable, and rejects otherwise. Design an algorithm to
solve CircuitSATSearch which makes at most a polynomial number of calls to B and spends at most a
polynomial amount of time outside those calls. (This implies that to be able to search for a satisfying
assignment in polynomial time, it is sufficient to be able to detect the presence or absence of such an
assignment in polynomial time.)

Firstly lets consider how to reduce a circuit by fixing the value of a variable x1 . Lets define the
following function reduce as follows:
Algorithm 1 Reduce(C,v,x)
Input: Circuit C, Variable v, Value x
Output: Reduced Circuit C’
1 for all gates g with v as a direct input do
2 if g is AND GATE then
3 if x=False then
4 Replace output of g by 0
5 end
6 else
7 Replace output of g by other input y of g
8 end
9 end
10 if g is OR GATE then
11 if x=True then
12 Replace output of g by other input y of g
13 end
14 else
15 Replace output of g by 1
16 end
17 end
18 end

Now consider the following algorithm for solving a circuit:

Algorithm 2 Solve(C,V)
Input: Circuit C, Variables {x1 ,x2 ,.....xn }
Output: Solution if it exists and no solution otherwise
19 Circuitstore = C
for i = 1 to n do
20 rep1 = Reduce(Circuitstore,xi ,False).
if B(rep1) (There exists a solution with value of xi as False) then
21 Circuitstore = Reduce(Circuitstore ,xi ,False)
xi = False
22 end
23 else
24 Circuitstore = Reduce(Circuitstore,xi ,True)
xi = True
25 end
26 if assigned (x1 ,....,xn ) satifies Circuit C then
27 Return corresponding assignment as solution.
28 end
29 else
30 Return no solution found.
31 end
32 end

We see that solve(C,{x1 ,x2 ,....,xn } yields the required solution. The algorithm works because it
initially assumes existence of a solution, and accordingly follows the branch with can lead to a
true branch(if one value reduction leads to an insolvable circuit we assume other value leads to a
solveable circuit). Finally we check if solution we obtained satisfies circuit or not, and if it does, we
return it as solution. If it doesn’t then we know no feasible solution exists to the circuit.

We see that one call to ”black box algorithm” B is made at every iteration, and thus no of calls
made to B is O(n) which is a polynomial no of calls. Also we see that reduce function for a variable
takes time proportional to number of gates with that variable as a direct input(it takes constant
time to reduce a variable). Because each variable is reduced atmost twice, overall processing time
for reduction is of O(m+n), where m is the no of gates of the circuit. We see this time is polynomial
in the size of input, and thus a polynomial time is spent outside calls to B.

You might also like