0% found this document useful (0 votes)
54 views5 pages

NP-Hard vs NP-Complete Explained

The document discusses NP-hard and NP-complete problems and classifications of problems into P, NP, NP-hard and NP-complete. It defines these complexity classes and explains concepts like polynomial time, non-deterministic algorithms, reduction and Cook's theorem for proving NP-completeness.

Uploaded by

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

NP-Hard vs NP-Complete Explained

The document discusses NP-hard and NP-complete problems and classifications of problems into P, NP, NP-hard and NP-complete. It defines these complexity classes and explains concepts like polynomial time, non-deterministic algorithms, reduction and Cook's theorem for proving NP-completeness.

Uploaded by

vvvcxzzz3754
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NP –Hard and NP-Complete Problems

Basic Concepts

P, NP, NP-Hard and NP-Complete are classes that any problem would fall under or would
be classified as.

The computing times of algorithms fall into two groups.

Group1– consists of problems whose solutions are bounded by the polynomial of small
degree. Example – Binary search o(log n) , sorting o(n log n), matrix multiplication 0(n
2.81).

Group2 – contains problems whose best known algorithms are non polynomial. • Example
–Traveling salesperson problem 0(n22 n ), knapsack problem 0(2 n/2 ) etc.

P- Polynomial time solving . Problems which can be solved in polynomial time, which take
time like O(n), O(n2), O(n3).

It uses deterministic algorithm.

Eg: finding maximum element in an array or to check whether a string is palindrome or not.
so there are many problems which can be solved in polynomial time.

These problems are called tractable, while others are called intractable or
superpolynomial.

NP- Non deterministic Polynomial time solving. Problem which can't be solved in
polynomial time like TSP( travelling salesman problem) or An easy example of this is
subset sum: given a set of numbers, does there exist a subset whose sum is zero?.

but NP problems are checkable(verified) in polynomial time means that given a solution
of a problem , we can check that whether the solution is correct or not in polynomial time.

It uses the non deterministic algorithms

There are two classes of non polynomial time problems 1) NP- hard 2) NP-complete
P versus NP

Every decision problem that is solvable by a deterministic polynomial time algorithm is


also solvable by a polynomial time non-deterministic algorithm.

All problems in P can be solved with polynomial time algorithms, whereas all problems
in NP - P are intractable.

It is not known whether P = NP. However, many problems are known in NP with the
property that if they belong to P, then it can be proved that P = NP.

If P ≠ NP, there are problems in NP that are neither in P nor in NP-Complete.

The problem belongs to class P if it’s easy to find a solution for the problem. The problem
belongs to NP, if it’s easy to check a solution that may have been very tedious to find.

To define NP – hard and NP-Complete classes of problems. We need to know reducibility.


Reduction: Let L1 and L2 be problems. Problem L1 reduces to L2 if and only if there is a
way to solve L1 in a deterministic polynomial time using deterministic algorithm that
solves L2 in polynomial time.

Non-deterministic Algorithms

Deterministic algorithm, for a given particular input, the computer will always produce
the same output going through the same states. Can solve the problem in polynomial
time. Can determine the next step of execution.

Non-deterministic algorithm, for the same input, the compiler may produce different
output in different runs. In fact non-deterministic algorithms can’t solve the problem in
polynomial time and can’t determine what is the next step. The non-deterministic
algorithms can show different behaviors for the same input on different execution and
there is a degree of randomness to it.

To implement a non-deterministic algorithm, we have a couple of languages like Prolog


but these don’t have standard programming language operators and these operators are
not a part of any standard programming languages.

Some of the terms related to the non-deterministic algorithm are defined below:
choice(X) : chooses any value randomly from the set X.
failure() : denotes the unsuccessful solution.
success() : Solution is successful and current thread terminates.

Problem Statement : Search an element x on A[1:n] where n>=1, on successful search


return j if a[j] is equals to x otherwise return 0.
Non-deterministic Algorithm for this problem :
j= choice(a, n)

if(A[j]==x) then

write(j);
success();

write(0);

failure();

In Computer Science, many problems are solved where the objective is to maximize or
minimize some values, whereas in other problems we try to find whether there is a
solution or not. Hence, the problems can be categorized as follows −

Optimization Problem

Optimization problems are those for which the objective is to maximize or minimize some
values. For example,

 Finding the minimum number of colors needed to color a given graph.

 Finding the shortest path between two vertices in a graph.

Decision Problem

There are many problems for which the answer is a Yes or a No. These types of problems
are known as decision problems. For example,

 Whether a given graph can be colored by only 4-colors.

 Finding Hamiltonian cycle in a graph is not a decision problem, whereas checking a


graph is Hamiltonian or not is a decision problem.

NP-Hard and NP-Complete Classes

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

L ϵ NP and

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.

Cook’s Theorem

Cooks Theorem implies that any NP problem is at most polynomially harder than SAT. This
means that if we find a way of solving SAT in polynomial time, we will then be in a position
to solve any NP problem in polynomial time. This would have huge practical repercussions,
since many frequently encountered problems which are so far believed to be intractable
are NP. This special property of SAT is called NP-completeness. A decision problem is NP-
complete if it has the property that any NP problem can be converted into it in polynomial
time. SAT was the first NP-complete problem to be recognized as such (the theory of NP-
completeness having come into existence with the proof of Cooks Theorem), but it is by no
means the only one. There are now literally thousands of problems, cropping up in many
different areas of computing, which have been proved to be NP-complete.

In order to prove that an NP problem is NP-complete, all that is needed is to show that SAT
can be converted into it in polynomial time. The reason for this is that the sequential
composition of two polynomial-time algorithms is itself a polynomial-time algorithm, since
the sum of two polynomials is itself a polynomial.

Suppose SAT can be converted to problem D in polynomial time. Now take any NP problem
D0. We know we can convert it into SAT in polynomial time, and we know we can convert
SAT into D in polynomial time. The result of these two conversions is a polynomial-time
conversion of D0 into D. since D0 was an arbitrary NP problem, it follows that D is NP-
complete

Common questions

Powered by AI

The Traveling Salesman Problem (TSP) is an NP-hard problem because it exemplifies the class's complex nature, where the best-known algorithms require non-polynomial time, O(n2^n), for a solution . Its NP-hard status implies that solving it efficiently would lead to a breakthrough in solving all NP problems efficiently, reflecting the general difficulty in devising a polynomial-time solution . This problem’s complexity indicates it's widely applicable yet computationally challenging, and no polynomial time solution has been found .

Deterministic algorithms produce the same output for the same input every time, enabling solutions in polynomial time and characterizing the P class . In contrast, non-deterministic algorithms can exhibit different behaviors for the same input, involving a degree of randomness, making them suitable for verifying solutions rather than directly solving them in polynomial time. This non-deterministic nature defines the NP class where solutions can be verified quickly, even if they cannot be directly computed quickly .

Problems in P can be solved in polynomial time using deterministic algorithms, which means they take time like O(n), O(n^2), O(n^3). NP problems cannot generally be solved in polynomial time but can be verified in polynomial time given a solution . NP-hard problems are as hard as the hardest problems in NP, implying that if an NP-hard problem can be solved in polynomial time, then all problems in NP can be solved in polynomial time . NP-complete problems are those that are both in NP and NP-hard, meaning they are the hardest problems within NP . If any NP-complete problem is solvable in polynomial time, every NP-complete problem would be solvable in polynomial time, leading to the conclusion P = NP, which is still a major open question in computer science .

Optimization problems are generally more complex than decision problems because they involve finding the best solution out of many possible solutions, which often requires searching a large solution space . Decision problems, in contrast, typically ask whether a solution exists within certain constraints, often answerable by a simple yes or no, and are the focus of the P and NP classes . While some decision problems are NP-complete due to complexity, optimization problems often involve additional layers of computational problems, making them potentially harder and associated with NP-hard classification .

Proving P = NP would imply that all problems currently classified as NP-Complete, which are believed to be intractable, could be solved in polynomial time . This would revolutionize fields reliant on solving complex computational problems, such as cryptography, optimization, and artificial intelligence, by significantly reducing the computational resources needed . Additionally, it would solve many open questions in theoretical computer science and impact practical applications, leading to more efficient algorithms across disciplines .

The NP-hard classification necessitates the development of approximate, heuristic, or probabilistic algorithms for many real-world problems, as exact polynomial-time solutions are likely impossible . This impacts algorithm design by focusing on near-optimal solutions within reasonable computational limits rather than pursuing exact answers, which would be computationally infeasible for large instances . As such, the strategy often involves balancing approximation accuracy and computational efficiency .

Cook's Theorem establishes SAT as NP-complete by showing that any problem in NP can be reduced to SAT in polynomial time, ensuring SAT is as hard as any problem in NP . It was the first such problem to be identified, underpinning the theory of NP-completeness and leading to the classification of numerous other problems as NP-complete via polynomial time reducibility to SAT . This foundational application allows researchers to demonstrate NP-completeness for new problems, thereby illustrating the widespread applicability and significance of the theorem in computational complexity theory .

The ability to verify solutions in polynomial time is a defining characteristic of NP problems, distinguishing them from problems that don't belong to NP. For NP problems, once a solution is at hand, it can be checked efficiently, showing that while finding the solutions might be difficult (possibly requiring non-polynomial time), checking them is feasible . Problems outside NP may not have verifiable solutions in polynomial time, complicating their classification and limiting their tractability .

Reducibility is used to classify a problem as NP-Complete by demonstrating that a known NP-Complete problem, such as SAT, can be converted into it in polynomial time . This conversion shows that the problem is at least as hard as the hardest problems in NP. If a problem can be shown through reduction to solve SAT in polynomial time, it inherits the NP-Complete classification . The polynomial-time composition of two problems via reduction ensures the resulting problem is NP-Complete if the original problem was NP-Complete .

If an NP-hard problem can be reduced to a known NP-complete problem like SAT, it allows for leveraging existing methodologies and techniques developed for SAT to potentially address the NP-hard problem, bringing it into a framework where more is understood about its complexity . Such a reduction implies that if SAT could be solved in polynomial time, the NP-hard problem could be tackled similarly, thus easing its computational challenges . This underscores the importance of SAT as a benchmark problem in computational complexity .

You might also like