P-Class and NP-Class Problems
P-Class and NP-Class Problems
P-Class and NP-Class Problems
CSE3004
Dr. Paras Jain
Associate Professor - SCAI
VIT Bhopal University
Outline
• Introduction to algorithm
• Asymptotic notation
• Time and space complexity
• P,
• NP,
• NPN,
• NPC
What are the applications of
algorithm?
1. S1: Read A 1
S2: Read B 1 2. Main()
S3: Sum = A+B 1
S4: Print (sum) 1/4 Int a, b, sum; 1
3. Main() Scanf (a,b); 1
Int a=1; Sum = a + b; 1
While(1) infinite
Printf (sum) 1
A= a+1; inf
Complexity definitions
• Big-Oh
• Big-Theta
• Big - Omega
Big Oh (O)
• f(n)= O(g(n)) iff there exist positive constants c and n0 such that f(n) ≤ cg(n)
for all n ≥ n0
• Theta notation is used when function f can be bounded both from above
and below by the same function g
How bad is exponential complexity
• Fibonacci example – the recursive fib cannot even compute fib(50)
P, NP, NP Hard, NP
Complete
Traveling Salesperson Problem
• The class P consists of those problems that are solvable in polynomial time.
• More specifically, they are problems that can be solved in time O(nk) for
some constant k, where n is the size of the input to the problem.
{
answer = false;
break;
} Naïve primality testing is exponential!!
}
return answer;
}
Why obsess about primes?
• Fractional Knapsack
• MST
• Others?
• – Traveling Salesman
• – Graph Coloring
• – Satisfiability (SAT)
• The problem of deciding whether a given Boolean formula is satisfiable
Ex.
• The deterministic version of a poly time non deterministic Turing machine will
run in exponential time (worst case)
Hamiltonian cycles
• Hamiltonian cycle, Hamiltonian circuit, vertex tour or graph cycle is a
cycle that visits each vertex exactly once. A graph that contains a
Hamiltonian cycle is called a Hamiltonian graph.
• Determining whether a directed graph has a Hamiltonian cycle does not
have a polynomial time algorithm (yet!)
• However if someone was to give you a sequence of vertices, determining
whether or not that sequence forms a Hamiltonian cycle can be done in
polynomial time.
• Therefore Hamiltonian cycles are in NP
SAT
x
y
x
y
z
z
Satisfiability via path finding
• Since it takes polynomial time to run the program, just run the program and
get a solution
• But is NP a subset of P?
• No one knows if P = NP or not
• Solve for a million dollars!
• http://www.claymath.org/millennium-problems
• The Poincare conjecture is solved today
What is not in NP?
• Undecidable problems
• Given a polynomial with integer coefficients, does it have integer roots
• Hilbert’s nth problem
• Impossible to check for all the integers
• Even a non-deterministic TM has to have a finite number of states!
• More on decidability later
• Tautology
• A boolean formula that is true for all possible assignments
• Here just one ‘verifier’ will not work. You have to try all possible values