Вы находитесь на странице: 1из 16

Design and Analysis of Algorithms (18CSE107)

NP Completeness
Complexity Classes

Veningston. K
Computer Science and Engineering
Unit V - Outline

• Network flow problem


– Ford Fulkerson Algorithm for Maximum Flow Problem

• NP–Hard and NP–Complete Problems

– Terminologies
– Examples
– Complexity Class - P, NP, NP-Complete, NP-Hard
– Is P=NP?
– Reducibility
•Design and Analysis of Algorithms
•2
(18CSE107)
Introduction to NP Completeness

• Is every problem easy to solve? (or) Some problems


are difficult to solve?
• Scenario:
– You’re a Software Engineer
– Your manager asked you to solve a problem
– You supposed to solve it and give a demo
– Panel has given you the input and you have to run your
implementation
– What if your program does not stop?

•Design and Analysis of Algorithms


•3
(18CSE107)
Scenario (cont.)

• What are you supposed to do?


– Imagine if you were to say “I did not come up with a
solution”
– It is not right to say “You cannot solve it”
• You should say that “I cannot solve it and no one else
really solved it till this point”
– Nobody knows, even in future, it could be solved or not.
• If you can say such a statement, then your manager
will believe you and you may not loose your job.
You’re not able to solve it in Polynomial time
Why polynomial time?

• Polynomial time algorithm will run faster.


• If we are not able to find the solution in terms of
O(nk)
– You shouldn’t say your manager that “I cannot solve it”
– Rather say this statement “Any problem belonging to this
model has never been solved in Polynomial time”
– “In future, I cannot say if someone could solve it”
• It is very easy to prove that you can solve a problem.
– How? Solve it and show the implementation
Why polynomial time?

• It is very difficult to prove that “you cannot solve a


problem and no one else could solve this problem”
– We cannot bring everyone to your job and ask them to
solve and show your Manager that “they all failed to
solve”

• Therefore, in order to make these things easy, we


study “NP Completeness”
Types of algorithms
Problems
Algorithm exists

Decidable Problems
Undecidable Problems

No algorithm
exists. Example:
Tractable Intractable
Halting Problem of
If there exist If the Turing Machine
at least one problem is
polynomial not tractable, ✘
bound then it is
algorithm intractable
O(nk) O(cn),
O(nlogn)
Problem Classification

• 2 types:
– Decidable problem
– Undecidable problem
• If there exist an algorithm to solve a problem,
then it is called decidable problem
• If there exist no algorithm, then it is called
Undecidable problem
What is algorithm?
• It is a procedure which supposed to halt after some
time.
• If we do not have any algorithm which halts, then
there is no algorithm
Polynomial Time Complexity Exponential Time Complexity
Linear Search - O(n) 0/1 Knapsack - O(2n)
Binary Search -O(log n) TSP - O(n22n)
Merge sort - O(n log n) Sum of subsets - O(2n)
Quick sort - O(n log n) Hamiltonian cycle - O(n22n)
Insertion sort - O(n2) Satisfiability - O(2n)
Matrix multiplication - O(n3) Clique in graph - O(2n)
Types of problems
• 2 Types
– Tractable
– Intractable
• Tractable
– Fast algorithm
– Easy problems are called tractable problems
– There exists at least one polynomial bound algorithm O(nk)
• Intractable
– Problems which are not tractable, then it is intractable
– Exponential time algorithm  If we do not find any
algorithm which runs in polynomial time O(cn)
Tractable vs. Intractable

• All programs we see in computer are tractable


– Runs fast

– Software industries are always interested in tractable


solutions/tractable problems

• If the problem is intractable, no one would really


implement them
– Runs slowly
How to handle intractable problems?

• Even though we are not able to solve it fast, we can


compromise.
• It may take lot of time to give exact answer
• Heuristics:
– Approximation algorithms, which will not solve the
problem completely. But, it will give a close answer.
– We will definitely stop trying to solve the problem exactly
– It will give some solution, which is not exact solution. But,
which will run faster.
Types of Problem
Undecidable problems Set of all problems
(Halting problem of TM)
Set of all
Decidable
problems
(These problems
cannot be solved
in polynomial
time) -
NP Problems

Problems solvable
in polynomial time.
NP Problems

• We do not know anything about these problems.


– whether we could solve them in polynomial time or not.
• Example:
– TSP  we do not have polynomial time algorithm
– In future,
• Someone might be able to find out the polynomial time solution (or)
• someone might prove that there is no polynomial time algorithm
exist
• NOTE: As of now, we do not know anything about
intractable problems.
NP Problems
Set of all problems
Undecidable problems
Set of all
Decidable
problems

Problems solvable
in polynomial time.
P Problems NP Problems
P vs. NP

• P
– If the problem is solvable in polynomial time, it is P
• NP
– If the problem is decidable and if we do not have any
polynomial time algorithm till now, then these problems
are NP
– We do not know anything about NP
• We do not whether they could be solved in polynomial time or
they cannot be solved in polynomial time
• Future will decide (No one knows)

Вам также может понравиться