0% found this document useful (0 votes)
847 views7 pages

Understanding NP-Completeness and Hardness

This document discusses NP-complete problems and polynomial time reductions. It begins by defining NP-completeness and what it means for a problem to be NP-hard or NP-complete. It then explains that a problem is NP-complete if it is in NP and is as hard as any other problem in NP. The document provides examples of NP-complete problems like the traveling salesman problem. It also discusses how reductions can be used to show that if one NP-complete problem can be solved in polynomial time, then all NP problems can be solved in polynomial time. Reductions map one problem to another to show the first problem can be solved via the second.

Uploaded by

Monica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
847 views7 pages

Understanding NP-Completeness and Hardness

This document discusses NP-complete problems and polynomial time reductions. It begins by defining NP-completeness and what it means for a problem to be NP-hard or NP-complete. It then explains that a problem is NP-complete if it is in NP and is as hard as any other problem in NP. The document provides examples of NP-complete problems like the traveling salesman problem. It also discusses how reductions can be used to show that if one NP-complete problem can be solved in polynomial time, then all NP problems can be solved in polynomial time. Reductions map one problem to another to show the first problem can be solved via the second.

Uploaded by

Monica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • NP Complete and NP Hard
  • NP Hard Problems
  • NP-Completeness and Reducibility
  • NP Complete Problems

UNIT V

NP COMPLETE AND NP HARD


NP-Completeness: Polynomial Time – Polynomial-Time Verification – NP-
Completeness and Reducibility – NP-Completeness Proofs – NP-Complete
Problems.
NP-COMPLETENESS
A problem is in the class NPC if it is in NP and is as hard as any problem in NP. A
problem is NP-hard if all problems in NP are polynomial time reducible to it, even though it
may not be in NP itself.

If a polynomial time algorithm exists for any of these problems, all problems in NP
would be polynomial time solvable. These problems are called NP-complete. The phenomenon
of NP-completeness is important for both theoretical and practical reasons.

Definition of NP-Completeness
A language B is NP-complete if it satisfies two conditions
 B is in NP
 Every A in NP is polynomial time reducible to B.
If a language satisfies the second property, but not necessarily the first one, the
language B is known as NP-Hard. Informally, a search problem B is NP-Hard if there exists
some NP-Complete problem A that Turing reduces to B.
The problem in NP-Hard cannot be solved in polynomial time, until P = NP. If a problem is
proved to be NPC, there is no need to waste time on trying to find an efficient algorithm for it.
Instead, we can focus on design approximation algorithm.

POLYNOMIAL TIME:
NP class contains P class as a subset. NP problems being hard to solve.

Definition of P class Problem: - The set of decision-based problems come into the division of P
Problems who can be solved or produced an output within polynomial time. P problems being
easy to solve
Definition of Polynomial time: - If we produce an output according to the given input within a
specific amount of time such as within a minute, hours. This is known as Polynomial time.

Definition of Non-Polynomial time: - If we produce an output according to the given input but
there are no time constraints is known as Non-Polynomial time. But yes output will produce but
time is not fixed yet.:00/04:47

Definition of Decision Based Problem: - A problem is called a decision problem if its output is
a simple "yes" or "no" (or you may need this of this as true/false, 0/1, accept/reject.) We will
phrase many optimization problems as decision problems. For example, Greedy method, D.P.,
given a graph G= (V, E) if there exists any Hamiltonian cycle.

Definition of NP-hard class: - Here you to satisfy the following points to come into the division
of NP-hard

1. If we can solve this problem in polynomial time, then we can solve all NP problems in
polynomial time
2. If you convert the issue into one form to another form within the polynomial time

Definition of NP-complete class: - A problem is in NP-complete, if

1. It is in NP
2. It is NP-hard

Pictorial representation of all NP classes which includes NP, NP-hard, and NP-complete

NP-Complete Problems
Following are some NP-Complete problems, for which no polynomial time algorithm is known.

 Determining whether a graph has a Hamiltonian cycle


 Determining whether a Boolean formula is satisfiable, etc.
NP-Hard Problems
The following problems are NP-Hard

 The circuit-satisfiability problem


 Set Cover
 Vertex Cover
 Travelling Salesman Problem
In this context, now we will discuss TSP is NP-Complete

TSP is NP-Complete
The traveling salesman problem consists of a salesman and a set of cities. The salesman has to
visit each one of the cities starting from a certain one and returning to the same city. The
challenge of the problem is that the traveling salesman wants to minimize the total length of the
trip

POLYNOMIAL TIME VERIFICATION


Before talking about the class of NP-complete problems, it is essential to introduce the notion of
a verification algorithm.

Many problems are hard to solve, but they have the property that it easy to authenticate the
solution if one is provided.

Hamiltonian cycle problem:-


Consider the Hamiltonian cycle problem. Given an undirected graph G, does G have a cycle that
visits each vertex exactly once? There is no known polynomial time algorithm for this dispute.
Note: - It means you can't build a Hamiltonian cycle in a graph with a polynomial time even if
there is no specific path is given for the Hamiltonian cycle with the particular vertex, yet you
can't verify the Hamiltonian cycle within the polynomial time

Fig: Hamiltonian Cycle


ava Program for Beginners

Let us understand that a graph did have a Hamiltonian cycle. It would be easy for someone to
convince of this. They would similarly say: "the period is hv3, v7, v1....v13i.

We could then inspect the graph and check that this is indeed a legal cycle and that it visits all of
the vertices of the graph exactly once. Thus, even though we know of no efficient way to solve
the Hamiltonian cycle problem, there is a beneficial way to verify that a given cycle is indeed a
Hamiltonian cycle.

Note:-For the verification in the Polynomial-time of an undirected Hamiltonian cycle graph G. There
must be exact/specific/definite path must be given of Hamiltonian cycle then you can verify in the
polynomial time.

Definition of Certificate: - A piece of information which contains in the given path of a vertex
is known as certificate

Relation of P and NP classes


1. P contains in NP
2. P=NP

1. Observe that P contains in NP. In other words, if we can solve a problem in polynomial time, we
can indeed verify the solution in polynomial time. More formally, we do not need to see a
certificate (there is no need to specify the vertex/intermediate of the specific path) to solve the
problem; we can explain it in polynomial time anyway.
2. However, it is not known whether P = NP. It seems you can verify and produce an output of the
set of decision-based problems in NP classes in a polynomial time which is impossible because
according to the definition of NP classes you can verify the solution within the polynomial time.
So this relation can never be held.

NP-COMPLETENESS AND REDUCIBILITY


A decision problem L is NP-Hard if

L' ≤p L for all L' ϵ NP.

Definition: L is NP-complete if

1. L ϵ NP and
2. L' ≤ p L for some known NP-complete problem L.' Given this formal definition, the complexity
classes are:

P: is the set of decision problems that are solvable in polynomial time.

NP: is the set of decision problems that can be verified in polynomial time.

NP-Hard: L is NP-hard if for all L' ϵ NP, L' ≤p L. Thus if we can solve L in polynomial time,
we can solve all NP problems in polynomial time.

NP-Complete L is NP-complete if

1. L ϵ NP and
2. L is NP-hard

If any NP-complete problem is solvable in polynomial time, then every NP-Complete problem is
also solvable in polynomial time. Conversely, if we can prove that any NP-Complete problem
cannot be solved in polynomial time, every NP-Complete problem cannot be solvable in
polynomial time.

Reductions:
The class NP-complete (NPC) problems consist of a set of decision problems (a subset of
class NP) that no one knows how to solve efficiently. But if there were a polynomial solution for
even a single NP-complete problem, then every problem in NPC will be solvable in polynomial
time. For this, we need the concept of reductions.

Suppose there are two problems, A and B. You know that it is impossible to solve
problem A in polynomial time. You want to prove that B cannot be explained in polynomial
time. We want to show that (A ∉ P) => (B ∉ P)

Consider an example to illustrate reduction: The following problem is well-known to be


NPC:

3-color: Given a graph G, can each of its vertices be labeled with one of 3 different
colors such that two adjacent vertices do not have the same label (color).

Coloring arises in various partitioning issues where there is a constraint that two objects
cannot be assigned to the same set of partitions. The phrase "coloring" comes from the original
application which was in map drawing. Two countries that contribute a common border should
be colored with different colors.
It is well known that planar graphs can be colored (maps) with four colors. There exists a
polynomial time algorithm for this. But deciding whether this can be done with 3 colors is hard,
and there is no polynomial time algorithm for it.

Fig: Example of 3-colorable and non-3-colorable graphs.

Polynomial Time Reduction:


We say that Decision Problem L1 is Polynomial time Reducible to decision Problem L2 (L1≤p L2)
if there is a polynomial time computation function f such that of all x, xϵL1 if and only if xϵL2

NP-COMPLETENESS PROOFS
To prove TSP is NP-Complete, first we have to prove that TSP belongs to NP. In TSP,
we find a tour and check that the tour contains each vertex once. Then the total cost of the edges
of the tour is calculated. Finally, we check if the cost is minimum. This can be completed in
polynomial time. Thus TSP belongs to NP.
Secondly, we have to prove that TSP is NP-hard. To prove this, one way is to show
that Hamiltonian cycle ≤p TSP (as we know that the Hamiltonian cycle problem is
NPcomplete).
Assume G = (V, E) to be an instance of Hamiltonian cycle.
Hence, an instance of TSP is constructed. We create the complete graph G' = (V, E'), where
E′={(i,j):i,j∈Vandi≠jE′={(i,j):i,j∈Vandi≠j
Thus, the cost function is defined as follows −
t(i,j)={01if(i,j)∈Eotherwiset(i,j)={0if(i,j)∈E1otherwise
Now, suppose that a Hamiltonian cycle h exists in G. It is clear that the cost of each edge
in h is 0 in G' as each edge belongs to E. Therefore, h has a cost of 0 in G'. Thus, if graph G has
a Hamiltonian cycle, then graph G' has a tour of 0 cost.
Conversely, we assume that G' has a tour h' of cost at most 0. The cost of edges
in E' are 0 and 1 by definition. Hence, each edge must have a cost of 0 as the cost of h' is 0. We
therefore conclude that h' contains only edges in E.
We have thus proven that G has a Hamiltonian cycle, if and only if G' has a tour of cost
at most 0. TSP is NP-complete
NP-COMPLETE PROBLEMS
A problem is called NP (nondeterministic polynomial) if its solution can be guessed and
verified in polynomial time; nondeterministic means that no particular rule is followed to make the guess.
If a problem is NP and all other NP problems are polynomial-time reducible to it, the problem is NP-
complete.

NP problem: - Suppose a DECISION-BASED problem is provided in which a set of inputs/high


inputs you can get high output.

Criteria to come either in NP-hard or NP-complete.

1. The point to be noted here, the output is already given, and you can verify the output/solution
within the polynomial time but can't produce an output/solution in polynomial time.
2. Here we need the concept of reduction because when you can't produce an output of the problem
according to the given input then in case you have to use an emphasis on the concept of reduction
in which you can convert one problem into another problem.

Note1:- If you satisfy both points then your problem comes into the category of NP-complete class

Note2:- If you satisfy the only 2nd points then your problem comes into the category of NP-hard
class

So according to the given decision-based NP problem, you can decide in the form of yes or no.
If, yes then you have to do verify and convert into another problem via reduction concept. If you
are being performed, both then decision-based NP problems are in NP compete.

Common questions

Powered by AI

Focusing on approximation algorithms is recommended for NP-complete problems because such problems are believed to lack polynomial-time solutions, implying they are computationally intractable to solve exactly for large inputs. Approximation algorithms provide a practical approach by delivering near-optimal solutions within a reasonable time, often with provable guarantees on how close the solution is to the optimal. This focus allows real-world applications to manage problem complexity pragmatically, balancing computational limits against solution quality rather than pursuing exact solutions that are infeasible to obtain efficiently .

To demonstrate that the Traveling Salesman Problem (TSP) is NP-complete, it is necessary to show that TSP is both in NP and NP-hard. TSP is in NP because if a solution (a tour) is given, it can be verified quickly by checking if each vertex is visited exactly once and the total cost is minimal, which can be done in polynomial time. To show that TSP is NP-hard, we can use a known NP-complete problem, like the Hamiltonian cycle problem, to reduce it to TSP. By constructing a complete graph where the cost is minimal if edges correspond to those in a Hamiltonian cycle, one can prove that finding a zero-cost tour corresponds directly to finding a Hamiltonian cycle, thus proving TSP's NP-hardness .

NP-complete problems are distinguished from NP-hard problems based on their membership in the NP class. A problem is NP-complete if it is both in NP and as hard as any problem in NP, meaning all NP problems can be reduced to it in polynomial time. In contrast, a problem is NP-hard if all problems in NP can be reduced to it in polynomial time, but it may not be verifiable in polynomial time (and hence not necessarily in NP). This distinction is significant because it impacts whether we can efficiently verify solutions to these problems. NP-complete problems allow for efficient verification (important for practical applications), whereas NP-hard problems may not provide this assurance .

Nondeterminism in the context of NP problems refers to the theoretical concept that a solution can be guessed and then verified efficiently, even if it cannot be easily or deterministically computed. This means given the right 'guess', a computer could verify the correctness of a solution quickly (in polynomial time). Nondeterminism influences computational complexity by highlighting the distinction between problems we can verify quickly (NP) and those we can solve quickly (P). This forms the basis for the critical question of whether all problems that can be verified quickly can also be solved quickly, encapsulated in the P vs NP problem .

The phrase 'coloring' is relevant to illustrating NP-complete problems through reductions as it connects the practical applications of graph colorability to theoretical complexity frameworks. For example, the 3-coloring problem demonstrates NP-completeness, indicating the difficulty of partitioning graph vertices into three sets while ensuring adjacency constraints. By showing reductions from known NP-complete problems to graph colorability issues, the coloring problem serves as a concrete instance that aids in understanding how complex problems can be transformed to showcase their inherent computational difficulty. This exemplifies how a seemingly simple task (assigning colors) encapsulates deeper theoretical challenges in determining efficient solutions .

In the context of NP problems, a 'certificate' serves as a piece of information that aids in verifying the correctness of a given solution. If a problem is in NP, then any 'yes' instance of the problem has a polynomial-time verifiable certificate that can confirm the solution's validity. This concept is essential as it enables quick confirmation of correct solutions, distinguishing NP from other complexity classes where such quick verification may not be possible. Certificates allow us to formally define and understand the class NP as problems for which solutions can be checked efficiently, even if finding the solution is potentially hard .

Polynomial-time verification in the context of decision problems in NP has significant implications for our understanding of computational complexity. It implies that while it might be challenging to discover a solution to a decision problem initially, checking the validity of a given solution can be done efficiently. This characteristic of NP problems highlights a critical boundary in the field of computational theory, raising the fundamental question of whether every verifiable problem is also solvable in polynomial time (i.e., P = NP). The assurance of efficient verifiability allows researchers to focus on solution methods that might not need to solve a problem outright but can verify potential solutions effectively .

Polynomial-time reducibility is a key concept in identifying NP-complete problems because it is used to demonstrate that every problem in NP can be efficiently transformed (or reduced) to the problem in question. If a problem B is NP-complete, then for every problem A in NP, there exists a polynomial-time reduction from A to B. This means if B can be solved in polynomial time, then all problems in NP can also be solved in polynomial time. This characteristic helps in proving the equivalence of computational hardness among various problems in NP .

The Hamiltonian cycle problem is often used in reductions to prove other problems are NP-complete due to its established status as an NP-complete problem. It provides an ideal candidate for demonstrating the hardness of a new problem. When proving another problem is NP-hard, showing that the Hamiltonian cycle problem can be reduced to it helps establish this new problem's intractability. This method leverages the transitive property of polynomial-time reductions, allowing researchers to build on known results rather than attempting an entirely new, direct proof for each problem. This approach exploits the interconnectedness of known NP-complete problems .

The assumption that P = NP cannot be made merely because problems in NP are verifiable in polynomial time. Verification in polynomial time means that given a solution, one can check its correctness quickly, but this does not imply we can find the solution efficiently. Solving a problem (finding a solution without assistance) might still require non-polynomial time. The distinction between verification and finding solutions is central to the complexity class separation challenge. While NP problems are verifiable, whether all of them can be efficiently solved (i.e., P = NP) remains unknown and is one of the biggest open questions in computer science .

You might also like