0% found this document useful (0 votes)
141 views

Daa Unit v Notes

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)
141 views

Daa Unit v Notes

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
You are on page 1/ 7

Unit- V

NP-Hard and NP-Complete Problems: Basic concepts, Nondeterministic algorithms, the


classes NP - Hard and NPComplete, Cook’s theorem, NP-Hard Graph Problems-Clique
Decision Problem (CDP),Node cover decision problem

P, NP, NP hard and NP complete | Complexity Classes

In computer science, there exist some problems whose solutions are not yet found, the problems
are divided into classes known as Complexity Classes. In complexity theory, a Complexity Class
is a set of problems with related complexity. These classes help scientists to group problems
based on how much time and space they require to solve problems and verify the solutions. It is
the branch of the theory of computation that deals with the resources required to solve a
problem.
The common resources are time and space, meaning how much time the algorithm takes to solve
a problem and the corresponding memory usage.
 The time complexity of an algorithm is used to describe the number of steps required to
solve a problem, but it can also be used to describe how long it takes to verify the answer.
 The space complexity of an algorithm describes how much memory is required for the
algorithm to operate.
Complexity classes are useful in organizing similar types of problems.
Types of Complexity Classes
This article discusses the following complexity classes:
1. P Class
2. NP Class
3. NP-hard
4. NP-complete
P Class
The P in the P class stands for Polynomial Time. It is the collection of decision
problems(problems with a “yes” or “no” answer) that can be solved by a deterministic machine
in polynomial time.
Features:
 The solution to P problems is easy to find.
 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.
This class contains many problems:
1. Calculating the greatest common divisor.
2. Finding a maximum matching.
3. Merge Sort
NP Class
The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection of
decision problems that can be solved by a non-deterministic machine in polynomial time.
Features:
 The solutions of the NP class are hard to find since they are being solved by a non-
deterministic machine but the solutions are easy to verify.
 Problems of NP can be verified by a Turing machine in polynomial time.
Example:
Let us consider an example to better understand the NP class. Suppose there is a company
having a total of 1000 employees having unique employee IDs. Assume that there are 200 rooms
available for them. A selection of 200 employees must be paired together, but the CEO of the
company has the data of some employees who can’t work in the same room due to personal
reasons.
This is an example of an NP problem. Since it is easy to check if the given choice
of 200 employees proposed by a coworker is satisfactory or not i.e. no pair taken from the
coworker list appears on the list given by the CEO. But generating such a list from scratch seems
to be so hard as to be completely impractical.
It indicates that if someone can provide us with the solution to the problem, we can find the
correct and incorrect pair in polynomial time. Thus for the NP class problem, the answer is
possible, which can be calculated in polynomial time.
This class contains many problems that one would like to be able to solve effectively:
1. Boolean Satisfiability Problem (SAT).
2. Hamiltonian Path Problem.
3. Graph coloring.
NP-hard class
An NP-hard problem is at least as hard as the hardest problem in NP and it is a class of problems
such that every problem in NP reduces to NP-hard.
Features:
 All NP-hard problems are not in NP.
 It takes a long time to check them. This means if a solution for an NP-hard problem is
given then it takes a long time to check whether it is right or not.
 A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-time
reduction from L to A.
Some of the examples of problems in Np-hard are:
1. Halting problem.
2. Qualified Boolean formulas.
3. No Hamiltonian cycle.
NP-complete class
A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the hard
problems in NP.
Features:
 NP-complete problems are special as any problem in NP class can be transformed or
reduced into NP-complete problems in polynomial time.
 If one could solve an NP-complete problem in polynomial time, then one could also solve
any NP problem in polynomial time.
Some example problems include:
 Hamiltonian Cycle.
 Satisfiability Problem
 Vertex cover.

Complexity Class Characteristic feature

P Easily solvable in polynomial time.

NP Yes, answers can be checked in polynomial time.

NP-hard All NP-hard problems are not in NP and it takes a long time to check them.

NP-complete A problem that is NP and NP-hard is NP-complete.

NON-DETERMINISTIC ALGORITHMS

In a deterministic algorithm, for a given particular input, the computer will always produce the
same output going through the same states but in the case of the 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(): The solution is successful and the current thread terminates.
Example :

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 :


1.j= choice(a, n)
2.if(A[j]==x) then
{
write(j);
success();
}
3.write(0); failure();
We can classify the problem in one of the following categories:
1. The problem which cannot be even defined in a proper way.
2. The problem which can be defined but cannot be solved.
3.The problem which can be solved theoretically, but computationally they are not feasible. The
algorithm takes very long time to solve such problems, and the time is practically not acceptable.
For example, cracking the password of 256 characters by brute force method may take years.
Definition
Problem is called intractable or infeasible if it takes too long time to be solved. A solution of
such problems has no practical application.
4.Problems which can be solved theoretically and practically in a reasonable amount of time. For
such problems, there exists a deterministic Turing machine that can solve the problem in O (p(n))
time, where p(n) is polynomial in n, and n is a problem size.
Definition
If the problem is solvable in polynomial time, it is called tractable. Such problems are denoted by
P problems.
5. The problem which is not known whether it is in P or not in P. Such problems falls somewhere
in between class 3 and 4.
Definition
 The problem is said to be decision problem if they produce output “Yes” or “No” for
given input. An algorithm which solves the decision problem is called decision algorithm.
 An optimization problem aims for the best solution from the set of all feasible solutions.
An algorithm which solves optimization problem is called optimization algorithms.
 Optimization algorithm seeks to find best profit or least cost solution. Decision problems
are simpler than optimization problem.
Nondeterministic Knapsack algorithm
Algorithm DKP(p, w, n, m, r, x)
{ W:=0; P:=0;
for i:=1 to n do
{
x[i]:=choice(0, 1);
W:=W + x[i]*w[i];
P:=P + x[i]*p[i]; }
if( (W>m) or (P<r) then failure();
else
success();
}

You might also like