{
  "id": "np-hardness",
  "title": "NP-hardness",
  "lang": "en",
  "source_lang": "en",
  "summary": "NP-hardness classifies computational problems to which every problem in NP can be reduced in polynomial time.",
  "category": "computer-science",
  "subcategory": "algorithms-theory",
  "type": "concept",
  "aliases": [
    "NP hardness",
    "nondeterministic polynomial-time hardness"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/np-hardness/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/np-hardness/",
      "json": "https://aiwiki.page/zh/np-hardness.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "NP-hardness is a property of computational problems that are at least as hard as every problem in the complexity class NP, under a specified notion of efficient reduction. In its standard meaning, a problem is NP-hard if every problem in NP can be transformed into it by a polynomial-time many-one reduction. An efficient general algorithm for any NP-hard problem would therefore yield efficient algorithms for all problems in NP.\n\nThe concept is central to computational complexity because it allows difficulty to be established without proving a separate lower bound for each problem. NP-hardness applies to decision problems, search problems, and problems in mathematical optimization, although the precise reduction must match the kind of problem being considered. It is distinct from NP-completeness: an NP-complete problem is both NP-hard and a member of NP, whereas an NP-hard problem need not belong to NP or even be decidable.\n\nNP-hardness is a worst-case classification, not a claim that every instance is difficult or that useful computation is impossible. Its practical significance depends on input representation, structural restrictions, approximation requirements, and the resources available. It organizes both impossibility results and the search for algorithms that exploit features omitted by the unrestricted problem definition."
    },
    {
      "heading": "Formal definition and the role of NP",
      "text": "A decision problem asks a question with a yes-or-no answer. Formally, it can be represented by a language \\(L\\subseteq\\Sigma^*\\), the set of finite strings encoding yes-instances over a finite alphabet \\(\\Sigma\\). The class P consists of languages decidable by a deterministic Turing machine in time bounded by a polynomial in the input length. The class NP consists of languages whose yes-instances have certificates that can be checked in polynomial time. Equivalently, NP is the class decidable by nondeterministic Turing machines in polynomial time.\n\nThe certificate definition can be expressed using a polynomial-time verifier \\(V\\) and a polynomial \\(p\\):\n\n\\[x\\in L \\quad\\Longleftrightarrow\\quad \\exists y,\\ |y|\\le p(|x|)\\text{ such that }V(x,y)=1.\\]\n\nFor example, a satisfying assignment is a certificate for a Boolean formula's satisfiability. Checking the assignment requires evaluating the formula, not searching through all possible assignments. NP does not mean “non-polynomial”: every problem in P also belongs to NP, and whether the two classes are equal is the P versus NP problem.\n\nFor decision problems \\(L\\) and \\(H\\), a polynomial-time many-one reduction from \\(L\\) to \\(H\\), written \\(L\\le_m^p H\\), is a polynomial-time computable function \\(f\\) satisfying\n\n\\[x\\in L\\quad\\Longleftrightarrow\\quad f(x)\\in H.\\]\n\nThe target \\(H\\) is NP-hard when\n\n\\[\\forall L\\in\\mathrm{NP},\\qquad L\\le_m^p H.\\]\n\nThus, a procedure for deciding \\(H\\) would decide every NP problem after an efficient preprocessing step. If \\(H\\) itself had a polynomial-time algorithm, then \\(\\mathrm{P}=\\mathrm{NP}\\).\n\nNothing in this definition requires \\(H\\) to have efficiently checkable certificates. The halting problem, for example, is NP-hard: a Boolean formula can be transformed into a machine that systematically tests assignments and halts exactly when it finds a satisfying one. Producing the description of that machine takes polynomial time, even though its execution may not terminate. NP-hardness therefore establishes a lower bound on relative difficulty, not an upper bound or a complete classification. NP-completeness adds the upper-bound statement that the target belongs to NP.\n\nThe classification concerns a formally specified family of instances of unbounded size. A single fixed puzzle, a finite benchmark collection, or one particular industrial schedule is not NP-hard in this asymptotic sense. Establishing hardness requires defining how instances grow, how they are encoded, and what constitutes a valid answer."
    },
    {
      "heading": "Reductions and the meaning of relative difficulty",
      "text": "A polynomial-time reduction transfers the ability to solve one problem into the ability to solve another. Its direction is essential. To demonstrate that a new problem \\(H\\) is NP-hard, a standard approach reduces a known NP-hard problem \\(A\\) to \\(H\\). Reducing \\(H\\) to a known hard problem proves an upper comparison instead: it shows that solving the known problem would suffice to solve \\(H\\), not that \\(H\\) is difficult.\n\nReductions compose. If \\(A\\le_m^p B\\) and \\(B\\le_m^p C\\), then \\(A\\le_m^p C\\). Polynomial running times remain polynomial under this composition, including the time needed to write the intermediate instance. Consequently, once an NP-complete starting problem is available, proving \\(A\\le_m^p H\\) is enough to establish the NP-hardness of \\(H\\). There is no need to construct separate reductions from every language in NP. This transitivity is what makes hardness proofs form a connected theory rather than an unrelated collection of examples.\n\nThe standard many-one reduction produces a single target instance whose answer determines the source answer without further interaction. A polynomial-time Turing reduction is more permissive: it allows a polynomial-time algorithm to make multiple, possibly adaptive queries to an oracle for the target problem. A later query can depend on the response to an earlier one. Hardness under Turing reductions is therefore not automatically the same statement as hardness under many-one reductions. Terms such as “NP-hard under polynomial-time Turing reductions” identify this distinction explicitly.\n\nThe computational resources of the reduction also matter. Logarithmic-space reductions place stronger restrictions on the transformation than polynomial-time reductions and are useful for finer classifications. Conversely, an unrestricted computable reduction may perform an enormous amount of work before asking its target question. Such a reduction would not support the inference that a polynomial-time target algorithm gives a polynomial-time source algorithm. “Hardness” has meaning only relative to the reduction being used.\n\nOrdinary decision reductions preserve yes-or-no answers, but need not preserve other properties. They may substantially increase instance size, alter the number of solutions, or destroy any relationship between objective values. A reduction adequate for NP-hardness may therefore be inadequate for proving approximation hardness, counting hardness, or a sharp exponential-time lower bound. Those purposes require additional guarantees. For example, deriving a lower bound measured in the number of variables may require a reduction with nearly linear rather than merely polynomial growth."
    },
    {
      "heading": "Historical development",
      "text": "The foundations of NP-hardness emerged from attempts to understand efficient computation rather than from a known proof that particular optimization tasks require exponential time. During the 1960s, polynomial time became established as a robust mathematical model of feasible computation. Work by Alan Cobham and Jack Edmonds helped articulate its importance. Edmonds's polynomial-time algorithm for maximum matching also showed that a problem with a large combinatorial search space need not require enumerating that space.\n\nIn 1971, Stephen Cook published “The Complexity of Theorem-Proving Procedures.” Its central result established the universality of Boolean satisfiability for nondeterministic polynomial-time computation. The result is now presented as the Cook–Levin theorem: the Boolean satisfiability problem, or SAT, is NP-complete. A bounded nondeterministic computation can be encoded as a Boolean formula whose satisfying assignments correspond to accepting computation histories. This supplied a foundational hard problem from which other hardness results could follow.\n\nLeonid Levin independently developed a closely related theory of universal search problems in the Soviet Union, publishing his work in 1973. His formulation emphasized search tasks rather than only decision languages. The joint name Cook–Levin recognizes the independent origins of the central completeness result, while also reflecting that decision and search formulations are closely connected but formally different. An algorithm that merely reports whether a witness exists is not identical to an algorithm that constructs one, even when efficient reductions relate the two.\n\nRichard Karp's 1972 paper “Reducibility Among Combinatorial Problems” demonstrated the breadth of the theory through 21 combinatorial problems. Its reductions connected satisfiability with graph problems, covering and packing problems, and numerical problems. The significance was methodological: problems arising in apparently unrelated settings could share the same computational barrier. Instead of repeatedly seeking an unrestricted polynomial-time algorithm without explanation for the lack of success, researchers could identify a common consequence that such an algorithm would have.\n\nMichael Garey and David Johnson's 1979 book Computers and Intractability: A Guide to the Theory of NP-Completeness consolidated proof techniques and a large catalog of complete and hard problems. Subsequent research extended the framework to approximation, restricted graph classes, parameterized complexity, and average-case complexity. NP-hardness thus became a starting point for more detailed analysis rather than a final verdict. A hardness classification identifies a barrier for the general formulation; later work asks which modifications preserve that barrier and which permit efficient algorithms."
    },
    {
      "heading": "How NP-hardness proofs are constructed",
      "text": "A typical proof begins with a known NP-complete problem and constructs a target instance that represents its choices and constraints. The construction must be executable in polynomial time, and its correctness requires both implications: every yes-instance of the source must produce a yes-instance of the target, and every yes-instance of the target produced by the construction must correspond to a yes-instance of the source. Informal similarity between two tasks is insufficient. The correspondence must account for every legal solution of the constructed instance.\n\nA standard example reduces 3-SAT to the clique problem. Let a formula have \\(m\\) clauses, each containing three literals. Construct an undirected graph with one vertex for each literal occurrence. Join two vertices exactly when they come from different clauses and their literals are not contradictory: a variable and its negation are contradictory. Set the requested clique size to \\(m\\). The graph has \\(3m\\) vertices and at most a quadratic number of edges, so the construction has polynomial size.\n\nIf the formula is satisfiable, choose one true literal from each clause. The corresponding vertices form a clique because no two true literals contradict each other. Conversely, an \\(m\\)-vertex clique contains exactly one vertex from each clause: no two vertices from the same clause are adjacent, and there are only \\(m\\) clauses. Its chosen literals are mutually consistent, so they can be extended to an assignment satisfying every clause. This proves\n\n\\[\\varphi\\text{ is satisfiable} \\quad\\Longleftrightarrow\\quad G_\\varphi\\text{ has a clique of size }m.\\]\n\nSince 3-SAT is NP-complete, clique is NP-hard. A list of \\(m\\) vertices can also be checked in polynomial time, establishing that clique belongs to NP and is therefore NP-complete.\n\nMore elaborate reductions use gadgets, small structures that enforce particular choices or relations. In graph coloring, a gadget may represent a Boolean variable through two allowed color patterns, while another gadget excludes combinations corresponding to an unsatisfied clause. Scheduling reductions may encode a logical choice through the order of two jobs. The crucial property is not a visual resemblance to a variable or clause but a proved correspondence between the gadget's feasible configurations and the intended logical states.\n\nCommon errors include proving only one direction, allowing unintended target solutions, or hiding an exponential construction inside the reduction. Numerical constants require particular care: a number can have exponential magnitude while still having polynomially many binary digits, but explicitly producing that many vertices or time slots would take exponential space. A proof must measure the representation actually produced. Finally, proving NP-hardness and proving membership in NP are separate tasks; only their combination establishes NP-completeness."
    },
    {
      "heading": "Decision, search, optimization, and counting",
      "text": "Many important NP-hard problems are not naturally yes-or-no questions. The traveling salesperson problem asks for a minimum-length tour visiting every city and returning to the starting point. Its decision version asks whether a tour of length at most a specified bound \\(B\\) exists. For integer edge weights encoded in binary, a proposed tour can be checked by verifying the visits and summing its edge weights. The decision version belongs to NP and is NP-complete; computing an optimal tour is NP-hard because an optimal answer would immediately resolve the threshold question.\n\nThis relationship is general but requires attention to output. For a minimization problem with optimum value \\(\\operatorname{OPT}(x)\\), the threshold question has the form\n\n\\[\\operatorname{OPT}(x)\\le B.\\]\n\nAn algorithm returning an exact optimum solves that question directly. In the other direction, if objective values are integers within a known interval of polynomial bit length, a decision oracle can locate the optimum by binary search using polynomially many queries. Recovering an optimal solution, rather than just its value, may require additional structure.\n\nSAT illustrates self-reducibility, the ability to solve a search problem using decision queries about related instances. First test whether the formula is satisfiable. If it is, assign the first variable false and ask whether the resulting formula remains satisfiable. Keep that assignment if the answer is yes; otherwise assign the variable true. Repeating the procedure produces a satisfying assignment using a linear number of decision queries. This explains why a polynomial-time SAT decision algorithm would also permit efficient construction of satisfying assignments.\n\nCounting is a distinct task. Determining whether a formula has a satisfying assignment asks whether its number of solutions is positive; counting asks for the exact number. The class #P formalizes counting accepting computation paths, equivalently counting witnesses for polynomial-time predicates under the standard bounded-witness formulation. Counting satisfying assignments is #P-complete. An exact count settles satisfiability, but a satisfiability answer alone does not generally reveal the count. Counting hardness therefore captures information that ordinary NP-hardness leaves unspecified.\n\nThese distinctions also matter in computational applications. A system may be asked to find any feasible schedule, certify that none exists, minimize its total completion time, count feasible schedules, or sample from them. Such tasks can have different formal complexities even when their input data look identical. An optimization problem need not “belong to NP,” since NP is a class of decision languages. A precise account instead states that the optimization task is NP-hard and separately identifies the complexity of its associated decision or verification problems."
    },
    {
      "heading": "Encoding, weak hardness, and strong hardness",
      "text": "The length of an input is the number of symbols needed to represent it, not the magnitude of its numerical values. A nonnegative integer \\(W\\) requires only \\(O(\\log(W+1))\\) bits in binary. An algorithm whose running time is polynomial in \\(W\\) can therefore be exponential in the length of the encoding of \\(W\\). This distinction is crucial for numerical problems and for interpreting algorithms that seem to contradict an NP-hardness result.\n\nThe subset sum problem is a standard example. Given positive integers \\(a_1,\\ldots,a_n\\) and a target \\(W\\), it asks whether some subset sums to \\(W\\). A dynamic programming algorithm records which totals from \\(0\\) through \\(W\\) are achievable after processing successive integers. Its running time is \\(O(nW)\\), with a straightforward implementation using \\(O(W)\\) storage. This is a pseudo-polynomial-time algorithm: its time is polynomial in a numerical value, but not necessarily in the binary input length.\n\nA problem is strongly NP-hard, in the usual setting of numerical problems, if it remains NP-hard even under an appropriate restriction that bounds the numerical values polynomially in the nonnumerical size of the instance. Unary encoding provides a closely related way to express the distinction, because representing an integer \\(W\\) in unary requires \\(W\\) symbols. Weakly NP-complete problems such as subset sum admit pseudo-polynomial algorithms; their hardness depends essentially on the possibility of compactly encoding large numbers. Strong hardness excludes that explanation.\n\nThe 3-partition problem is a canonical strongly NP-complete problem. It is given \\(3m\\) positive integers with total sum \\(mB\\), each strictly between \\(B/4\\) and \\(B/2\\), and asks whether they can be divided into \\(m\\) groups each summing to \\(B\\). The size restrictions force every group to contain exactly three integers. The problem remains NP-complete when the numbers are polynomially bounded, making it especially useful in strong-hardness proofs for scheduling, packing, and resource allocation.\n\nThese classifications concern the specified numerical model, not just the informal description of a task. Fixed machine counts, bounded capacities, rational rather than integer input, or alternative encodings may change the complexity. A strongly NP-hard numerical problem cannot have a pseudo-polynomial exact algorithm under the usual bounded-value interpretation unless \\(\\mathrm{P}=\\mathrm{NP}\\). This conditional statement is stronger than ordinary NP-hardness, but it still says nothing by itself about which individual instances will be difficult."
    },
    {
      "heading": "Approximation and gap-preserving hardness",
      "text": "NP-hardness of exact optimization does not determine how well a problem can be approximated. An approximation algorithm runs in polynomial time and provides a proved relationship between its output and the optimum. For a minimization problem, a multiplicative factor \\(\\rho\\ge1\\) typically means that the returned feasible solution has cost at most \\(\\rho\\operatorname{OPT}\\). For maximization, a common convention requires value at least \\(\\operatorname{OPT}/\\rho\\). These guarantees concern solution quality, not exact recovery of the optimum.\n\nThe assumptions on the input can make approximation dramatically different. General traveling salesperson optimization with arbitrary nonnegative edge weights has no polynomial-time constant-factor approximation unless \\(\\mathrm{P}=\\mathrm{NP}\\). One can assign weight 1 to edges of a graph and a sufficiently large weight to nonedges, producing a large gap between instances with and without a Hamiltonian cycle. By contrast, when distances satisfy the triangle inequality, shortcutting repeated vertices does not increase tour length. For symmetric metric instances, Christofides's 1976 algorithm achieves an approximation factor of \\(3/2\\).\n\nOther problems admit approximation schemes. A polynomial-time approximation scheme, or PTAS, produces a solution within a factor \\(1+\\varepsilon\\) of optimal for a minimization problem, with polynomial running time for each fixed \\(\\varepsilon>0\\). The degree of the polynomial may depend on \\(\\varepsilon\\). A fully polynomial-time approximation scheme, or FPTAS, is polynomial in both input length and \\(1/\\varepsilon\\). The standard 0–1 knapsack optimization problem has an FPTAS despite being NP-hard. Thus, exact hardness can coexist with efficiently controllable approximation error.\n\nTo rule out approximation guarantees, a reduction must usually create a gap. Instead of merely mapping yes-instances to feasible target instances, it may map them to instances with optimum at most \\(a\\), while mapping no-instances to instances with optimum at least \\(b>a\\). An approximation algorithm strong enough to distinguish these ranges would solve the original decision problem. The transformation must preserve the promised gap, which an ordinary decision reduction need not do.\n\nThe PCP theorem, developed in the early 1990s, supplied a central foundation for approximation hardness. In its standard characterization, NP has probabilistically checkable proofs whose verifiers use logarithmically many random bits and inspect only a constant number of proof positions, with constant soundness error. This local-checking structure enables reductions that maintain a separation between fully satisfiable constraints and instances in which a nonzero fraction must be violated. The theorem and its extensions explain why approximation has a complexity theory of its own rather than following automatically from exact NP-hardness."
    },
    {
      "heading": "Structural restrictions and parameterized complexity",
      "text": "Worst-case hardness applies to the entire permitted instance family. Restricting that family can remove the structures used by a hardness reduction and make the problem tractable. SAT is NP-complete, but 2-SAT is solvable in polynomial time: clauses with at most two literals can be represented by implications, and strongly connected components detect whether a variable and its negation force each other. Horn satisfiability, in which every clause has at most one positive literal, also admits efficient algorithms through propagation of forced assignments.\n\nGraph problems provide another illustration. Finding a minimum vertex cover is NP-hard in general graphs. In bipartite graphs, however, Kőnig's theorem equates the minimum vertex-cover size with the maximum matching size, yielding a polynomial-time method. The restricted algorithm does not contradict the general hardness result because the reduction establishing general hardness does not confine its output to bipartite graphs. A restriction must be analyzed formally; descriptive claims that instances are “structured” or “sparse” do not by themselves establish tractability.\n\nParameterized complexity studies running time in terms of both total input size \\(n\\) and a chosen parameter \\(k\\). A problem is fixed-parameter tractable if it admits an algorithm with running time\n\n\\[f(k)n^{O(1)},\\]\n\nwhere the exponent of \\(n\\) is independent of \\(k\\). The function \\(f\\) may be exponential or larger. This differs from a bound such as \\(n^k\\): the latter becomes an increasingly high-degree polynomial as the parameter grows and does not establish fixed-parameter tractability.\n\nVertex cover parameterized by solution size illustrates the approach. For any uncovered edge \\(\\{u,v\\}\\), a valid cover must contain \\(u\\) or \\(v\\). Branching on these alternatives and reducing the remaining budget by one yields a search tree with at most \\(2^k\\) leaves, giving a fixed-parameter algorithm with polynomial work at each node. By contrast, clique parameterized by the requested clique size is W[1]-complete and is not known to be fixed-parameter tractable. Ordinary NP-hardness alone does not distinguish these cases.\n\nAnother useful parameter is treewidth, which measures how closely a graph can be decomposed into a tree-like arrangement of small vertex sets. Many graph problems admit dynamic programming whose exponential dependence is confined to the width of such a decomposition. Kernelization instead preprocesses an instance into an equivalent one whose size is bounded by a function of the parameter. Both methods identify concrete routes around unrestricted hardness, while parameterized lower bounds show where those routes are unlikely to succeed."
    },
    {
      "heading": "Consequences, limitations, and computational practice",
      "text": "An NP-hardness proof is not an unconditional proof that no polynomial-time algorithm exists. For the standard reductions, it establishes that such an algorithm would imply \\(\\mathrm{P}=\\mathrm{NP}\\). Nor does NP-hardness establish that exhaustive search is optimal. A problem may have exact algorithms substantially faster than naive enumeration while remaining outside polynomial time under the usual conjecture. Stronger conditional lower bounds use assumptions such as the Exponential Time Hypothesis, which asserts that 3-SAT on \\(n\\) variables cannot be solved in \\(2^{o(n)}\\) time by a deterministic algorithm.\n\nThe classification also does not locate the practical boundary between easy and hard instances. Modern SAT solvers, integer optimization systems, and constraint-programming tools routinely solve many instances of NP-hard tasks. They exploit implication propagation, learned conflicts, cutting planes, preprocessing, and branching rules. Branch-and-bound methods maintain feasible solutions and bounds on the best possible objective value, discarding regions of the search space that cannot improve the current answer. Their worst-case behavior may remain exponential even when they perform well on large structured inputs.\n\nA heuristic can find useful solutions without guaranteeing optimality or polynomial running time. Distinguishing a good feasible solution from a proof of optimality is important: some instances yield excellent solutions quickly but require much longer to exclude every better possibility. Conversely, verification can be easy when discovery is difficult. A satisfying assignment provides a short certificate for a satisfiable formula; an unsatisfiable formula has no such assignment, and proving unsatisfiability raises different proof-complexity questions.\n\nAverage-case behavior is separate from worst-case hardness. A distribution of instances may overwhelmingly generate easy cases while assigning negligible probability to the cases responsible for NP-hardness. Hardness on arbitrary inputs therefore does not by itself establish security for cryptography, where adversaries encounter inputs generated by a particular procedure and may only need to succeed with some nonnegligible probability. Cryptographic arguments require assumptions about the relevant distributions and tasks, sometimes supported by additional worst-case-to-average-case reductions.\n\nChanging the computing model also requires care. Parallel computing may accelerate search without eliminating its worst-case resource requirements. A quantum computer is not known to solve NP-complete problems in polynomial time; generic quantum search gives a quadratic improvement in query complexity, not a general polynomial-time solution. Likewise, learning-based methods can improve branching, prediction, or solution construction without establishing a worst-case complexity breakthrough. Claims about practical success, approximation guarantees, and exact polynomial-time solvability are different claims and require different evidence."
    }
  ],
  "links": [
    "computational-complexity",
    "mathematical-optimization",
    "np-completeness",
    "turing-machine",
    "p-versus-np-problem",
    "halting-problem",
    "boolean-satisfiability-problem",
    "dynamic-programming",
    "approximation-algorithm",
    "exponential-time-hypothesis",
    "heuristic",
    "cryptography",
    "parallel-computing",
    "quantum-computer"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}