2SAT
2-SAT is a special case of the boolean satisfiability problem in which the formula is a conjunction of disjunctions of at most two literals. In the standard formulation, the formula is in 2-CNF: F = ∧i (ℓi1 ∨ ℓi2), where each literal ℓ is either a variable xk or its negation ¬xk. The problem asks whether there exists an assignment to the variables that makes F true.
A classic linear-time algorithm uses an implication graph. For each clause (a ∨ b), add the implications
To get a satisfying assignment, compute the SCCs of the graph (via Tarjan or Kosaraju) and consider
2-SAT runs in linear time relative to the input size: O(n + m) for n variables and m