2-satisfiability 2026-10-18
2-satisfiability restricts SAT to CNF in which each Boolean clause has at most two Boolean literals. The example in Boolean satisfiability problem is therefore a 2-SAT instance. Unlike general SAT and 3-SAT, 2-SAT has a polynomial-time algorithm; its tractability concerns finding a satisfying assignment or deciding that none exists, not merely checking a candidate. 3-SAT allows up to three Boolean literals per Boolean clause and is NP-complete, even though it includes many individually easy instances such as this one.[ref]
The key logical equivalence iswhere are Boolean literals. It expresses a two-Boolean literal Boolean clause as two logical implications. Representing these logical implications as edges in a directed graph gives a route to the polynomial-time algorithm. In the example, says both and : enabling the feature requires its component, and an absent component excludes the feature.
Conditional expectations algorithm cost 2026-10-18
Directly scanning all edges to evaluate each child of each of choices takes elementary operations, in Big O notation. There is a faster implementation. When assigning vertex , let and count its already assigned graph neighbours labelled zero and one. Contributions from edges not incident to are unchanged, and contributions from edges to unassigned graph neighbours stay for either choice. ThereforeChoose zero if , otherwise one: put on the side with fewer already assigned graph neighbours. With adjacency lists, scanning each vertex's list once costs operations overall and uses storage including the graph. These bounds count operations on labels and counters that fit in machine words of bits. Multiplying the conditional expectation cut formula by two also permits exact integer comparisons without rounding.
If is the size of a maximum cut, then . The constructed cut of a graph thus has size at least , an approximation ratio of in the maximization convention. The five-versus-six example illustrates the gap between this guarantee and exact optimization.
For a general randomized algorithm, the averaging proof alone does not establish efficient derandomization. One needs a polynomial number of commitments, an efficient way to find a suitable child at each step, and manageable representations and evaluation costs for the relevant conditional expectations. Those evaluations can themselves be hard. Enumerating all completions verifies this small example, but would take exponentially many assignments as grows. The polynomial-time algorithm here comes from the local conditional expectation cut formula, not from that enumeration.
Edge cover and matching identity 2026-10-25
If a finite graph has no isolated vertex, its minimum edge cover cardinality and matching number sum to its number of vertices.
Proof. Start with a maximum cardinality matching . Its unmatched vertices in a matching form an independent set, since an edge between two of them could be added. Add one incident edge for each such vertex. They are distinct, giving an edge cover of size .
Conversely, in any inclusion-minimal edge cover , every edge has an endpoint of vertex degree one in ; otherwise it could be removed. Thus each component is a star graph: two vertices of vertex degree at least two in one component would produce a graph path containing an edge with both endpoints of vertex degree at least two. If there are components, . Selecting one edge from each star graph gives a matching in a graph of size , so and . A minimum-cardinality edge cover is inclusion-minimal, completing the proof. The constructive first half also gives a polynomial-time algorithm once a maximum cardinality matching is available.
Error reduction for a randomized algorithm Created 2026-09-24 Updated 2026-10-18
Independent repetitions reduce a randomized algorithm's error probability while preserving polynomial running time.
The combining rule depends on the error orientation. For one-sided error with false acceptance probability at most , reject as soon as any trial rejects and accept only if every trial accepts. For independent trials on the same fixed negative input, false acceptance has probability at most . The protected positive inputs still always accept. If false rejection is the possible mistake instead, accept as soon as any trial accepts. This uses the decisive answer rather than a majority vote.
For constant , grows only logarithmically in to achieve error at most . A polynomial number of trials preserves a polynomial-time algorithm's running-time bound. Independence matters: repeating one answer, or evaluating at the same random point each time, supplies no new evidence. The independent repetition of a polynomial identity test gives an exact -outcome example.
A polynomial-time algorithm for integer linear feasibility gives exact rational linear programming optimization. Rational vertex bounds give a polynomial-bit bound on every finite optimal value and its denominator. An objective threshold below that bound detects unboundedness after feasibility is established. Binary search with the additional inequality localizes the finite optimum to an interval containing a unique rational of bounded denominator; continued fractions recover it exactly. A feasible optimizer can then be found by successive coordinate minimizations on a bounded optimal face. These produce faces of one fixed rational polytope, so one uniform vertex-denominator bound works throughout, avoiding exponential growth of precision requirements.
Kernelization 2026-10-24
A kernelization is a polynomial-time algorithm mapping a parameterized decision problem instance to an equivalent instance of the same problem, with both encoded length and parameter bounded by a computable function of . Equivalent means that both instances have the same yes/no answer. The bound need not be a polynomial in ; a polynomial kernel is the stronger requirement that it is. For a decidable problem, exhaustively solving the bounded output leaves only a computable dependence on , so kernelization yields fixed-parameter tractability.
Matrix rounding with fixed margins 2026-10-25
A matrix of nonnegative rational numbers with integer row and column sums can be rounded entrywise up or down while preserving all those sums. Let and be its floor and fractional part. The residual row and column sums and are nonnegative integers. Build a flow network with source-to-row flow network edge capacities , row-to-column flow network edge capacities one where , and column-to-sink flow network edge capacities . The fractional parts supply a feasible flow saturating all source arcs. The integral max-flow theorem supplies an integral one of the same total value. If its middle-arc flows are , with where , then is the required matrix. This is a constructive polynomial-time algorithm; no multiplication by a common denominator is required.
For a finite graph without an isolated vertex and with nonnegative edge weights, put and let attain this minimum. Define savings and baseline . A maximum-weight matching with weights , allowing arbitrary cardinality, gives a minimum-weight edge coverIt replaces separate cheapest coverage of two endpoints by a shared edge when doing so saves enough weight. Savings can be negative even though original costs are nonnegative; such edges need not be selected.
Proof. The construction covers all vertices. Duplicate selected edges are counted once, so nonnegative weights give . Take an optimal edge cover and delete redundant edges to make it inclusion-minimal without increasing cost. Its components are star graphs, by the argument for the edge cover and matching identity. Select one edge from each component to obtain a matching in a graph . A component with center , selected leaf and other leaves contributes to , at most its total edge weight since . Thus . Maximizing giveswhich proves both the construction and the displayed identity, including zero-weight cases. One call to a general-graph maximum-weight matching polynomial-time algorithm suffices, together with linear-time preprocessing. Choosing a maximum cardinality matching under these modified weights would impose an unnecessary constraint and can spoil the reduction.[ref]
Maximum-weight matching documentation by NetworkX. max_weight_matching, maxcardinality=False, and Notes on polynomial running time
One-sided error Created 2026-09-24 Updated 2026-10-18
A randomized decision algorithm has one-sided error when one answer is always correct and only the other answer can be mistaken.
The guarantee concerns each fixed input, with probability taken over the choices of the randomized algorithm. Always state which answer is protected. In polynomial identity testing, call an input positive when its polynomial is identically zero, and let acceptance mean claiming an identity. Then the possibilities are:
| Actual polynomial | Accept: claim identity | Reject: claim nonidentity |
|---|---|---|
| Identically zero | Always correct; every trial accepts. | Impossible with exact polynomial evaluation. |
| Nonzero | Possible mistake if the chosen point is a zero. | Always correct; the point is a witness. |
Thus a zero polynomial evaluation can leave uncertainty, but a nonzero polynomial evaluation settles the question. An error bound for a fixed nonzero polynomial is not the conditional probability that a particular accepted input is an identity; that latter question would need a distribution on the inputs as well.
In computational complexity theory, a polynomial-time algorithm with this orientation and false acceptance probability at most establishes membership in co-RP. Reversing the question to ask whether the polynomial is nonzero gives the RP orientation: negative instances are always rejected. The random evaluation test for a polynomial identity explains the required field, total degree, sampling and evaluation assumptions.
Past exam of the computer science course of the University of Oxford 2019 Algorithms 1 c Solution 2026-10-25
A path-cycle matching is exactly an edge subset whose resulting subgraph has maximum degree at most two: every nontrivial connected component of a graph of this form is a graph path or a cycle in a graph. Thus the task is a bipartite b-matching problem with bound two at every vertex.
Find a bipartition , orient every original edge from to , and add a source and sink . Give each arc , for , flow network edge capacity two; each original arc flow network edge capacity one; and each arc , for , flow network edge capacity two. Compute an integral maximum flow and select the original edges whose flow is one. The integral max-flow theorem guarantees such an integral optimum.
By flow conservation, at most two selected edges touch each vertex, so they decompose into the required vertex-disjoint paths and cycles in a graph. Conversely, any permissible path-cycle matching gives a feasible flow: send one unit through its middle arc for each selected edge, with the outside arc amounts equal to the endpoint degrees. In both directions, the flow value equals the number of selected edges. Maximizing either quantity therefore maximizes the other.
The blue edges in this example form a four-cycle in a graph and a one-edge graph path; the dashed edge is unused. Their five units of flow are optimal: the two left vertices can each contribute at most two selected edges, and has only one incident edge.
The constructed flow network has vertices and arcs. A polynomial-time algorithm for maximum flow, such as the Edmonds–Karp algorithm, followed by a traversal of the selected subgraph, gives an efficient solution.
Past exam of the computer science course of the University of Oxford 2019 Algorithms 3 d ii Solution 2026-10-25
The optimum radius is a distance from some city to a selected city, so it belongs toSort the distinct values of , try them in increasing order, and run part (i)'s greedy procedure with each trial value . Declare a trial successful when all cities are covered using at most centers; stop a failed trial as soon as a st center would be selected. The trial must succeed by part (i), so the first successful value satisfies . Its output hasThere are candidate distances and work per trial, giving a polynomial-time algorithm with running time , plus sorting. Success at need not mean that radius itself is feasible; only the radius- guarantee is used.
A faster alternative is the farthest-first traversal. Choose any first center, then repeatedly choose a city farthest from its nearest current center until have been chosen. Let be the resulting radius. If , adjoin a city attaining that distance. At every earlier selection, the maximum distance to the then-current center set was at least , so all pairs among these cities are at distance at least . Two belong to the same optimal radius- closed ball, giving by the triangle inequality. If , the guarantee is immediate. Maintaining nearest-center distances gives distance evaluations without knowing .
Use minimum-weight edge cover by matching savings. Reject inputs with an isolated vertex. For every vertex , choose a cheapest incident edge and write . Define a baseline and a saving for each edge byCompute a maximum-weight matching using as its weights, allowing the empty matching in a graph and imposing no maximum-cardinality condition. Negative savings may be ignored. ReturnThis is an edge cover. Since original weights are nonnegative, removing duplicate appearances of an edge cannot increase the total, and henceTo prove optimality, take a minimum-weight edge cover and remove redundant edges until it is inclusion-minimal. Nonnegative weights ensure that its weight does not increase, so it remains optimal. As proved in (i), its components are star graphs. Choose one edge from each star graph, forming a matching in a graph .
In a star graph with center , selected leaf , and other leaves , this choice contributes to . Each other leaf has its edge available, so . Thus this contribution is at most the weight of that star graph. Summing over components yieldsSince maximizes saving, , and consequentlyAll inequalities are equalities. Therefore is a minimum-weight edge cover. This proof also handles zero weights and duplicate cheapest-edge choices.
Finding all and constructing takes time. A general-graph maximum-weight matching polynomial-time algorithm supplies the only substantial step; the documented routine runs in arithmetic time. Exact rational or integer weights avoid floating-point comparisons affecting optimality.[ref]
Maximum-weight matching documentation by NetworkX. max_weight_matching, maxcardinality=False; Notes: O(number_of_nodes ** 3), integer arithmetic for integer weights, and floating-point precision caveat
First test for an isolated vertex, reporting infeasibility if one exists. Otherwise compute a maximum cardinality matching using a general-graph polynomial-time algorithm, then add one arbitrary incident edge for each unmatched vertex in a matching. The proof in (i) shows that the resulting edge cover has minimum cardinality .
The final scan takes time with adjacency lists; the maximum cardinality matching computation is polynomial. One may obtain it from a general-graph maximum-weight matching routine with every weight equal to one.[ref]
Maximum-weight matching documentation by NetworkX. max_weight_matching, unit weights give maximum cardinality; Notes: cubic vertex-count running time
Past exam of the mathematics course of the University of Cambridge 2002 iii Paper 34 5 Solution Created 2026-10-03 Updated 2026-10-14
For the metric travelling salesman problem, a tour is a polynomial-size complexity certificate: list the vertices in cyclic visiting order. In polynomial time verify that every vertex occurs exactly once, add the encoded integer edge costs and compare the sum with the threshold. The certificate has bits, and addition uses a number of bits polynomial in the input length. If validity of the metric input is not treated as a promise, nonnegativity, symmetry and all triangle inequalities can also be checked in polynomial time. Therefore the decision problem belongs to NP.
An evaluation algorithm immediately decides a threshold instance by computing the optimum and comparing it with . Conversely, suppose there is a polynomial-time decision algorithm. The optimum is an integer in , where is the largest edge cost; any fixed cyclic ordering gives the upper bound. Binary search on this interval using threshold queries finds the exact minimum. It makes queries, and every queried threshold has polynomial encoding length. Thus the time is polynomial in the bit length, even when is numerically large. Zero-cost and trivial small instances can be handled directly. ConsequentlyThis concerns the optimum value; constructing an optimal tour is the separate optimization task.
For the hardness reduction, start with an undirected graph on vertices and form the complete graph with costsThese costs satisfy the triangle inequality, since every direct cost is at most two and every two-edge path costs at least two. Set the threshold to . Every tour has exactly edges, each costing at least one. Hence it has cost at most precisely when all its edges came from , which is precisely the existence of a Hamiltonian cycle in . The construction and threshold encoding are polynomial-time. Thus the assumed NP-completeness of the Hamiltonian circuit problem gives NP-hardness of metric TSP; together with its NP membership this proves NP-completeness of metric TSP decision.
For the approximation, compute a minimum spanning tree . Deleting any one edge of an optimal tour leaves a spanning tree, so nonnegative costs implyDouble every tree edge. The resulting connected multigraph has even degrees and hence an Euler circuit, of cost . Traverse it and skip previously visited vertices, except for the final return to the start. Each skip replaces a path by its direct edge; repeated use of the triangle inequality shows that no replacement increases cost. The result is a tour visiting every vertex exactly once and satisfyingThe Euler traversal and shortcutting take polynomial time, so the assumed polynomial-time MST routine supplies the requested polynomial-time algorithm. This is the double-tree approximation for metric TSP. In the relative-error convention, when the optimum is positive, explaining the printed term “1-approximation”; in the multiplicative convention it is a factor-two approximation. If the optimum is zero, the same bound forces the returned tour to have zero cost as well.
Past exam of the mathematics course of the University of Cambridge 2006 iii Paper 38 1 Solution Created 2026-10-03 Updated 2026-10-14
Introduce slack variables . The initial simplex dictionary isAll six variables are nonnegative. The given rule is the Dantzig pivot rule: select the nonbasic variable with the largest positive reduced cost. It applies to slack variables too once they become nonbasic. At each step the simplex ratio test limits how far that entering variable can increase before a basic variable reaches zero.
The successive objective rows of the simplex dictionary, expressed in the current nonbasic variables, areThese rows identify each entering variable unambiguously. Performing the corresponding simplex ratio tests gives the complete pivot sequence:For example, after pivot two the dictionary has , and . Although increasing improves the objective at rate four, reaches zero first at , giving pivot three. After pivot four, and ; the upper bound gives pivot five.
In the final objective row every reduced cost is nonpositive. Since , it also directly certifies the upper bound , attained only when all three vanish. Thus
A greatest improvement pivot rule uses the total feasible increase in the objective, rather than its increase per unit of the entering variable. At the origin, the three candidate edge moves have improvements , and . It therefore brings into the simplex basis first, with leaving, and immediately reaches the optimum. This rule solves this instance in one pivot.
This is a three-dimensional Klee-Minty cube example: the specified Dantzig pivot rule visits every vertex before reaching the optimum. Higher-dimensional versions require pivots, so that rule has exponential worst-case running time despite its strong practical performance. Each pivot requires only polynomially many arithmetic operations. An anti-cycling rule such as the Bland pivoting rule ensures finite termination; without one, degenerate pivots can cycle. A crude terminating bound is the number of possible bases, for constraints and original variables, which can be exponential. This does not show that every conceivable pivot rule must take exponential time. Linear programming itself has polynomial-time algorithms, including the ellipsoid method and suitable interior-point methods.
Past exam of the mathematics course of the University of Cambridge 2006 iii Paper 38 3 Solution Created 2026-10-03 Updated 2026-10-14
For decision problems, the usual meaning of “no harder” is a polynomial-time reduction: if there is a polynomial-time computable map taking each instance of to an instance of such that is a yes-instance exactly when is. A polynomial-time algorithm for would then solve in polynomial time. A problem is NP-hard if every problem in NP admits such a reduction to it.
For a zero-sum game with rational payoff matrix , the row player can calculate its value by linear programming:The minimax theorem identifies this optimum with the game value. Rational linear programming has polynomial-time algorithms, and an optimal rational value can be compared exactly with rational in polynomial time in the binary input length. Thus the decision problem belongs to P. If it were NP-hard, composing the reductions with this algorithm would put every problem in NP in P, contradicting the assumed separation. ThereforeThe finite rational encoding is part of the computational model; arbitrary real inputs without an encoding would not define the same complexity question.
For the set cover reduction to equilibrium support, first take and assume every element belongs to some subset. Suppose rows cover . Let player 1 use the uniform mixed strategy on these rows and let player 2 play column . The row player's payoff is one for every row, so any row mixture is a best response to column . If denotes the probability that a random supported row covers element , then , and player 2's payoff from column isColumn also pays one. It is therefore a best response, giving a Nash equilibrium whose row-player support of a mixed strategy contains exactly rows.
Conversely, suppose an equilibrium has row support of size , and some element is not covered by . For that column , so player 2 can earn . This is the largest possible column payoff, and it is attained exactly at columns corresponding to elements uncovered by . The column player's mixed strategy must consequently put all its probability on these columns, with none on column . Every currently supported row gives player 1 payoff zero. Choose any positive-probability column ; because , there is some row containing . Deviating to gives strictly positive expected payoff, contradicting the best response condition. Thus must be a cover, provingunder the stated union and conditions.
The printed formulation omits both conditions. For , its payoffs contain division by zero. Without the union condition its claimed implication is false: take , , and . No selection covers , but any row mixture supported on two rows, paired with pure column , is a Nash equilibrium. The row player always gets zero, and column is the column player's strictly optimal choice with payoff two. This gives an explicit counterexample to the unrestricted wording.
These restrictions do not weaken the complexity conclusion. The set cover problem remains NP-complete when every element occurs in some subset and : globally uncovered elements and the easy cases can be recognized and replaced by fixed promised yes- or no-instances. A cover by at most subsets can be padded to exactly . The constructed game has polynomial size, so deciding whether a Nash equilibrium of the specified support size exists is NP-hard. Computing a complete description of all equilibria would resolve this question and hence is at least this difficult. In addition, the equilibrium set may be infinite; a complete output must then describe families rather than list individual points. There is a finite representation by feasible pairs of supports and their associated strategy polytopes, but there are exponentially many support pairs to consider. This reduction concerns locating specified supports or describing all equilibria, rather than finding one unrestricted equilibrium.
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 b Solution Created 2026-10-03 Updated 2026-10-14
Let the bipartite graph have parts . Add a source , a sink , capacity-one edges for and for , and capacity on each original edge directed . Use the max-flow min-cut theorem: maximum flow value equals minimum cut capacity. Also use Integrality of the Ford-Fulkerson algorithm: integral capacities admit an integral maximum flow, found by integral augmenting paths.
An integral flow selects a matching in a graph, because each left and right vertex carries at most one unit. Conversely every matching gives a unit flow along its selected paths. Hence maximum flow value equals maximum matching cardinality.
A minimum cut has capacity at most , whereas crossing even one original edge would cost . For its source side , no edge of the original graph runs from to . Thereforeis a vertex cover, and its cardinality is exactly the cut capacity. Conversely, given any cover , use . No original edge crosses this cut, because both its endpoints would otherwise be outside the cover; its capacity is . Thus minimum cut capacity equals minimum cover size, proving Kőnig's theorem for bipartite matching:For the algorithm, repeatedly find augmenting paths in the residual network, then take to be the vertices reachable from . Each integral augmentation increases flow by at least one; the total value is at most . Each reachability search takes time, so this procedure takes time. The network uses only polynomially many edges and integer capacities, yielding the requested polynomial-time algorithm and an explicit cover.
Precondition-free STRIPS planning 2026-10-24
Automated planning with ground actions that are always applicable because their precondition sets are empty. Delete effects are still permitted, so taking the union of all add effects does not decide reachability. With a positive conjunctive goal, the last-achiever algorithm for precondition-free planning gives a polynomial-time algorithm.
Let be a nonzero multivariate polynomial over a field , with total degree at most . Choose a nonempty finite set . For independent random variables , each with a uniform distribution on a finite set on , the Schwartz-Zippel lemma givesNonzeroness is essential; the zero polynomial always evaluates to zero. The total degree sums exponents within each monomial, rather than taking their maximum: has total degree five. The field need not be finite, but must be finite. The estimate reduces error only when .[ref]
CMPT 710 - Complexity Theory: Lecture 18. CMPT 710 and CMPT 407 - Computational Complexity - Fall 2007; CMPT 710 - Complexity Theory: Lecture 18, §3.1, pp. 3–4: Lemma 4 and its inductive proof
The proof begins with the root bound for a polynomial. For several variables, write , with . The total degree of is at most . By induction, vanishes with probability at most . Otherwise the remaining univariate polynomial has at most polynomial roots. Adding the two contributions gives .[ref]
CMPT 710 - Complexity Theory: Lecture 18. CMPT 710 and CMPT 407 - Computational Complexity - Fall 2007; CMPT 710 - Complexity Theory: Lecture 18, §3.1, pp. 3–4: split by the leading coefficient in the last variable
The algorithm samples a point, performs exact polynomial evaluation, rejects the identity if the value is nonzero, and otherwise accepts. The lemma bounds false acceptance for every fixed nonzero input. For the polynomial identity testing over a finite field example, has and , so its exact error attains the bound. Numerical near-zero values from floating-point arithmetic do not satisfy this exact algebraic contract. A polynomial-time algorithm claim additionally needs efficient sampling and evaluation, including the bit cost of representing and operating on field elements. Counting field operations alone does not establish that cost.
