NP Completeness
NP Completeness
Criteria:
1. Input
2. Output
3. Definiteness
4. Finiteness
5. Effectiveness
Decision problem: A decision problem is a question that has two possible answers
“yes” or ”no”.
A problem is decidable if there is an algorithm that says yes if the answer is yes,
and no otherwise.
Examples:
Example 1:
AvB
AvC
~B
Prove A.
(A v B) L ~A = B
B L (A v C) = (B L A) v (B L C)
B L ~ B = False
AvB
AvC
~B
Prove ~A.
(A v C) L A = A
(A v B) L A = A
A L ~B = A L ~B
(A L ~B) L (A v B) = A L ~ B
…..
Let LOOP is a program that checks other programs for infinite loops:
Non deterministic algorithm: These machines may not produce the correct
results every time but is guaranteed to produce the correct result if proper
choice is made.
Example :
Deterministic search(a[],n,x)
for i=1 to n do
if(i>n)
else
Nondeterministic_search(a[],n,x)
j=CHOICE(1,n);
Else FAILURE();
Reduction of problems
Example :
Composite(x)
5
if Prime(x)
else
return true;
Composite ∞ Prime
P and NP
Example :
Algorithm Nondeterministic_satisfiability(f,n)
for i=1 to n do
Xi=CHOICE(0,1);
if f(x1,x2,…,xn)
else
FAILURE();
}
7
NP-hard
Reduction from a 3CNF formula into a graph that has an independent set of
a certain size if and only if the formula is satisfiable.
8
The graph has one node for each instance of each literal in the formula.
Two nodes are connected by an edge if (1) they correspond to literals in the
same clause, or (2) they correspond to a variable and its inverse.
Example:
Now suppose the original formula had k clauses. Then we claim that the
formula is satisfiable if and only if the graph has an independent set of size k.
Thus, the reduction is correct. Since the reduction from 3CNF formula to graph
takes polynomial time.
9
To prove that CDP € NP , design a non deterministic algorithm that solves CDP
in polynomial time
Non-deterministic_CDP(G, n)
for i= 1 to k do
x[i]=0;
for i= 1 to k do
if(x[i]≠0)
then FAILURE();
else
x[i]=CHOICE(1,n);
for i= 1 to k -1do
for j= i+1 to k do
SUCCESS();}
12