Technique
2-SAT
Model each boolean variable as two literals, each clause (a or b) as implications not a -> b and not b -> a, and solve with SCCs.
Learn firstStrongly Connected Components & Condensation
0%
mastery
0/2 solved
0/2 solved
Recognise it
The signal
each item picks one of two options with pairwise constraints
1Brute force
Try all 2n assignments.
2The observation
Exponential assignments: implications propagate in the SCC condensation.
3Why it works
Unsatisfiable iff x and not x are in the same SCC; otherwise pick the literal later in topological order.
Reach for it when
- +clauses of size two
Not when
- ×clauses of size three (3-SAT is NP-hard)
Practice
0/2 solved
- Giant PizzaCSESHard
- Two Stacks SortingCSESHard
Pitfalls
Misconceptions
- !adding only one direction of each implication
Go deeper1 combinations · resources
Combinations
Strongly Connected Components & Condensation+2-SAT
each item chooses one of two options with pairwise 'at least one' constraints
- Strongly Connected Components & Condensation:
- finds contradictions x <-> not x
- 2-SAT:
- models the clauses as implications