0% found this document useful (0 votes)
216 views13 pages

NP-Hard and NP-Complete

The document discusses polynomial time algorithms and complexity classes P, NP, NP-hard, and NP-complete. It defines each class and provides examples. Polynomial time algorithms run in O(nk) time, where n is the input size and k is a constant. P contains problems solvable in polynomial time, while NP contains problems verifiable in polynomial time. NP-hard problems are at least as hard as NP, and NP-complete problems are both NP-hard and in NP. The circuit satisfiability problem is used as an example of an NP-complete problem.

Uploaded by

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

NP-Hard and NP-Complete

The document discusses polynomial time algorithms and complexity classes P, NP, NP-hard, and NP-complete. It defines each class and provides examples. Polynomial time algorithms run in O(nk) time, where n is the input size and k is a constant. P contains problems solvable in polynomial time, while NP contains problems verifiable in polynomial time. NP-hard problems are at least as hard as NP, and NP-complete problems are both NP-hard and in NP. The circuit satisfiability problem is used as an example of an NP-complete problem.

Uploaded by

mathu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

NP-Hard and NP-

Complete
Polynomial-time Algorithms

• An algorithm is said to be solvable in polynomial time if the number of


steps required to complete the algorithm for a given input is O(nk) for
some non-negative integer k, where n is the complexity(size) of the input.

• In other words,

• An algorithm is said to be of polynomial time if its running time is 


upper bounded by a polynomial expression in the size of the input for the
algorithm, i.e., T(n) = O(nk) for some positive constant k.
• Efficient algorithms that use at most polynomial amount of computational
resources [Polynomial: (x7 + 2y4 - 5) * 3x]
• On inputs of size n, their worst-case running time is O(n k) for some constant k
• Most familiar mathematical operations such as
• addition,
• subtraction,
• multiplication, and
• division, as well as
• computing square roots,
• powers, and
• logarithms,
can be performed in polynomial time. 
The concept of polynomial time leads to several
complexity classes in computational complexity
theory.
The complexity class of decision problems that can be solved on
P
a deterministic Turing machine in polynomial time

NP The complexity class of decision problems that can be solved on


a non-deterministic Turing machine in polynomial time

Decision problem - problems where the answer is either YES


or NO.
 
P problem
• P is the class of decision problems that can be solved efficiently,
• ie. decision problems which have polynomial time algorithms.
P problem - efficiently solvable
• An example would be basic multiplication of two numbers.
• Multiplying two n digit numbers will only require n² single-digit
multiplications, which is a polynomial in n.
• Polynomial Time • Exponential Time Algorithms
Algorithms: • 0/1 knapsack -- 2n
• Linear Search -- n • Travelling Salesman Pblm -- 2n
• Binary Search – log n • Sum of Subsets -- 2n
• Insertion sort – n2 • Graph coloring --2n
• Merge Sort – nlogn • Hamiltonian cycle -- 2n
• There is no polynomial time efficient solutions for all
Matrix Multiplication – n3
these problems.
1) If one problem is solved, then all the other
problems could also be solved.
2) If there is no deterministic soln, we can try for non-
deterministic solution
NP problem
• NP is a "class of computational problems for which solutions can be computed by a
non-deterministic Turing machine in polynomial time.

• Equivalently, NP is the set of decision problems for which the problem instances,


where the answer is "yes", have proofs verifiable in polynomial time by a
deterministic Turing machine.

• In other words,
• “A problem is in NP” if, given a potential solution, you can verify that it is correct or incorrect in
polynomial time.
• For instance if the problem is sorting lists, if you can verify that one list is the sorted version of
another list in polynomial time, then sorting is in NP.
• NP – efficiently verifiable
• An example of a problem which we do not know how to solve
efficiently but we can efficiently verify proofs:
• However if  two sets A and B is given , we can easily check if the sums
are equal and if A and B is a partition of S.
• Note that we can compute sums efficiently.
• Eg. S={1,2,4,5} A ={2,4} and B={1,5} // Proof for YES
• A={2,5} and B={1,4} // Proof is invalid but doesn’t mean the answer
is NO
• P =efficiently solvable and NP=efficiently verifiable.

• So P=NP iff the problems that can be efficiently verified are the same
as the problems that can be efficiently solved.
NP – Hard Problem
• Minimum requirement of any efficient algorithm is that it runs in
polynomial time: O(nk ) for some constant k.
• not all problems can be solved this quickly
• NP-hard are problems, which most people believe that it cannot be
solved in polynomial time
• "at least as hard as the hardest problems in NP".
• A simple example of an NP-hard problem is the subset sum problem
• Problems that are NP-hard do not have to be elements of NP;
• indeed, they may not even be decidable.
NP-Complete

• A problem is NP-complete if it is both NP-hard and an element of NP

• Class of decision problems which contains the hardest problems in NP. (most difficult
NP problems)

• Each NP-complete problem has to be in NP.

• NP-Complete means the problem is at least as hard as any problem in NP

• If we can solve an NP-complete problem efficiently, we can solve all NP problems


efficiently.
Circuit Satisfiability Problem
• Eg. Circuit satisfiability : a problem that we don’t know how to solve in
polynomial time.
• Input: a boolean circuit - a collection of and, or, and not gates
• input to the circuit is a set of m boolean (true/false) values x1, . , xm.
• output is a single boolean value.
Requirement of Circuit satisfiability
problem
• Given a circuit, whether there is an input that makes the circuit
output True, or conversely, whether the circuit always outputs False.
• Nobody knows how to solve this problem faster than just trying all 2m
possible inputs to the circuit, but this requires exponential time.
• On the other hand, nobody has ever proved that this is the best we
can do;
• maybe there’s a clever algorithm that nobody has discovered yet!

You might also like