Practice Discrete Math

Algorithms / Cnf Modeling

Least You Need to Know: CNF Modeling, Clauses, and Constraint Encoding

Constraint problems are often made algorithmic by encoding decisions as Boolean variables and requirements as clauses. In conjunctive normal form (CNF), the whole formula is an AND of clauses, and each clause is an OR of literals. Modeling skill means turning real constraints into that structure cleanly.

The least you need to know

Key notation

literal a Boolean variable or its negation
clause an OR of literals
CNF an AND of clauses

Tiny worked example

  • Let `x_{i,j}` mean 'student `i` is assigned to slot `j`'.
  • An at-least-one clause can require each student to get some slot.
  • Pairwise at-most-one clauses can forbid a student from getting two different slots.
  • Satisfying assignments then correspond to legal schedules under the modeled constraints.

Common mistakes

How to recognize this kind of problem

Start practice