0% found this document useful (0 votes)
23 views12 pages

NP Completeness

An algorithm is a set of instructions that accomplishes a task. The document discusses different types of algorithms and problems including tractable, intractable, decision, optimization, decidable, undecidable, deterministic, non-deterministic problems. It also discusses complexity classes P, NP, NP-hard and provides examples to explain these concepts.

Uploaded by

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

NP Completeness

An algorithm is a set of instructions that accomplishes a task. The document discusses different types of algorithms and problems including tractable, intractable, decision, optimization, decidable, undecidable, deterministic, non-deterministic problems. It also discusses complexity classes P, NP, NP-hard and provides examples to explain these concepts.

Uploaded by

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

1

An algorithm is a finite set of instructions that if followed accomplishes a


particular task

Criteria:

1. Input
2. Output
3. Definiteness
4. Finiteness
5. Effectiveness

Tractable and Intractable problems

Tractable problems: The problems that can be solved in polynomial


time complexity

Intractable problems: The problems that can be solved in exponential time


complexity

Decision and Optimization algorithm

Decision algorithm: A decision algorithm gives the answer “YES” or “NO”

Optimization algorithm: A optimization algorithm maximizes or


minimizes a criterion function

Decision problem: A decision problem is a question that has two possible answers
“yes” or ”no”.

Decidable, semi-decidable and undecidable problems

A problem is decidable if there is an algorithm that says yes if the answer is yes,
and no otherwise.

Examples:

Given a graph G and a set of vertices K. Is K a clique?

Given a graph G and a set of edges M, is M a spanning tree?


2

Given a set of axioms (boolean expressions) and an expression,


is the expression provable under the axioms?

A problem is semi - decidable if there is an algorithm that says yes


if the answer is yes, however it may loop infinitely if the answer is no.

Examples of semi-decidable problems:

Example 1:

Given a set of axioms, prove that an expression is true.

Problem 1: Let the axioms be:

AvB

AvC

~B

Prove A.

To prove A we add ~A to the axioms.


If A is true then ~A will be false and this will cause a
contradiction - the conjunction of all axioms plus ~A will
result in False

(A v B) L ~A = B

B L (A v C) = (B L A) v (B L C)

B L ~ B = False

Problem 2: Let the axioms be:

AvB

AvC

~B

Prove ~A.

We add A and obtain:


3

(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

…..

This process will never stop, because the expressions we obtain


will always be different from False

Example 2: Given an infinite set of strings, determine whether a given string


belongs to the set or not.

A problem is undecidable if we can prove that there is no algorithm


that will deliver an answer.

Example of undecidable problem.

The halting problem

Let LOOP is a program that checks other programs for infinite loops:

LOOP(P) stops and prints "yes" if P loops infinitely

LOOP(P) enters an infinite loop if P stops

What about LOOP(LOOP)?

Deterministic and Non deterministic algorithm

Deterministic algorithm :The output of each and every step can be


uniquely determined i.e. for a particular input the underlying machine
will produce the same output and pass through the same irrespective of
how many times we are running the machine for that particular input.

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.

It has two parts:

1. A non deterministic part that includes guessing a solution


4

2. A deterministic part that checks whether the guessed solution is


correct or not

Example :

Deterministic search(a[],n,x)

for i=1 to n do

if (a[i]==x) then break;

if(i>n)

Print “unsuccessful search”;

else

print “element found at ith position”

Nondeterministic_search(a[],n,x)

j=CHOICE(1,n);

If (a[j]==x) then SUCCESS();

Else FAILURE();

Reduction of problems

The problem X is said to be reduced to another problem Y if there exist an


algorithm A for Y and that algorithm can be used to solve X

Example :

Composite(x)
5

if Prime(x)

then return f alse;

else

return true;

Composite ∞ Prime

Polynomial reduction: The problem X is said to be polynomialy reducible


to another problem Y if and only if there is a way to solve X using a
deterministic polynomial time algorithm that solves Y in polynomial time.

P and NP

P is the set of all decision problems solvable by deterministic


algorithm in polynomial time.

NP is the set of all decision problems solvable by non-deterministic


algorithm in polynomial time.

 To prove that problem A is NP, design a non deterministic algorithm


that verifies A in polynomial time
6

Example :

Satisfiability problem : Given a digital circuit with n Boolean variables as


inputs and a single output, the problem is to determine whether or not
there exists some binary certificate for which the output will be 1.

Algorithm Nondeterministic_satisfiability(f,n)

//Determines whether the propositional formula f is satisfiable.

//The input variables are x1,x2,…,xn

for i=1 to n do

Xi=CHOICE(0,1);

if f(x1,x2,…,xn)

then SUCCESS ();

else

FAILURE();

}
7

NP-hard

A problem L is NP-hard if f Satisfiability/ Any known NP-hard


problem reduces to L

 To prove that problem A is NP-hard, reduce a known NP-hard problem to


A.

A problem L is NP-complete iff L is NP-Hard and L € NP

 To prove that problem A is NP-complete, reduce a show that it is NP-hard


and it is NP

Maximum Independent (from 3SAT)


Let G be an arbitrary simple, unweighted graph. An independent set
in G is a subset of the vertices of G with no edges between them. The
maximum independent set problem, or simply MAXINDSET, asks for
the size of the largest independent set in a given graph.

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.

1. independent set satisfying assignment: If the graph has an


independent set of k vertices, then each vertex must come from a
different clause. To obtain a satisfying assignment, we assign the value
TRUE to each literal in the independent set. Since contradictory literals
are connected by edges, this assignment is consistent. There may be
variables that have no literal in the independent set; we can set these to
any value we like. The resulting assignment satisfies the original 3CNF
formula.

2. satisfying assignment  independent set: If we have a satisfying


assignment, then we can choose one literal in each clause that is TRUE.
Those literals form an independent set in the graph.

Thus, the reduction is correct. Since the reduction from 3CNF formula to graph
takes polynomial time.
9

Here’s a diagram of the reduction:


A clique is another name for a complete graph, that is, a graph where every
pair of vertices is connectedby an edge.
The maximum clique size problem, or simply MAXCLIQUE, is to compute, given a
graph, the number of nodes in its largest complete subgraph.

There is an easy proof that MAXCLIQUE is NP-hard, using a reduction from


MAXINDSET. Any graph G has an edge-complement G with the same vertices, but
with exactly the opposite set of edges—(u, v) is an edge in G if and only if it is
not an edge in G. A set of vertices is independent in G if and only if the same
vertices define a clique in G. Thus, we can compute the largest independent in
a graph simply by computing the largest clique in the complement of the
graph G.
10

Clique decision problem: Given a simple graph G and an integer K,


the problem is to find whether or not there exists a complete subgraph /
clique with K vertices

In order to prove that CDP is NP-Complete, first prove it to be NP- hard


11

To prove that CDP € NP , design a non deterministic algorithm that solves CDP
in polynomial time

Non-deterministic_CDP(G, n)

//x[1:k] is used to store the vertices in the clique

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

if(G(i,j)==0) then FAILURE();

SUCCESS();}
12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy