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

Papers

https://images.app.goo.gl/dX RjddvZ5DsJPdQh9https://images.app.goo.gl/dXRjddvZ5DsJPdQh9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Papers

https://images.app.goo.gl/dX RjddvZ5DsJPdQh9https://images.app.goo.gl/dXRjddvZ5DsJPdQh9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Unit-5

P and NP problems: Basic concepts, Class P, Fractional Knapsack problem in P, Class


NP, Fractional Knapsack problem in NP NP-Hard and NP-Complete problems: Basic
concepts, non-deterministic algorithms, NP - Hard and NP-Complete classes, Cook‘s
theorem.

P and NP problems: Basic concepts

NP Nondeterministic Polynomial time


The problems has best algorithms for their solutions have “Computing
times”, that cluster into two groups
Group 1 Group 2

> Problems with solution time > Problems with solution


bound by a polynomial of a times not bound by
small degree. polynomial (simply non
polynomial )
> It also called “Tractable
Algorithms” > These are hard or
intractable problems
> Most Searching & Sorting
algorithms are polynomial time >
algorithms None of the problems in this
group has been solved by
any polynomial
> Ex: time algorithm
Ordered Search (O (log n)),
Polynomial evaluation O(n) > Ex:
Traveling Sales Person O(n2 2n)
Sorting O(n.log n)
Knapsack O(2n/2)

No one has been able to develop a polynomial time algorithm for any
problem in the 2nd group (i.e., group 2)
So, it is compulsory and finding algorithms whose computing times are
greater than polynomial very quickly because such vast amounts of time to
execute that even moderate size problems cannot be solved.

Theory of NP-Completeness:
Show that may of the problems with no polynomial time algorithms are computational
time algorithms are computationally related.

There are two classes of non-polynomial time problems

1. NP-Hard
2. NP-Complete

NP Complete Problem: A problem that is NP-Complete can solved in polynomial time


if and only if (iff) all other NP-Complete problems can also be solved in polynomial
time.

NP-Hard: Problem can be solved in polynomial time then all NP-Complete problems can be
solved in polynomial time.

All NP-Complete problems are NP-Hard but some NP-Hard problems are not know to be NP-
Complete.

Class P

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:
1. The solution to P problems is easy to find.
2. 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 natural problems like:
1. Calculating the greatest common divisor.
2. Finding a maximum matching.
3. Decision versions of linear programming.

Fractional Knapsack problem in P

Class of NP

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:
1. 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.
2. 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
some 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.

Fractional Knapsack problem in NP

The Classes NP-Hard & NP-Complete:

For measuring the complexity of an algorithm, we use the input length as the parameter.
For example, An algorithm A is of polynomial complexity p() such that the computing
time of A is O(p(n)) for every input of size n.
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.

P is the set of all decision problems solvable by deterministic algorithms in


-)

polynomial time.
NP is the set of all decision problems solvable by nondeterministic algorithms in
-)

polynomial time.

Since deterministic algorithms are just a special case of nondeterministic, by this we


concluded that P NP⊆
Commonly believed relationship between P & NP
The most famous unsolvable problems in Computer Science is Whether P=NP or
P≠NP In considering this problem, s.cook formulated the following question.

If there any single problem in NP, such that if we showed it to be in ‘P’ then that would
imply that P=NP.

Cook answered this question with

Theorem: Satisfiability is in P if and only if (iff) P=NP

-)Notation of Reducibility
Let L1 and L2 be problems, Problem L1 reduces to L2 (written L1 α L2) iff there is a way
to solve L1 by a deterministic polynomial time algorithm using a deterministic algorithm
that solves L2 in polynomial time
This implies that, if we have a polynomial time algorithm for L2, Then we can solve
L1 in polynomial time.

Here α-) is a transitive relation i.e., L1 α L2 and L2 α L3 then L1 α L3

A problem L is NP-Hard if and only if (iff) satisfiability reduces to L ie., Statisfiability α L

A problem L is NP-Complete if and only if (iff) L is NP-Hard and L Є NP

Commonly believed relationship among P, NP, NP-Complete and NP-Hard

Most natural problems in NP are either in P or NP-complete.


Examples of NP-complete problems:
> Packing problems: SET-PACKING, INDEPENDENT-SET.
> Covering problems: SET-COVER, VERTEX-COVER.
> Sequencing problems: HAMILTONIAN-CYCLE, TSP.
> Partitioning problems: 3-COLOR, CLIQUE.
> Constraint satisfaction problems: SAT, 3-SAT.
> Numerical problems: SUBSET-SUM, PARTITION, KNAPSACK.

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 nondeterministic
algorithms.

The machine executing such operations is allowed to choose any one of these
outcomes subject to a termination condition to be defined later.

To specify nondeterministic algorithms, there are 3 new

functions. Choice(S) arbitrarily chooses one of the elements


-)

of sets S Failure () Signals an Unsuccessful completion


-)

Success () Signals a successful completion.


-)

Example for Non Deterministic algorithms:


Algorithm Search(x){ Whenever there is a set of choices
//Problem is to search an element x that leads to a successful
completion then one such set of
//output J, such that A[J]=x; or J=0 if x is not in A
choices is always made and the
J:=Choice(1,n); algorithm terminates.
if( A[J]:=x) then {
A Nondeterministic algorithm
Write(J); terminates unsuccessfully if and
Success(); only if (iff) there exists no set of
} choices leading to a successful
signal.
else{
write(0);
failure();

}
Nondeterministic Knapsack algorithm

Algorithm DKP(p, w, n, m, r, x){ p given Profits


-)

W:=0; w given Weights


-)

P:=0; n Number of elements (number of


-)

for i:=1 to n do{ p or w)


x[i]:=choice(0, 1); m Weight of bag limit
-)

W:=W+x[i]*w[i]; P Final Profit


-)

P:=P+x[i]*p[i]; W Final weight


-)

}
if( (W>m) or (P<r) ) then Failure();
else Success();
}

Success () Signals a successful completion.


-)

Cook‘s theorem

 The Cook-Levin theorem, also known as Cook’s theorem, states that the Boolean
satisfiability problem is NP-complete. That is, any problem in NP can be
reduced in polynomial time by a deterministic Turing machine to the problem
whether a Boolean formula is satisfiable.
 The theorem is named after Stephen Cook and Leonid Levin.
 An important consequence of this theorem is that if there exists a deterministic
polynomial time algorithm for solving Boolean satisfiability, then every NP
problem can be solved by a deterministic polynomial time algorithm.

The work shows that Cook’s theorem is the origin of the loss of non-determinism in
terms of the equivalence of the two definitions of NP, the one defining NP as the
class of problems solvable by a nondeterministic Turing machine in polynomial time,
and the other defining N P as the class of problems verifiable by a deterministic
Turing machine in polynomial time. Therefore, we argue that fundamental difficulties
in understanding P versus NP lie firstly at cognitionlevel, then logic level.
Cook’s Theorem: States that satisfiability is in P if and only if P=NP If
P=NP then satisfiability is in P
If satisfiability is in P, then P=NP To
do this
> A-) Any polynomial time nondeterministic decision algorithm.
I-)Input of that algorithm
Then formula Q(A, I), Such that Q is satisfiable iff ‘A’ has a successful
termination with Input I.

> If the length of ‘I’ is ‘n’ and the time complexity of A is p(n) for some
polynomial
p() then length of Q is O(p3(n) log n)=O(p4(n))

The time needed to construct Q is also O(p3(n) log n).

> A deterministic algorithm ‘Z’ to determine the outcome of ‘A’ on any


input ‘I’ Algorithm Z computes ‘Q’ and then uses a deterministic
algorithm for the satisfiability problem to determine whether ‘Q’ is
satisfiable.

>If O(q(m)) is the time needed to determine whether a formula of


length ‘m’ is satisfiable then the complexity of ‘Z’ is O(p3(n) log n +
q(p3(n)log n)).
> If satisfiability is ‘p’, then ‘q(m)’ is a polynomial function of
‘m’ and the complexity of ‘Z’ becomes ‘O(r(n))’ for some polynomial ‘r()’.
> Hence, if satisfiability is in p, then for every nondeterministic algorithm
A in NP, we can obtain a deterministic Z in p.
By this we shows that satisfiability is in p then P=NP

You might also like