maths.free › Discrete Math & Logic › Decision problems, satisfiability and reductions
Decision problems, satisfiability and reductions
Decision problems, polynomial time, certificates and the class NP, Boolean satisfiability, and what a reduction proves.
A decision problem is a question with a yes or no answer for each input: is this number prime, does this graph have a Hamilton cycle, is this formula satisfiable. Framing problems this way lets us compare their difficulty precisely. An algorithm runs in polynomial time if its number of steps is \( O(n^c) \) for some constant \( c \), where \( n \) is the length of the input. The class P is the set of decision problems solvable in polynomial time, and it is the standard formal meaning of "efficiently solvable".
Many problems have a different feature: a yes answer can be checked quickly given the right evidence. A proposed Hamilton cycle can be verified by walking round it, and a proposed 3-colouring by looking at each edge. The class NP is the set of decision problems for which every yes instance has a certificate of polynomial length that a polynomial-time verifier accepts, while for a no instance the verifier rejects every proposed certificate. Every problem in P is in NP (the verifier can ignore the certificate and solve the problem). Brute force solves any NP problem by trying all certificates, but there can be exponentially many of them.
The central NP problem is Boolean satisfiability (SAT): given a formula, is there an assignment of truth values that makes it true? A formula in conjunctive normal form is an AND of clauses, each an OR of variables or their negations. The example \( (p \lor q) \land (\lnot p \lor r) \land (\lnot q \lor \lnot r) \) is satisfiable (take \( p \) true, \( r \) true, \( q \) false), and the truth table finds every satisfying row. With \( n \) variables the table has \( 2^n \) rows: for 30 variables, over a billion. 2-SAT, with two literals per clause, can be solved in linear time using a graph of implications; 3-SAT has no known polynomial algorithm.
A reduction from problem \( A \) to problem \( B \) is a polynomial-time transformation of each instance of \( A \) into an instance of \( B \) with the same answer. It shows that \( B \) is at least as hard as \( A \): a fast algorithm for \( B \) would give a fast algorithm for \( A \). The direction matters, and it is the most common error: to show a new problem is hard, reduce a known hard problem to it. A small example: a set \( S \) of vertices touches every edge (a vertex cover) exactly when its complement contains no edge (an independent set), so a graph on \( n \) vertices has a vertex cover of size \( k \) if and only if it has an independent set of size \( n - k \), and each problem reduces to the other. A problem to which every NP problem reduces is NP-hard, and an NP-hard problem that is itself in NP is NP-complete. The Cook-Levin theorem (1971) shows SAT is NP-complete, and chains of reductions from it establish 3-SAT, 3-colouring, Hamilton cycle, vertex cover and thousands more.
Whether P = NP is one of the great open questions of mathematics, and one of the Clay Millennium Prize Problems. A polynomial-time algorithm for any single NP-complete problem would give one for every problem in NP; nobody has found such an algorithm, and nobody has proved that none exists. Most researchers expect P and NP to be different, but that is a belief, not a theorem: an NP-completeness proof shows a problem is as hard as any in NP, and it is only this open question that stops it from also proving that no fast algorithm exists.
Picture it: finding a satisfying assignment is searching a huge maze; checking one is following a path someone hands you. NP is the class of mazes where every exit has a short path that can be checked, and a reduction is a way of redrawing one maze as another.
Think it: NP-completeness is a statement about the worst case of a general problem, not about every instance. SAT solvers routinely handle industrial formulas with millions of variables, and special cases (2-SAT, colouring with 2 colours, trees) are easy. Proving a problem NP-complete tells you to look for special structure, approximations or good heuristics rather than a fast exact algorithm for every input.
Worked example · truth table of (p or q) and (not p or r) and (not q or not r)
Truth table of (p or q) and (not p or r) and (not q or not r)
Step by step
- \left(p \vee q\right) \wedge \left(r \vee \neg p\right) \wedge \left(\neg q \vee \neg r\right)
3 variable(s) → 8 rows. Fill in every combination.
- \
Contingent: true for some inputs, false for others.
Reveal the answer
Now you Pick a problem, or type or draw your own. Every step, a picture, the answer hidden until you ask.
Symbols used here
Tap any symbol for the full definition, a picture, and what every letter in it means.
How to: Decision problems, satisfiability and reductions
- State the problem as a decision problem with a yes or no answer.
- To show it is in NP, describe a certificate and a polynomial-time check.
- To show it is hard, choose a known NP-complete problem and transform its instances into instances of yours.
- Prove both directions: yes instances map to yes instances, and no instances map to no instances.
- Check that the transformation takes polynomial time in the input size.
Questions people ask
Does NP stand for "not polynomial"?
No. It stands for nondeterministic polynomial time: the problems a machine that could guess the certificate would solve in polynomial time.
If a problem is NP-complete, is every instance hard?
No. The classification is about the worst case over all inputs. Many instances, and many restricted versions, are solved quickly in practice.
What makes mathematics "discrete"?
It deals with separate, countable objects (integers, graphs, statements) rather than continuous quantities. No limits, no infinitesimals; instead induction, counting and logic.
How does a proof by induction work?
Show the statement for the first case, then show that whenever it holds for n it holds for n + 1. Like dominoes: the first falls, and each knocks over the next.
What order should I take these lessons in?
Logic and proof first, because every later lesson proves things. Then induction, sets, relations and functions, counting, recurrences, graphs, Boolean algebra and automata, and finally algorithms and complexity, which use nearly everything before them.
Is discrete mathematics the same as the maths of computer science?
Largely. Data structures are graphs and trees, correctness arguments are induction, running times are recurrences and sums, circuits are Boolean algebra, and what a computer can do efficiently is the subject of the last lessons. It is also ordinary mathematics in its own right.
Do I need calculus for this course?
No. School algebra is enough. A little familiarity with limits helps when comparing growth rates, and the lesson on asymptotic analysis explains the one limit fact it uses.
More in Discrete Math & Logic
Truth tablesSums and inductionProof by inductionAlgorithms and growth of functionsPredicate logic and quantifiersDirect proof, contrapositive and contradictionStrong induction and the well-ordering principleRelations: equivalence relations and partial ordersFunctions and cardinalityCounting: rules, choices and bijectionsThe pigeonhole principleSolving linear recurrence relationsGraphs: degrees, paths and connectivityTrees and spanning trees