0% found this document useful (0 votes)
92 views3 pages

Cse 421 HW 8

This document discusses three polynomial time algorithms for NP-complete problems if P=NP: 1. A satisfiability algorithm that tries variable assignments and keeps the satisfying assignment. 2. A factoring algorithm that uses binary search to find factors of a number in polynomial time. 3. A matching algorithm that maps variables in satisfiable clauses to true/false using max cardinality matching on a bipartite graph in polynomial time.

Uploaded by

api-522855390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views3 pages

Cse 421 HW 8

This document discusses three polynomial time algorithms for NP-complete problems if P=NP: 1. A satisfiability algorithm that tries variable assignments and keeps the satisfying assignment. 2. A factoring algorithm that uses binary search to find factors of a number in polynomial time. 3. A matching algorithm that maps variables in satisfiable clauses to true/false using max cardinality matching on a bipartite graph in polynomial time.

Uploaded by

api-522855390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

If P = NP, then there is a polynomial time algorithm that, given a 3SAT formula, finds a
satisfying assignment to the formula, if there is one. To produce a satisfying assignment
for a formula A, first try substituting the variables x​0​ = 0 and x​1​ = 1 into the formula and
see which of A with x​0​ or A with x​1​ is satisfiable. One of them has to be because A is
satisfiable by our assumption. Whichever substitution works, make it permanent in A.
Continue substituting with x​2​ as the new 1 or 0 substitute, and continue the cycle of
keeping whichever formula is satisfiable until all x​i​ are found. This algorithm will
examine a new node each time it iterates through, so it runs in O(n) times, which is
polynomial.
2. If A is the problem of factoring in polynomial time, we are looking for a factor f of the
integer n in the range a < b. Since f is the certificate, A is in NP. We are assuming P =
NP, which means there exists a polynomial algorithm that solves the above problem. We
can use binary search to search halved areas of the range from a < b/2, a + b/2 < b, and if
there isn’t a factor in one half then we know there is in the other half. Through the
recursive algorithm it will run at most log(n) times for each individual value, and it could
do that up to n times for each factor, making the runtime nlog(n), which is bounded by n​2
which is polynomial, and thus the algorithm itself is polynomial.

Answer = Call search(2, n - 1, n)


If answer == -1, no factor, otherwise answer is the factor

search(int a, int b, int n)


if(b == a)
If (n % b == 0)
Return b
Return -1
if(search(a, a + (b - a)/2)) == -1)
Return search((a + (b - a)/2, b)
3. Consider the bipartite graph G with the clauses on the left and the variables on the right,
with the clauses and variables connected if the variable is in the clause. We use the
Capacity Scaling Algorithm to find the residual graph and according to lecture, the
residual graph is the max cardinality matching of a graph. According to Hall’s theorem,
each subset of nodes and their adjacent nodes will have a matching, because the number
of clauses in a neighborhood must be less than or equal to the number of variables in a
neighborhood. If the number of clause nodes and variable nodes are equal, then it’d be
perfect, as seen in lecture, but otherwise it’s just a matching because the sides aren’t the
same sizes. The runtime of this algorithm is also in polynomial time, because the majority
of it is the Capacity Scaling Algorithm.

Input Array of Clauses C, Array of Variables V


Map of variables M to booleans
for (Variable V​i​)
Create node with V​i
For (Clause C​i​)
Create node with C​i
For (each of the 3 variables V in C)
Add edge of weight 1 from C​i​ to V​i
Let this graph be graph G.
Use the Capacity Scaling Algorithm on G to get a residual graph R
For (Variable V​i​)
If (V​i​ in C is negated)
Add mapping of V​i​ to false to map M
Else
Add mapping of V​i​ to true to map M

You might also like