2-CNF Satisfiability is Poly-time Decidable
Mar. 20, 2023
2-CNF is CNF that every clause has at most two literals. The satisfiability of CNF is NP-complete in general, however 2-CNF satisfiability is special becuase it is solvable in polynomial time. Let’s call the satisfiability problem of 2-CNF as 2-SAT.
Definition. (complement) For literal , define its complement as following:
Definition. (implication graph) The implication graph of a 2-CNF formula is a directed graph . For propositional variables ,
The edge (L, M) represents the implication . For example, consider following 2-CNF formula.
Then we can draw an implication graph as follows.
For instance, the formula has clause, then there are two implications, and . These two edges exists in the graph.
Definition. (consistent) Implication graph is consistent if there is no propositional variable with paths from and .
In other words, the formula is consistent if its implication graph has no that cycle having nodes and exists.
Theorem. There is polynomial time algorithm that checks if implication graph is consistent.
It is well-known that we can build strongly connected components from directed graph in polynomial time. Also, checking if there is a component containing and for arbitrary variable takes linear time.
Finally, we can show 2-SAT is solvable in polynomial time if we show the following.
Theorem. 2-CNF formula is satisfiable iff its implication graph is consistent.
() This direction is quite trivial. Suppose is satisfiable, and implication graph is not consistent. Then there exists an satisfying assignment . If is not consistent, a propositional variable such that implications and \neg p \to p $ holds. If $A(p) = true, then does not hold. If , then does not hold. Contradiction.
() We need to show that if implication graph is consistent, then the formula is satisfiable. Claim that following algorithm always return satisfying assignment if is consistent.
Empty assignment means, is not defined for every assignment . To prove this algorithm works, we will show two invariants first.
Outer loop invariant : Any node reachable from a true node is also true.
- (base) is true for empty assignment.
- (step) If holds and there is some assigned variable, we can always choose a literal such that there is no path by consistency. After running inner loop, there is no path (assumming the ) and and there is no edge (inner loop condition). Therefore, holds after running outer loop body.
Inner loop invariant : There is no path from a true node to a false node.
- (base) Suppose is not true at the beginning of the inner loop. By , every node reachable from a true node is also true at the beginning of the outer loop. Therefore, there is no path neither nor at the beginning of the outer loop. Since is breaked after , there is a path where . From the fact that there is no path from to , so we know . Then is the literal that was assigned as false at the begnning of the outer loop body. By contrapositive of , there is a path , which is a path from true to false. However, is assigned as true at the begnning of the outer loop, so this contradicts to . Therefore the assumption is false.
- (step) Assume is true at the beginning of the inner loop. After running inner loop body, suppose does not hold. There exist a path from true to false.
If outer loop invariant is true and all variables are assigned, then for all implications , there is no case that and .