NP-completeness
computational complexity
algorithm theory
problem-solving
computer science

How to prove that a problem is NP complete?

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Introduction to NP Completeness

In computational complexity theory, proving that a problem is NP-complete is a crucial step in understanding its computational properties. A problem being NP-complete implies that it is as "difficult" as the hardest problems in NP (Nondeterministic Polynomial time). If one could solve an NP-complete problem efficiently (in polynomial time), all problems in NP could also be solved efficiently, which is an unsolved question in computer science, famously known as the P vs. NP problem.

Definitions

  1. NP (Nondeterministic Polynomial time): A problem is in NP if its solution can be verified in polynomial time by a deterministic Turing machine. Importantly, NP does not require that the solution be found in polynomial time, only verified.
  2. NP-Complete: A problem is NP-complete if it satisfies two conditions:
    • (NP Condition): The problem is in NP.
    • (NP-Hardness): Every problem in NP can be reduced to it in polynomial time. This implies that an efficient (polynomial time) solution to this problem would solve all NP problems efficiently.

Steps to Proving NP-Completeness

To prove a problem PP is NP-complete, you must demonstrate two key aspects:

  1. Show that PP is in NP: You need to construct or reason out a way that proposes any solution to PP can be verified in polynomial time.
  2. NP-Hardness via Polynomial-Time Reduction:
    • Start with a known NP-complete problem QQ.
    • Provide a polynomial-time reduction from QQ to PP.

Detailed Example

Let's illustrate this process with an example: proving that the 3-SAT (3-Satisfiability) problem is NP-complete.

Step 1: Show 3-SAT is in NP

For a given Boolean formula in conjunctive normal form (CNF) where each clause has exactly three literals, a nondeterministic algorithm can guess assignments of truth values to the variables. It can then verify, in polynomial time, that these assignments satisfy all clauses of the formula, hence proving membership in NP.

Step 2: Prove NP-Hardness

To establish NP-hardness, reduce another NP-complete problem, such as CIRCUIT-SAT, to 3-SAT:

  • CIRCUIT-SAT Problem: This is a known NP-complete problem where, given a Boolean circuit, the task is to determine whether there is an assignment to its inputs that makes the circuit evaluate to true.
  • Reduction Process:
    • For each gate and connection in the circuit, construct equivalent constraints in CNF with three literals per clause.
    • Ensure the clauses simulate the circuit’s behavior, making the solution to this Boolean formula correspond to a valid input for CIRCUIT-SAT.

This polynomial-time transformation from CIRCUIT-SAT implies that if you could efficiently solve 3-SAT, you could solve CIRCUIT-SAT and thus all problems in NP.

Common NP-Complete Problems

Here’s a table summarizing some well-known NP-complete problems:

Problem NameBrief DescriptionOriginal NP-Complete Problem for Reduction
3-SATCNF formula with clauses, each containing exactly 3 literalsCIRCUIT-SAT
CLIQUEFinding a complete subgraph of a given size in a graph3-SAT
HAMILTONIAN CYCLEDetermining whether a graph has a cycle visiting every vertex exactly once3-SAT
SUBSET SUMVerifying if a subset of numbers sums to a target valuePARTITION
VERTEX COVERFinding a set of vertices covering all edges with minimal size3-SAT

Additional Topics

NP-Completeness and Real-World Problems

Many real-world optimization and decision-making problems can be NP-complete. These include scheduling, routing, and resource allocation tasks. Proving NP-completeness enables researchers to focus efforts on heuristic or approximation algorithms instead of striving for efficient exact solutions.

Approximation Algorithms

For NP-complete problems, exact solutions might be intractable, but approximation algorithms offer near-optimal solutions with reasonable computational overhead. Understanding the problem's NP-completeness provides insights into the effort needed to approximate effectively.

Open Problems and Challenges

Despite advancements, no polynomial-time solutions have been found for NP-complete problems when input size grows. The P vs. NP question remains unsolved, and finding a polynomial-time solution for any NP-complete problem would revolutionize computer science and mathematics.

Conclusion

Proving NP-completeness involves understanding the systematic process of demonstrating membership in NP and showing NP-hardness. This fundamental concept reshapes how we tackle complex problems and optimizes decision-making through approximation methods when exact solutions prove elusive. As research progresses, solving NP-completeness continues to be a pivotal frontier in computational theory.


Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.