← Lessons

quiz vs the machine

Platinum1880

Algorithms

2 SAT with SCC

Decide a formula of two literal clauses by building an implication graph and checking its strongly connected components.

7 min read · advanced · beat Platinum to climb

Clauses as implications

A 2 SAT problem is a boolean formula where every clause has two literals. Each clause that one of two literals must be true is equivalent to two implications: if the first is false then the second is true, and if the second is false then the first is true.

The implication graph

Build a directed graph with two nodes per variable, one for the variable being true and one for it being false. Add an edge for each implication. The formula is satisfiable if and only if no variable has its true node and its false node in the same strongly connected component.

  • Convert each clause into two implication edges.
  • Find strongly connected components.
  • Unsatisfiable when a variable and its negation share a component.

To extract an assignment, order components topologically and set each variable by which of its two nodes appears later.

Key idea

2 SAT reduces to an implication graph where each clause becomes two edges, and it is satisfiable exactly when no variable shares a strongly connected component with its own negation.

Check yourself

Answer to earn rating on the learn ladder.

1. How is each two literal clause represented in the implication graph?

2. When is a 2 SAT formula unsatisfiable?

3. How is a satisfying assignment read off?