Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 12

P, NP, NP-COMPLETE AND NP-

HARD

PIYALI CHANDRA
Assistant Professor
UEMK
Polynomial and Exponential Functions


Polynomial functions: Any function that is O(nk), i.e. bounded from
above by nk for some constant k.
• Eg, O(1), O(log n), O(n), O(n log n), O(n2), O(n3)

Exponential functions: The remaining functions like O(2n), O(n!),
O(nn)

Polynomial time algorithm: An algorithm whose order of magnitude
time performance is bounded from above by a polynomial function of
n, where n is the size of its inputs.

Exponential time algorithm: An algorithm whose order of magnitude
time performance is not bounded from above by a polynomial
Tractable and Intractable Problems

Tractable Problem: A problem that is solvable by a polynomial-time algorithm.
• Examples: Searching an unordered list, searching an ordered list, sorting a list,
multiplication of integers, finding a minimum spanning tree in a graph.

Intractable Problem: A problem that cannot be solved by a polynomial-time algorithm.

Example:
• Towers of Hanoi: Worst case running time is at least 2n - 1
• List all permutations of n numbers

Others have polynomial amount of output, but still cannot be solved in polynomial time.
P, NP, NP-Complete and NP-Hard
Problems Examples:

P Algorithms: Shortest path
algorithms, linear and binary search
algorithms etc.

NP Algorithms: Integer Factorization,
Graph Isomorphism

NP-complete Algorithms: Traveling
salesman Search (TSP), Graph
coloring

NP-hard: Traveling salesman
Optimization (TSP-OPT)
Turing machines

Turing machines are a model of computation. It is believed that anything
that can be computed can be computed by a Turing Machine.

In a deterministic Turing machine, the set of rules impose at most one
action to be performed for any given situation.

In a nondeterministic Turing machine, it may have a set of rules that
prescribes more than one action for a given situation.

In deterministic algorithm, for a given particular input, the computer will
always produce the same output going through the same states.

In case of non-deterministic algorithm, for the same input, the compiler
may produce different output in different runs.

Non-deterministic algorithms can’t solve the problem in polynomial time
and can’t determine what is the next step. The non-deterministic
P and NP

P is set of problems that can be solved by a deterministic Turing machine
in Polynomial time.

NP is set of decision problems that can be solved by a Non-deterministic
Turing Machine in Polynomial time. P is subset of NP (any problem that
can be solved by deterministic machine in polynomial time can also be
solved by non-deterministic machine in polynomial time).

P versus NP problem is a major unsolved problem in computer science. It
asks whether every problem whose solution can be quickly verified can
also be solved quickly.

If P ≠ NP, which is widely believed, it would mean that there are problems
in NP that are harder to compute than to verify: they could not be solved
in polynomial time, but the answer could be verified in polynomial time.

In other words, is P=NP? Is efficient checking same as efficient generation?
NP-complete and NP-Hard

NP-complete problems are the hardest problems in NP set.

A decision problem L is NP-complete if:
1) L is in NP (Any given solution for NP-complete problems can be verified
quickly, but there is no efficient known solution).
2) Every problem in NP is reducible to L in polynomial time

A problem is NP-Hard if it follows property 2, doesn’t need to follow
property 1. Therefore, NP-Complete set is also a subset of NP-Hard set.

It does not restrict the class NP-hard to decision problems, and it also
includes search problems or optimization problems.

If P ≠ NP, then NP-hard problems could not be solved in polynomial time.

Some NP-hard optimization problems can be polynomial-time 
Reduction

We want to solve problem A

We know how to solve problem B

Convert input for A into input for B

Interpret output of B as output of A

A reduces to B

Can transfer efficient solution from B to A

But preprocessing and postprocessing must also be efficient

Typically both should be polynomial time

Reverse interpretation is also useful
Boolean Satisfiability

Satisfiable : If the Boolean variables can be assigned values such that
the formula turns out to be TRUE, then we say that the formula is
satisfiable.

Unsatisfiable : If it is not possible to assign such values, then we say
that the formula is unsatisfiable.

For example, the formula "a AND NOT b" is satisfiable because one
can find the values a = TRUE and b = FALSE, which make (a AND
NOT b) = TRUE. In contrast, "a AND NOT a" is unsatisfiable.

3SAT, or the Boolean satisfiability problem, is a problem that asks
what is the fastest algorithm to tell for a given formula in Boolean
algebra (with unknown number of variables) whether it is satisfiable,
that is, whether there is some combination of the (binary) values of
the variables that will give 1.
Cook-Levin Theorem


Boolean Satisfiability problem is NP-complete

Every problem in NP can be reduced to SAT

Theorem is named after Stephen Cook and Leonid Levin

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.
P NP (non-deterministic NP-Complete NP-Hard
polynomial)
P is a complexity class NP is a complexity class A problem p in NP is NP- A problem X is NP-hard, if
that represents the set of that represents the set of complete if every other there is an NP-complete
all decision problems that all decision problems for problem in NP can be problem Y, such that Y is
can be solved in which the instances where transformed (or reduced) reducible to X in
polynomial time. the answer is "yes" have into p in polynomial time. polynomial time.
proofs that can be verified
in polynomial time.
That is, given an instance This means that if This means that we can These are the problems
of the problem, the someone gives us an solve Y quickly if we know that are at least as hard
answer yes or no can be instance of the problem how to solve X quickly. as the NP-complete
Precisely, Y is reducible to X,
decided in polynomial and a certificate problems. Note that NP-
if there is a polynomial time
time. (sometimes called a algorithm f to transform hard problems do not
witness) to the answer instances y of Y to instances x have to be in NP, and they
being yes, we can check of X in polynomial time, with do not have to be decision
that it is correct in the property that the answer problems.
polynomial time. to y is yes, if and only if the It stands for non-
answer to f(y) is yes. deterministic polynomial
If a deterministic polynomial acceptable problems
time algorithm can be found
to solve one of them, every
NP problem is solvable in
polynomial time.
Conclusion


P problems are quick to solve

NP problems are quick to verify but slow to solve

NP-complete problems are also quick to verify, slow to solve and can
be reduced to any other NP-complete problem

NP-hard problems are slow to verify, slow to solve and can be
reduced to any other NP problem

You might also like