3-SAT reduction to vertex cover Created 2026-10-07 Updated 2026-10-14
A polynomial-time many-one reduction represents each variable by an adjacent literal pair and each clause by a triangle in a graph. Connect each occurrence vertex to its corresponding literal vertex. A vertex cover of size must choose one literal vertex per variable and two vertices per clause, and its omitted clause vertex forces a true literal. Conversely a satisfying Boolean valuation supplies such a cover. This establishes NP-hardness of the vertex-cover decision problem from 3-SAT.
Cook-Levin theorem Created 2026-10-07 Updated 2026-10-14
Every NP verifier can be compiled into a polynomial-size Boolean circuit whose inputs encode its certificate, and then into an equisatisfiable conjunctive normal form by a Tseitin transformation. This gives a polynomial-time many-one reduction from every NP language to SAT. Checking a guessed assignment proves membership, so SAT is NP-complete.
Past exam of the mathematics course of the University of Cambridge 2003 iii Paper 37 1 Solution Created 2026-10-03 Updated 2026-10-14
A decision problem is in NP if every yes-instance has a complexity certificate of length bounded by a polynomial in the input length, and a deterministic verifier can check that certificate in polynomial time. More precisely, for some polynomial and verifier ,where runs in polynomial time. Equivalently, a nondeterministic machine decides the problem in polynomial time. A problem is NP-complete if it belongs to NP and is NP-hard: every problem in NP has a polynomial-time many-one reduction to it. Such a reduction maps instances to instances with if and only if is a yes-instance of the target problem.
For 3-SAT, the complexity certificate is one truth value for each Boolean variable. Check every Boolean literal, negate its variable's truth value when appropriate, evaluate the disjunction in each Boolean clause, and check their conjunction. This takes time linear in the encoded Boolean formula, apart from equally polynomial bookkeeping for variable names. A satisfying assignment passes; an unsatisfiable Boolean formula has no passing assignment. Thus 3-SAT belongs to NP.
For the diagram's three-colour clause gadget, name the three colours by the graph triangle . Each input is adjacent to , so each has colour or . Suppose that none has colour . Then all three have colour . Because is adjacent to and to , neither has colour . The edge forces these two colours to be and in some order. The graph triangle now forces to have colour . Since is adjacent to and , it must have colour . The graph triangle forces to have colour . But is adjacent to , which also has colour , contradicting a proper graph colouring. Therefore at least one input has colour .
To give the polynomial-time many-one reduction, use one common palette graph triangle . For each Boolean variable , create two graph vertices and join them to each other and to . This Boolean-pair colouring gadget forces them to have opposite colours . For each Boolean clause, introduce five fresh auxiliary graph vertices and the edges of the three-colour clause gadget, identifying its inputs with that clause's three Boolean literal vertices and using the common . In the notation of the diagram, its ten additional edges are the two triangles and , the bridge , and the three input edges. With variables and clauses the constructed undirected graph has vertices and at most edges. Repeated literals do not affect the argument. Its construction takes polynomial time.
A proper graph colouring defines a consistent truth assignment by declaring true precisely when its vertex has colour . The only-if result just proved makes every clause true. Conversely, a satisfying assignment colours every literal vertex consistently, and the supplied if-direction extends each satisfied clause's colours to its fresh auxiliary vertices. These extensions do not conflict, since different clauses share only already-coloured palette and literal vertices. Thus the Boolean formula is satisfiable exactly when the constructed undirected graph is three-colourable. Since 3-SAT is NP-complete, composition of reductions proves NP-hardness of the three-colourability problem.
Finally, a list of three colour labels, one for each graph vertex, is a complexity certificate for the three-colourability problem. Checking all edges takes time. Hence this problem is in NP as well, and the three-colourability problem is NP-complete.
Past exam of the mathematics course of the University of Cambridge 2007 iii Paper 40 2 Solution Created 2026-10-03 Updated 2026-10-14
An integer program for the travelling salesman problem must exclude disconnected cycle covers, not merely require one incoming and one outgoing edge. Here is a compact order formulation of the travelling salesman problem. The one-city case is trivial. For , use binary variables for directed edges, , and integer variables for . Minimize subject toThe degree equations give a collection of disjoint directed cycles. Along any selected edge between nondistinguished cities, the last inequality gives . Summing around a cycle avoiding city would yield for its positive length . Thus every cycle must contain city , so there is exactly one tour. Conversely, number the cities after city in tour order, giving . Selected edges satisfy the order inequalities. Unselected edges impose no additional restriction, since . This proves equivalence with tours, including symmetric-distance instances represented by directed variables.
There are variables and rows. For the bit count, store only nonzero coefficients and their indices. The degree equations have entries in total; each order inequality has three entries, so these too have entries. Indices and the coefficients bounded by need bits each. The objective has distance coefficients, each needing at most bits because the PDF's bound is . ThereforeWriting an unnecessarily dense constraint matrix would give a larger encoding; it is the sparse explicit encoding that establishes the requested bound. For the decision version add . A threshold can be capped at , so its relevant binary length is ; negative thresholds can be rejected immediately for nonnegative distances.
A decision problem belongs to NP if its yes-instances have certificates of polynomial length checkable in deterministic polynomial time. It is NP-complete if it belongs to NP and every NP problem has a polynomial-time many-one reduction to it. The preceding construction is a polynomial-time reduction from travelling-salesman decision to integer-linear feasibility. If the former is NP-complete, the latter is consequently NP-hard.
For completeness we must also establish membership in NP for general integer-linear feasibility, rather than just for the binary instances produced by the reduction. An arbitrary feasible integer assignment could be numerically enormous; what is needed is the existence of a short one. We give a small integer feasibility witness by homogeneous cone decomposition.
Split each unrestricted integer variable into the difference of two nonnegative integer variables and add nonnegative integer slacks to inequalities. This gives , , with variables and integer data bounded in absolute value by . Both and are polynomially bounded by the original input length. Consider the homogeneous coneEvery vector in this cone is a nonnegative combination of at most support-minimal rays. To prove this, choose a nonnegative kernel vector of minimal nonempty support contained in the support of a given vector, subtract with the smallest positive coordinate ratio, and repeat. Each subtraction strictly reduces support. On a minimal support the kernel is one-dimensional: an independent kernel direction would let us perturb a positive vector to the boundary of its support without making it zero, contradicting minimality. Cofactors of independent rows therefore give an integer nonnegative generator of each such ray. Every coordinate is bounded byusing the elementary determinant bound. This proves the needed support-minimal rays of a nonnegative kernel facts directly.
Start with any integer feasible and decompose in this way. A ray whose last coordinate is a positive integer normalizes to a point with and ; the coefficients of these normalized points sum to one. Rays with last coordinate zero have integer nonnegative first coordinates with and coordinates at most . Hencewith at most ray terms. Subtract from . The result is still integer, nonnegative and feasible, and satisfiesIts binary length is polynomial, since . The assignment can be checked by exact integer arithmetic in polynomial time. Thus general integer-linear feasibility is in NP. Combining this with the reduction proves
Past exam of the mathematics course of the University of Cambridge 2008 iii Paper 38 5 Solution Created 2026-10-03 Updated 2026-10-14
Use a complete directed graph on cities, with integral arc costs and a threshold . A symmetric cost matrix also represents the undirected travelling salesman problem by orienting a tour. Let the binary variable indicate that city follows city , and forbid self-arcs. The decision integer programming formulation asks whether the following system has a solution:The in-degree and out-degree equations make the selected arcs a cycle cover of a directed graph. Any proper graph cycle on a city set would violate its subset inequality, so the selected arcs form one Hamiltonian cycle. Conversely, a Hamiltonian cycle obeys every inequality: a proper subset cannot contain all the successor arcs of its graph vertices. Thus the binary feasibility system is equivalent to the decision travelling salesman problem. The subset formulation has exponentially many inequalities, which is harmless for this formulation; verifying a proposed tour does not require listing them.
To call this decision problem NP-complete means two separate things. It belongs to NP: a yes-instance has a polynomial-length certificate in computational complexity, namely the cyclic ordering of the cities, and a deterministic algorithm checks distinct visits, the return to the start, and the total cost in polynomial time in the binary input length. It is also NP-hard: every decision problem in NP has a polynomial-time many-one reduction to it, preserving yes and no answers. This is a statement about worst-case computation on finite encodings, not a proof that every individual tour is hard to find or that no polynomial algorithm exists; that last conclusion would require .
For the strict-threshold decision Max-TSP, choose an integer and replace each arc cost by . Every tour uses exactly arcs, soSet the new threshold to . Its encoding length, the transformed matrix's encoding length and the computation time are all polynomial in the original input length. If thresholds are required to be nonnegative, take ; the same identity works. Symmetry of costs is preserved. This is a polynomial-time many-one reduction from decision travelling salesman problem to decision Max-TSP, so the latter is NP-hard. A tour is again a polynomially verifiable certificate in computational complexity, now checking strict excess over , soFor the approximation algorithm, use the standard nonnegative-length setting on a complete graph; no triangle inequality is required. Solve the maximum-weight assignment problem with diagonal assignments forbidden, for example by applying the Hungarian algorithm to the negative weights. The resulting cycle cover of a directed graph has weight with , since every tour is an allowed assignment.
If it already has a single graph cycle, it is an optimal tour. Otherwise remove a least-weight arc from each graph cycle. A graph cycle of arcs and weight loses at most . The remaining arcs form vertex-disjoint graph paths covering all cities. Join the endpoint of each graph path to the start of the next, cyclically. The required arcs exist by completeness, and their nonnegative weights cannot diminish the retained weight. The resulting single Hamiltonian cycle therefore satisfiesThe Hungarian algorithm takes arithmetic operations, and finding the graph cycles, cutting them and patching the graph paths takes further operations. For rational or integer weights these operations have polynomial encoding length, giving polynomial time. With symmetric costs, the same directed construction is a valid undirected tour after forgetting its orientation. This is the cycle-cover patching half-approximation for Max-TSP.
Nonnegativity is essential to this multiplicative guarantee. If arbitrary signed weights were allowed, giving every arc cost would make every tour have weight , while half the optimum is . No tour could achieve the requested bound. Thus “length” has its usual nonnegative meaning in the approximation assertion.
Past exam of the mathematics course of the University of Cambridge 2012 iii Paper 42 3 a Solution Created 2026-10-03 Updated 2026-10-07
A decision problem belongs to NP if every yes-instance has a polynomial-length certificate verifiable by a deterministic polynomial-time algorithm. It is NP-hard if every problem in NP has a polynomial-time many-one reduction to it. It is NP-complete if it is both NP-hard and in NP.
A polynomial-time algorithm for any NP-complete problem would therefore give one for every problem in NP, implying . Conversely, if , all NP-complete decision problems have polynomial-time algorithms. NP-completeness does not unconditionally prove that polynomial-time solution is impossible. Optimization problems such as minimum tour cost are described as NP-hard, while their threshold decision versions can be NP-complete.
For a minimization problem with nonnegative costs, an approximation algorithm of ratio is a polynomial-time algorithm returning a feasible solution of cost at most times the optimum on every instance. For maximization, one often uses with value at least ; an equivalent convention uses ratios at most one. The metric-tour question uses the minimization convention.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 38 4 a Solution Created 2026-10-03 Updated 2026-10-07
Use the specified construction as a polynomial-time many-one reduction from 3-SAT. There are vertices and edges: one edge per variable pair, three edges per clause triangle in a graph, and three occurrence edges per clause. Any vertex cover must take at least one vertex from every variable pair and at least two from every clause triangle. Therefore every cover has at least vertices.
Given a satisfying Boolean valuation, include the vertex corresponding to the true Boolean literal in each variable pair. In each clause choose a true occurrence and omit its clause vertex, including the other two. Every variable edge and triangle edge is covered. An occurrence edge with an included clause endpoint is covered automatically; the only omitted occurrence vertex is joined to the included true-literal vertex. This is a vertex cover with exactly vertices.
Conversely, a cover of that size must use exactly one vertex in each variable pair and exactly two in each triangle. Declare a variable true precisely when its positive-literal vertex is included. Each clause has one omitted vertex. Its occurrence edge forces the corresponding literal vertex into the cover, so that literal is true. Every clause is therefore satisfied. ThusThe construction and target size are polynomial in the input length. Since 3-SAT is NP-complete, the decision problem is NP-hard. The usual “at most ” version has the same equivalence here because is an unavoidable lower bound. More generally, a cover with fewer than vertices can be padded to exactly . Verifying a proposed cover is polynomial, so the usual vertex-cover decision problem is also in NP and hence NP-complete.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 59 1 a Solution Created 2026-10-03 Updated 2026-10-07
The Cook-Levin theorem states that the Boolean satisfiability problem is NP-complete under polynomial-time many-one reductions. Membership in NP follows by guessing an assignment and evaluating the formula in time polynomial in its description length.
For hardness, let have a deterministic polynomial-time verifier , with a polynomial witness-length bound. Use a fixed polynomial certificate length: a short certificate is encoded by its length followed by padded data, and the verifier checks this encoding. Pad the computation to exactly steps, with accepting and rejecting states absorbing. Enlarge polynomially if necessary to cover input/witness initialization. A standard polynomial slowdown permits a single-tape Turing machine, so it suffices to handle that model.
Encode a tape cell by a fixed number of bits recording its alphabet symbol and either no head or the head's finite control state. Starting with one head, a cell's next label depends only on its own label and the two neighboring labels: a head can change the symbol where it sits and can enter only a neighbor. Each such finite local function has a constant-size Boolean circuit. The initial row fixes , blanks and the starting head, leaving only the witness bits as Boolean circuit inputs. There are relevant cells with blank margins beyond every possible head position, and updates. Repeating these local Boolean circuits produces a Boolean circuit of size , with an output detecting an accepting head in the final row. The construction is computable in polynomial time. Induction on rows shows that every assignment to produces exactly the verifier's valid computation; invalid local encodings can be assigned arbitrary Boolean circuit behavior because they never arise from the valid initial row.
Convert this Boolean circuit to conjunctive normal form using a Tseitin transformation. Introduce one variable for each wire, and encode each gate output by:
| Gate relation | Clauses imposing equivalence |
|---|---|
Unit clauses fix constant sources and assert the final output. Each input assignment has exactly one extension to its gate values, so the resulting formula is satisfiable precisely when some witness makes accept. It has clauses of bounded length and is produced in polynomial time. ThusThis proof also gives hardness for clauses of at most three literals, without needing a separate satisfiability assumption.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 59 1 b Solution Created 2026-10-03 Updated 2026-10-07
A proposed assignment for 2UN-SAT can be checked in polynomial time, including checking the syntactic restriction, so the language belongs to NP.
For an explicit reduction, parse any Boolean formula into a Boolean circuit over binary AND (logical conjunction), binary OR (logical disjunction) and unary NOT (negation), and apply the gate equivalences in part (a), asserting its output. Every gate clause has at most two positive literals: the AND clauses have respectively one, one and one; the OR clauses have one, one and two; and the NOT clauses have two and zero. The unit output/constant clauses also obey the restriction. Hence the resulting formula is an instance of 2UN-SAT.
The Tseitin transformation is linear in the gate description, and its auxiliary variables enforce the gate values rather than relaxing their relation to the inputs. Therefore the original formula is satisfiable if and only if the transformed restricted formula is satisfiable. This is a polynomial-time many-one reduction from SAT, whose hardness follows from the Cook-Levin theorem. ConsequentlyThe condition limits positive literals, without limiting total clause length.
Past exam of the mathematics course of the University of Cambridge 2015 iii Paper 38 4 a Solution Created 2026-10-03 Updated 2026-10-06
P is the class of decision problems decided by a deterministic algorithm in time polynomial in the encoded input length. NP is the class whose yes-instances have complexity certificates of polynomial length that a deterministic algorithm verifies in polynomial time.
A decision problem is NP-complete if it belongs to NP and is NP-hard: every problem in NP admits a polynomial-time many-one reduction to it. Such a reduction maps an instance to an instance in polynomial time and satisfies is a yes-instance if and only if is a yes-instance. Membership in NP and NP-hardness are both required.
Past exam of the mathematics course of the University of Cambridge 2015 iii Paper 38 4 e Solution Created 2026-10-03 Updated 2026-10-06
The three-colourability problem belongs to NP: a colour assignment is a polynomial-length complexity certificate, and all edges can be checked in time.
For NP-hardness, reduce 3-SAT to the three-colourability problem. Start with a palette graph triangle with vertices . Its colours are necessarily distinct, and name them by these vertices. For each Boolean variable , add vertices , join them to each other, and join each to . The graph triangle is the forcing component of the Boolean-pair colouring gadget, so the two literal vertices receive opposite colours .
For each Boolean clause, attach a fresh copy of the three-colour clause gadget, identify its with the palette vertex , and identify its three input vertices with the Boolean clause's Boolean literal vertices. Copies share only palette or literal vertices. A Boolean clause with one or two Boolean literals is padded to three by repeating a literal; an empty Boolean clause can be mapped immediately to the uncolourable graph .
Any graph colouring with three colours gives a truth assignment by reading colour as true. The three-colour clause gadget forbids three false inputs, so every Boolean clause is satisfied. Conversely, any satisfying truth assignment colours the literal pairs, and the extension property proved above independently colours the fresh auxiliary vertices of each clause. Thus the entire graph is three-colourable exactly when the formula is satisfiable.
There are vertices for variables and nonempty padded clauses, and edges. The construction is a polynomial-time many-one reduction. Using the permitted NP-completeness of 3-SAT, we obtain
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 212 2 Solution Created 2026-10-03 Updated 2026-10-06
Use the usual finite binary encoding of integer or rational input data. NP consists of decision problems whose yes-instances have polynomial-length certificates in computational complexity verifiable in polynomial time. A decision problem is NP-hard if every problem in NP has a polynomial-time many-one reduction to it. It is NP-complete if it is both NP-hard and in NP. An optimization problem is NP-hard when computing its optimum would solve every NP decision problem through a polynomial-time reduction and an optimum-value query; membership in NP applies directly to decision problems, not to an unqualified optimization task.
Reduce subset sum to the 0-1 knapsack problem by setting and . Every feasible value is at most , and the optimum equals exactly when the subset sum answer is yes. The transformation and final comparison take polynomial time. Since subset sum is assumed NP-complete, exact knapsack optimization is NP-hard.
For the half-approximation algorithm for knapsack, use nonnegative weights and profits. Delete overweight items and nonpositive-profit items; take all positive-profit zero-weight items for free. On the remaining positive-weight items, sort decreasing . Take the maximal initial prefix fitting the capacity, and stop at the first item that would overflow. Let be the prefix profit, and let be the largest profit of any individually feasible remaining item. Return the better of the prefix and that singleton, together with the free items. If every item fits, take them all.
The fractional knapsack problem fills exactly that prefix and a fraction of the first excluded item. Its optimum bounds the integer optimum, and without the free items its value is at most . ThusWith total free profit , the same inequality is . This gives an approximation ratio of in sorting time, with polynomial bit complexity for rational data. Nonnegative weights and capacity are the standard knapsack problem assumptions; unrestricted negative weights would not support this argument.
For the quadratic knapsack problem and its fractional row bound for quadratic knapsack, multiply the capacity inequality by the binary and use :Remove items with first. If , the remaining coordinates are feasible in the fractional problem defining , so . If , that row's contribution is zero. Hence, with ,The double sum counts each symmetric interaction twice; there is no factor in this problem. Each is a fractional knapsack problem, computable by sorting positive ratios, also handling zero weights separately. This takes polynomial time even when some interactions are negative, because an optional fractional item with negative profit is omitted.
The resulting 0-1 knapsack problem need not be solved exactly. Relax its capacity constraint with a Lagrange multiplier . Its Lagrangian knapsack bound isFor feasible , adding only increases its objective, and maximizing over independent binary choices produces the displayed expression. It is a convex piecewise-linear function with breakpoints at positive . Evaluate those breakpoints and zero, or use the fractional knapsack problem ordering; the best bound is computable in polynomial time. Thus computing all and one additional Lagrangian relaxation gives the requested upper bound.
For the numerical example, the problem has capacity and item ratios and . Select and . This givesAn exchange argument justifies optimality: capacity used on the lower-ratio item can be transferred to the higher-ratio item until the latter is full. The stated and similarly follow from residual capacities and . Therefore , with ratios . The fractional solution takes items and one-third of item , yielding . At the Lagrangian knapsack bound gives the same value:The fractional solution attaining proves that this is the best bound from this auxiliary Lagrangian relaxation, though it need not be the exact quadratic optimum.
For branch and bound, branch on whether an unresolved is zero or one. If the selected set is , subtract its weight from the residual capacity and retain its exact objective as a constant. For each remaining item replace by , preserving the original interactions between remaining items. Recompute the fractional row bounds and the Lagrangian knapsack bound for that residual problem. Maintain an incumbent from genuine feasible binary solutions evaluated with the quadratic objective; prune infeasible nodes and nodes whose bound is no better than the incumbent. For example, selecting items gives the feasible value . A finite binary branching tree eventually certifies the optimum, but worst-case running time is exponential, as expected for an NP-hard problem.
Past exam of the mathematics course of the University of Cambridge 2024 iii Paper 124 1 ii Solution Created 2026-09-24 Updated 2026-09-25
The problem belongs to NP: an assignment in is a polynomial-length certificate in computational complexity, and substitution verifies every equation in polynomial time.
For NP-hardness, reduce the Circuit satisfiability problem. Introduce one variable in for every wire of a Boolean circuit. A logical negation gate is enforced by , and a logical conjunction gate is enforced by . For a logical disjunction gate use the suggested quadratic equationwhich is equivalent to for bits . Add the linear equation for the designated output wire.
The construction introduces one variable and one equation per wire or gate, so it is a polynomial-time many-one reduction. A satisfying circuit input extends uniquely through its gates to a solution of the equations, and any solution gives a consistent accepting circuit computation. Since circuit satisfiability is NP-complete, quadratic-equation satisfiability over F2 is therefore
Past exam of the mathematics course of the University of Cambridge 2024 iii Paper 124 1 i Solution Created 2026-09-24 Updated 2026-09-25
This is Ladner's theorem. Assume and let be the Boolean satisfiability problem. Enumerate all clocked polynomial-time deterministic machines as and all clocked polynomial-time candidate reductions as . A standard delayed-diagonalization schedule gives a nondecreasing, unbounded, polynomial-time computable function that increases only by one. DefineThe schedule alternates two requirements. At even stage , it holds fixed while searching successively larger finite sets of strings for an on which disagrees with membership in ; after finding one it increments . At odd stage , it searches for an such thatand then increments . Length and simulation budgets are increased slowly enough that each finite search is eventually exhaustive but computing still takes polynomial time. This is achieved, for example, by permitting only simulation steps and searches on strings of logarithmic length before deciding .
Every stage must finish. If an even stage remained forever, then would eventually be a fixed even number, so and would differ on only finitely many strings. If decided , those finitely many exceptions could be hardwired to decide in P, contradicting . If an odd stage remained forever, then would eventually be odd and would be finite. A correct polynomial-time many-one reduction from to would again put in P. Thus every fails to decide , and every fails to reduce to .
Finally, : compute and, when it is even, use the usual polynomial-time certificate for satisfiability. Hence
Three-colour clause gadget Created 2026-10-06 Updated 2026-10-14
Take auxiliary graph triangles and , join to , and add edges . When has colour and the inputs have colours in , this graph admits an extension to a graph colouring with three colours exactly when at least one input is . All-false inputs force , contradicting their edge. Conversely, use if , if , and if . The extension property is necessary for both directions of a polynomial-time many-one reduction.