P class
NP class
NP-Hard
NP-Complete
-By
Ziyauddin Shaik
CONCEPTS
 Problem
 Problem v/s Algorithm v/s Program
 Types of Problems
 Computational complexity
 P class v/s NP class Problems
 Polynomial time v/s Exponential time
 Deterministic v/s non-deterministic Algos
 Functions of non-deterministic Algorithms
 Non-deterministic searching Algorithm
 Non-deterministic sorting Algorithm
 NP - Hard and NP - Complete Problems
 Reduction & its properties
 Satisfiability problem and Algorithm
PROBLEM
“A computational problem specifies an input-output relationship.”
i.e. What does the input look like ?
What should the output be for each input ?
Example :
Input : A list of names of people
Output : The same list sorted alphabetically
Example:
Input : A picture in digital format
Output : A description of what the picture shows
Problem v/s Algorithm v/s Program
Aim - To convert centimeters to meters
PROBLEM ALGORITHM PROGRAM
we need to solve a An algorithm specifies A program is a computer executable
computational problem how to solve a problem description of an algorithm
Input : length in cm 1.Read cm #include<stdio.h>
Output : length in m 2.Calculate m=cm*0.01 #include<conio.h>
3.Print m void main()
{
float cm,m;
scanf(“%f”,&cm);
m=cm*0.01;
printf(“%f”,m);
getch();
}
Types of Problems
1. Tractable
2. Intractable
3. Decision
4. Optimization
1. Tractable Problems that can be solved in a
reasonable ( polynomial ) time
2. Intractable Problems that cannot be solved in a
reasonable time
3. Decision Problems that tries to answer a yes/no
question
4. Optimization Problems that tries to find an optimal
solution
Types of Problems
Computational complexity
“The amount of resources required to run an Algorithm”.
Depending on computational complexity of various problems,the problems can be
classified into 2 groups
computational complexity problems
P class NP class
NP complete NP hard
P class v/s NP class Problems
P class
The set of decision problems that
can be solved in polynomial time
using deterministic algorithms
are called P class problems
They can be solved and verified
in polynomial time
NP class
The set of decision problems that
can be solved in polynomial time
using non - deterministic algorithms
are called NP class problems
They can be verified in polynomial
time
NP
P
RULE :
Each space should be filled with
a digit of range (1-9) such that
It shouldn’t already present in
1 it’s row
2 it’s column
3 it’s block
Solving a Problem ( Sudoku )
It takes exponential time
RULE :
Each space should be filled with
a digit of range (1-9) such that
It shouldn’t already present in
1 it’s row
2 it’s column
3 it’s block
Verifying a Problem ( Sudoku )
It takes polynomial time
Polynomial time v/s Exponential time
Polynomial time
Linear search - n
Binary search - log n
Insertion sort - n2
Merge sort - n log n
Matrix multiplication - n3
Exponential time
0/1 knapsack - 2n
Travelling salesman - 2n
Graph colouring - 2n
Hamilton cycle - 2n
Sum of subsets - 2n
Time v/s input size (for polynomial & Exponential time Algorithms)
Deterministic v/s non-deterministic Algorithms
Deterministic
A Deterministic algorithm
produces only a single output
for the same input even on
different runs
1 0
0 0
Non-deterministic
A non - deterministic algorithm
can provide different outputs
for the same input on
different runs
q
q1
q2
q
q1
q2
Functions of non - deterministic algorithm
To specify such non - deterministic algorithms
we introduce three new functions
1. Choice(S) - arbitrarily chooses one of the elements of set S
2. Failure() - signals an unsuccessful completion
3. Success() - signals a successful completion
The assignment statement x=Choice(1,n) could result in x being
assigned any one of the integers in the range [1,n]
There is no rule specifying how this value is chosen
A non - deterministic searching algorithm
Searching for an element x in a given set of elements A[1:n], n>1. We are required
to determine an index j such that A[j]=x or j=0 if x is not in A.
Algorithm NSearch(A,n,key)
{
j=Choice(1,n);
if A[j]==key then
{
write( j);
Success( );
}
write ( 0);
Failure( );
}
Running Time : O(1)
NP - Hard and NP - Complete Problems
The NP class problems can be further categorized into
NP - hard and NP- complete problems
NP - Hard
A problem is NP - hard if all
other problems in NP can be
polynomially reduced to it
NP - Complete
A problem is NP - complete if it is
(a) in NP
(b) NP - hard
Relationship among P , NP , NP - hard , NP - complete problems
Problem
P
NP
NP - Complete
NP - Hard
Type
Tractable
Intractable
Decision
Optimization
Verifiable in
Polynomial time
YES
YES
YES
--
Solvable in
Polynomial time
YES
--
--
--
Complexity
Easy
Medium
Hard
Hardest
A B
Reduce
An expression that can
be constructed using
literals and operators
Either a
variable or it’s negation
whose value is either
TRUE or FALSE
A formula is said to
be satisfiable if
variables can be
assigned with values
such that the
formula turns out to
be TRUE
A formula is said to
be unsatisfiable if
variables cannot be
assigned with values
such that the
formula turns out to
be TRUE
THANK YOU

Webinar : P, NP, NP-Hard , NP - Complete problems

  • 1.
  • 2.
    CONCEPTS  Problem  Problemv/s Algorithm v/s Program  Types of Problems  Computational complexity  P class v/s NP class Problems  Polynomial time v/s Exponential time  Deterministic v/s non-deterministic Algos  Functions of non-deterministic Algorithms  Non-deterministic searching Algorithm  Non-deterministic sorting Algorithm  NP - Hard and NP - Complete Problems  Reduction & its properties  Satisfiability problem and Algorithm
  • 3.
    PROBLEM “A computational problemspecifies an input-output relationship.” i.e. What does the input look like ? What should the output be for each input ? Example : Input : A list of names of people Output : The same list sorted alphabetically Example: Input : A picture in digital format Output : A description of what the picture shows
  • 4.
    Problem v/s Algorithmv/s Program Aim - To convert centimeters to meters PROBLEM ALGORITHM PROGRAM we need to solve a An algorithm specifies A program is a computer executable computational problem how to solve a problem description of an algorithm Input : length in cm 1.Read cm #include<stdio.h> Output : length in m 2.Calculate m=cm*0.01 #include<conio.h> 3.Print m void main() { float cm,m; scanf(“%f”,&cm); m=cm*0.01; printf(“%f”,m); getch(); }
  • 5.
    Types of Problems 1.Tractable 2. Intractable 3. Decision 4. Optimization
  • 6.
    1. Tractable Problemsthat can be solved in a reasonable ( polynomial ) time 2. Intractable Problems that cannot be solved in a reasonable time 3. Decision Problems that tries to answer a yes/no question 4. Optimization Problems that tries to find an optimal solution Types of Problems
  • 7.
    Computational complexity “The amountof resources required to run an Algorithm”. Depending on computational complexity of various problems,the problems can be classified into 2 groups computational complexity problems P class NP class NP complete NP hard
  • 8.
    P class v/sNP class Problems P class The set of decision problems that can be solved in polynomial time using deterministic algorithms are called P class problems They can be solved and verified in polynomial time NP class The set of decision problems that can be solved in polynomial time using non - deterministic algorithms are called NP class problems They can be verified in polynomial time NP P
  • 9.
    RULE : Each spaceshould be filled with a digit of range (1-9) such that It shouldn’t already present in 1 it’s row 2 it’s column 3 it’s block Solving a Problem ( Sudoku ) It takes exponential time
  • 10.
    RULE : Each spaceshould be filled with a digit of range (1-9) such that It shouldn’t already present in 1 it’s row 2 it’s column 3 it’s block Verifying a Problem ( Sudoku ) It takes polynomial time
  • 11.
    Polynomial time v/sExponential time Polynomial time Linear search - n Binary search - log n Insertion sort - n2 Merge sort - n log n Matrix multiplication - n3 Exponential time 0/1 knapsack - 2n Travelling salesman - 2n Graph colouring - 2n Hamilton cycle - 2n Sum of subsets - 2n
  • 12.
    Time v/s inputsize (for polynomial & Exponential time Algorithms)
  • 13.
    Deterministic v/s non-deterministicAlgorithms Deterministic A Deterministic algorithm produces only a single output for the same input even on different runs 1 0 0 0 Non-deterministic A non - deterministic algorithm can provide different outputs for the same input on different runs q q1 q2 q q1 q2
  • 14.
    Functions of non- deterministic algorithm To specify such non - deterministic algorithms we introduce three new functions 1. Choice(S) - arbitrarily chooses one of the elements of set S 2. Failure() - signals an unsuccessful completion 3. Success() - signals a successful completion The assignment statement x=Choice(1,n) could result in x being assigned any one of the integers in the range [1,n] There is no rule specifying how this value is chosen
  • 15.
    A non -deterministic searching algorithm Searching for an element x in a given set of elements A[1:n], n>1. We are required to determine an index j such that A[j]=x or j=0 if x is not in A. Algorithm NSearch(A,n,key) { j=Choice(1,n); if A[j]==key then { write( j); Success( ); } write ( 0); Failure( ); } Running Time : O(1)
  • 17.
    NP - Hardand NP - Complete Problems The NP class problems can be further categorized into NP - hard and NP- complete problems NP - Hard A problem is NP - hard if all other problems in NP can be polynomially reduced to it NP - Complete A problem is NP - complete if it is (a) in NP (b) NP - hard
  • 18.
    Relationship among P, NP , NP - hard , NP - complete problems
  • 19.
    Problem P NP NP - Complete NP- Hard Type Tractable Intractable Decision Optimization Verifiable in Polynomial time YES YES YES -- Solvable in Polynomial time YES -- -- -- Complexity Easy Medium Hard Hardest
  • 20.
  • 22.
    An expression thatcan be constructed using literals and operators Either a variable or it’s negation whose value is either TRUE or FALSE A formula is said to be satisfiable if variables can be assigned with values such that the formula turns out to be TRUE A formula is said to be unsatisfiable if variables cannot be assigned with values such that the formula turns out to be TRUE
  • 25.