Apex › Storage & databases

2-SAT — boolean satisfiability in linear time

General SAT is NP-complete, but restrict every clause to two literals and it becomes solvable in linear time by a beautiful reduction to graph theory. A clause (a ∨ b) is two implications (¬a ⇒ b, ¬b ⇒ a); build the implication graph and the formula is unsatisfiable exactly when some variable and its negation land in the same strongly-connected component. One SCC pass decides it and builds a satisfying assignment. Pick a formula and watch the components and verdict.

More in Storage & databases