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.
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
- 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.
- 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 is NP-complete, you must demonstrate two key aspects:
- Show that is in NP: You need to construct or reason out a way that proposes any solution to can be verified in polynomial time.
- NP-Hardness via Polynomial-Time Reduction:
- Start with a known NP-complete problem .
- Provide a polynomial-time reduction from to .
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 Name | Brief Description | Original NP-Complete Problem for Reduction |
| 3-SAT | CNF formula with clauses, each containing exactly 3 literals | CIRCUIT-SAT |
| CLIQUE | Finding a complete subgraph of a given size in a graph | 3-SAT |
| HAMILTONIAN CYCLE | Determining whether a graph has a cycle visiting every vertex exactly once | 3-SAT |
| SUBSET SUM | Verifying if a subset of numbers sums to a target value | PARTITION |
| VERTEX COVER | Finding a set of vertices covering all edges with minimal size | 3-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
- How to provide most relevant results with Multiple Factor Weighted Sorting
- How to randomly shuffle a list that has more permutations than the PRNG's period?
- How to rank a million images with a crowdsourced sort
- How to rearrange an array by indices array?
- How to prune neurons in neural network
- How to put the files into memory using Hadoop Distributed cache?
- How to rearrange data in array so that two similar items are not next to each other?
- How to recursively list all the files in a directory in C?

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 courseTrack 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.