NP Completeness Lecture Notes
NP Completeness Lecture Notes
Decision problem/ Decision algorithm: Any problem for which the answer is either zero or
one is decision problem. Any algorithm for a decision problem is termed a decision algorithm.
Optimization problem/ Optimization algorithm: Any problem that involves the identification
of an optimal (either minimum or maximum) value of a given cost function is known as an
optimization problem. An optimization algorithm is used to solve an optimization problem.
Nondeterministic Algorithms
• Algorithms with the property that the result of every operation is uniquely defined are
termed as deterministic algorithms. Such algorithms agree with the way programs are
executed on a computer.
• Algorithms which contain operations whose outcomes are not uniquely defined but are
limited to specified set of possibilities. Such algorithms are called non-deterministic
algorithms.
• The machine executing such operations is allowed to choose any one of these outcomes
subject to a termination condition to be defined later.
P Class Problems
• Problems that are in “P” class can be solved in O(Nc) (where c is some constant) by a
deterministic polynomial time algorithm.
• P is often a class of computational problems that are solvable and tractable. Tractable
means that the problems can be solved in theory as well as in practice. But the problems
that can be solved in theory but not in practice are known as intractable.
• We say we can solve these in “polynomial time”. These are the easy problems.
➢ Binary Search
➢ Sorting
➢ Matrix Multiplication
➢ Shortest Path Problems
➢ Minimal Spanning Tree
➢ Etc…
NP Class Problems
• This doesn’t say it is easy to find a solution. In fact, it is often hard to find a
solution!
• Example problems include the Traveling Salesman Problem and the Hamiltonian
Circuit Problem. Note it is easy to verify a solution.
• NP-hard problems are those that are at least as hard as the hardest problems in NP. NP-
hard problems are not required to have a solution verifiable in polynomial time.
• The concept of NP-hardness captures problems that are, in a sense, "as difficult as" NP-
complete problems, but they may not have a yes/no answer (making them a
generalization of NP-complete problems).
2. May not have polynomial-time verifiable solutions: Unlike NP-complete problems, NP-
hard problems are not required to have solutions that can be verified in polynomial time.
3. May not be decision problems: NP-hard problems can be more general than decision
problems (yes/no problems). Many NP-hard problems are optimization problems.
o Problem: Given a list of cities and the distances between them, find the shortest
possible route that visits each city exactly once and returns to the starting city.
o Why NP-Hard: The optimization version of TSP (finding the shortest path) is NP-
hard because it requires searching through many possible paths to find the
optimal solution, and it is computationally infeasible to check all possible
combinations in a reasonable time for large inputs.
o Decision version (which asks if a path exists with a total cost less than a given
value) is NP-complete, but the optimization version is NP-hard.
o Problem: Given a set of items, each with a weight and a value, determine the
number of each item to include in a collection such that the total weight does not
exceed a limit and the total value is maximized.
o Why NP-Hard: Finding the exact best combination of items is NP-hard because
there are an exponential number of possible ways to fill the knapsack. The
decision version (whether it’s possible to reach a certain value with given
constraints) is NP-complete, but optimizing for the maximum value makes it NP-
hard.
NP-complete problems are a class of problems that are both in NP and as hard as any problem
in NP. These problems represent the intersection of the classes NP (nondeterministic polynomial
time) and NP-Hard.
1. In NP: NP-complete problems belong to the class NP, meaning their solutions can be
verified in polynomial time. If a proposed solution is given, it can be checked efficiently
(in polynomial time) whether the solution is correct.
2. NP-Hard: NP-complete problems are at least as hard as any problem in NP. This means
that any problem in NP can be transformed (or reduced) to an NP-complete problem in
polynomial time. Solving an NP-complete problem efficiently (in polynomial time) would
imply that every problem in NP can be solved efficiently, thus showing that P = NP.
3. Equivalence in Hardness: All NP-complete problems are inter-reducible, meaning that
if one NP-complete problem can be solved in polynomial time, then every NP-complete
problem can be solved in polynomial time.
• NP-complete problems are central to computer science because they represent the
boundary between problems that we know how to solve efficiently (in polynomial time)
and problems that we don’t know how to solve efficiently. If any NP-complete problem is
solved efficiently, then all problems in NP can also be solved efficiently, effectively proving
that P = NP.
• However, no polynomial-time algorithm has yet been discovered for any NP-complete
problem, and it remains one of the greatest open questions in theoretical computer
science.
Polynomial time verification is a key concept for understanding the class NP (Nondeterministic
Polynomial time). This concept relates to how quickly a solution to a problem can be verified,
even if the process of finding the solution may be more complex.
What is Verification?
Verification involves checking whether a given solution to a problem is correct. For many
problems, we may not know how to quickly find a solution, but if a solution is provided, we can
efficiently verify whether it is correct.
Polynomial Time
A verification process is said to be in polynomial time if the time it takes to verify the solution
grows at most as a polynomial function of the size of the input. This means that as the size of the
input (denoted by n) increases, the time taken to verify the solution is bounded by a function like
n², n³, etc., rather than an exponential or factorial function like 2ⁿ or n!. Problems that can be
verified in polynomial time are part of the NP class.
Formal Definition
2. Given this solution, there is a verification algorithm that can check if the solution
is correct in polynomial time.
• The problem asks whether there is a route that visits all cities exactly once with a total
distance less than some value D.
• While it is hard to find the best route among many cities (this process might take
exponential time), if someone gives you a proposed route, you can easily verify if the total
distance is less than D in polynomial time by summing up the distances.
The SAT problem asks whether there exists an assignment of true/false values to variables that
satisfies a given Boolean formula.
• Finding this satisfying assignment may be hard (we don't know a quick way to solve it),
but if someone provides an assignment, we can verify whether it satisfies the formula in
polynomial time by simply evaluating the formula.
Polynomial time verification is central to the definition of NP because it means that for problems
in NP, even if we cannot solve them efficiently (in polynomial time), we can still verify the
solutions efficiently. The class NP stands for "Nondeterministic Polynomial time" because, in
theory, if we had a nondeterministic computer, it could guess the solution and verify it in
polynomial time.
Reducibility
Reducibility is a key concept used to compare the difficulty of different computational problems.
If one problem can be "reduced" to another, it means that the first problem can be solved by
transforming it into the second problem. This transformation, or reduction, helps to understand
the relative complexity of problems and is fundamental to classifying problems as NP-complete
or NP-hard.
Definition of Reducibility
Examples of Reducibility
o The Boolean satisfiability problem (SAT) was the first problem proven to be
NP-complete. The 3-SAT problem is a special case of SAT where each clause has
exactly three literals.
o The CLIQUE problem asks whether a graph contains a complete subgraph (where
every pair of vertices in the subgraph is connected) of a given size.
1. Membership in NP: The problem must belong to the class NP, meaning that given a
solution, it can be verified in polynomial time.
For example, to prove that the CLIQUE problem is NP-complete, we can take an NP-complete
problem like 3-SAT and show that every instance of 3-SAT can be transformed into an instance of
CLIQUE in polynomial time.