I am really confused why 2-CNF SAT is in P, while 3-CNF SAT is in NPC. I Read CLRS, and I understand how they prove 3-CNF SAT is in NPC. Can't I use the same reducibility from SAT to 2-CNF-SAT to prove 2-CNF-SAT is in NPC. I don't understand why 2-CNF SAT is in P.
why 2-CNF SAT is in P
Because there is a polynomial algorithm to solve it.
A rough sketch of a proof:
Note that any clause in 2-CNF is in the form A => B
where A
and B
are either variables or their negation. Therefore, we can tell that this clause says when A is true, it forces B to be true. It also means that B is false forces A to be false. We have to consider that later.
Now, you can take a variable, one by one, and search if it transitively forces itself to be its negative (A => B => C => ... => non A) and vice versa (non A => ... => A). If the first is true, A has to be false; if the second, A is true. If both, the formula is unsatisfiable.
If you don't find any variable that makes the formula unsatisfiable, it is satisfiable.
Note that this "brutal" algorithm is not the actual one using strongly connected components of a graph, which I recommend you to read on. Yet, it is polynomial (the search for one variable is clearly O(N^2), since you force one variable at a time considering O(N) clauses and you consider O(N) variables, which means the algorithm is polynomial). Note that the fact that we have at most two literals in a clause is crucial. If the clauses were A => B or C
or something, it wouldn't work as good.