Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for 2-Satisfiability problem

Tags:

algorithm

Can anyone explain the algorithm for 2-satisfiability problem or provide me the links for the same? I could not find good links to understand it.

like image 250
avd Avatar asked Nov 02 '09 19:11

avd


People also ask

Can 2SAT be solved in polynomial time?

Solutions for 2SAT formulae can be found in polynomial time (or it can be shown that no solution exists) using resolution techniques; in contrast, 3SAT is NP-complete.

What is satisfiability problem give an example?

Boolean Satisfiability or simply SAT is the problem of determining if a Boolean formula is satisfiable or unsatisfiable. Satisfiable : If the Boolean variables can be assigned values such that the formula turns out to be TRUE, then we say that the formula is satisfiable.

Is 2SAT P complete?

SAT is NP-complete, there is no known efficient solution known for it. However 2SAT can be solved efficiently in O ( n + m ) where is the number of variables and is the number of clauses.


2 Answers

If you have n variables and m clauses:

Create a graph with 2n vertices: intuitively, each vertex resembles a true or not true literal for each variable. For each clause (a v b), where a and b are literals, create an edge from !a to b and from !b to a. These edges mean that if a is not true, then b must be true and vica-versa.

Once this digraph is created, go through the graph and see if there is a cycle that contains both a and !a for some variable a. If there is, then the 2SAT is not satisfiable (because a implies !a and vica-versa). Otherwise, it is satisfiable, and this can even give you a satisfying assumption (pick some literal a so that a doesn't imply !a, force all implications from there, repeat). You can do this part with any of your standard graph algorithms, ala Breadth-First Search , Floyd-Warshall, or any algorithm like these, depending on how sensitive you are to the time complexity of your algorithm.

like image 184
DivineWolfwood Avatar answered Nov 11 '22 08:11

DivineWolfwood


You can solve it with greedy approach. Or using Graph theory, here is link which explains the solution using graph theory. http://www.cs.tau.ac.il/~safra/Complexity/2SAT.ppt

like image 41
rachvela Avatar answered Nov 11 '22 10:11

rachvela