Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
COMPLEXITY THEORY
Motivation:
Computability : Generally problems are categorize into two, solvable and unsolvable.
Unsolvable means no matter how clever you are, no matter how powerful your digital
computer is, it is impossible to get the solution. you can understand the problem clearly, but
difficult to solve it. Some example of unsolvable problem are Halting problem, post
correspondence problem etc. Mathematicians initially raised this question for ages, what can
be computed and what cannot be computed. For example it is possible to bisect an angle
using ruler and compass, but it is impossible to trisect an angle. It is not possible to write
in decimal form, we can write upto 10000 place or 1 lakh place. No one is able to write in
exact decimal form or no one will ever be able to write in decimal form . They have come up
with a beautiful categorization of computability. Using recursive function they explained
what can be computed and what can not. They said recursive function is the ultimate for
computation. Then logicians, they defined first order logic ,second order logic etc and argued
that this is the ultimate for computation. Then linguistics have come with some symbols and
they said if any thing is computable it can be computed using some string manipulation. They
said type 0 grammar is the ultimate for computation. Turing, Even before the computer is
found, he designed a machine for computation. He said corresponding to any computable
function, there is a instruction set in the machine which is able to compute it. All these
computational models happened independently and everyone argued that their model is the
ultimate for computation.
Even though all the theory was developed independently ,Church claimed that all are
equivalent and his is just like many religion identified god in different way and finally agreed
that all are true
In mid fifties it is agreed that Turing computability is the ultimate .if recursive function
capture some functions which is computable, correspondingly we can design a Turing
machine. Therefore a problem is solvable then it is possible to design a Turing machine. If it is
impossible to design a Turing machine for a particular problem that problem is unsolvable
Complexity Theory
Now things changed from what can be computed to how well it can be computed
It is possible to find an efficient solution for certain problems and in certain other problem it is
not. For a travelling salesman problem it is not possible to get an n 2 algorithm .In automata
theory Idea of non determinism is introduced. here we solve the problem by doing multiple
option concurrently
Deterministic and non deterministic algorithms
The algorithm with the property that the result of every operation is uniquely determined is
known as deterministic algorithm.
Ex Algorithm to find root of a quadratic equation, algorithm to sort n numbers using bubble
sort etc
Algorithms whose outcomes are not uniquely defined but are limited to specified set of
possibilities is known as nondeterministic algorithm
Ex consider the following pseudo code
X = 10;
If(x==5)
{
Call function 1
Or
Call function 2
{
Else {
Call function 3
Or
Call function 4
}. This pseudo code is nondeterministic in nature.
Tractable and intractable problems
The problems that can be solved in finite amount of time is called tractable problems
Ex problem to find sum of 100 numbers
Problems solved using exponential algorithms(having the worst case complexity such as
O(2n),O(nn)) are called intractable problems
EX Travelling salesman problem
Decision problems
Any problem for which the answer is either zero or one is called a decision problem. An
algorithm for a decision problem is termed as a decision algorithm.
P class problem
It is the set of all decision problems that can be solved using deterministic algorithms in
polynomial time.
Feature of P class problem
1) P class problems are decision type problems.
2) P class problems are tractable
3) They are solved using deterministic algorithms
Non deterministic Polynomial(NP) problems
NP problems can be defined as the class of decision problems that can be solved in
polynomial time by non deterministic algorithms. Guess and verify mechanism is used to
prove that a problem is in NP. That is if a certificate is given it can be verified in polynomial
2
time. For example in the Hamiltonian cycle problem, the certificate is the list of vertices in the
Hamiltonian cycle. If a graph is Hamiltonian, the Hamiltonian cycle itself offers enough
information to verify this fact. NP is the set of problems where we can verify a Yes answer
quickly if we have the solution in front of us. For example, the circuit satisfiability problem is
in NP. If the answer is yes, then any set of m input values that produces True output is a proof
of this fact; we can check the proof by evaluating the circuit in polynomial time.
Note : Hamiltonian cycle is a simple cycle that visits every vertex exactly once
Prove that searching problem belongs to NP
Consider the searching problem. problem is to search a particular element in a binary tree. Let
the depth of the binary tree be n. Then the number of elements in the tree having depth n is
2n-1. If we use deterministic algorithm the search would take O(2 n) comparison, which is
exponential one.
But here we apply non deterministic machine to solve this problem as follows.
A non deterministic machine can compare the search element with all elements at each level
in single operation (one unit of time) .That is at each level it can have multiple options and it
will be performed in single unit of time. Therefore the search algorithm will have time
complexity O(n) which is polynomial in nature. Hence above problem is NP.
Note:
Since deterministic algorithms are just a special case of non deterministic one we conclude
that P NP. But it is not known whether P = NP or P NP which is a famous unsolved problem
in computer science.
Polynomial reductions
Defn: Let L1 and L2 be two problems. Problem L1 reduces to L2 iff there is a way to solve L1
by a deterministic polynomial algorithm that solves L2 in polynomial time. This means that if
we have a polynomial algorithm for L2 then we can solve L1 in polynomial time. Or in other
words we write L1 p L2 which means L1 is not more than a polynomial factor harder than L2.
Interpretations of L1 p L2:
3
We know:
L1 is
unsolvable
L2 is unsolvable
L1 is solvable
Nothing about
L2
L2 is solvable
L1 is solvable
L2 is
unsolvable
Nothing about
L1
algorithm for every problem in NP. This is like saying that if we could solve one particular NPhard problem quickly, then we could quickly solve any problem whose solution is easy to
understand, using the solution to that one special problem as a subroutine.
Example: satisfiabilty problem, traveling salesman problem
NP Complete
The concept of NP completeness was introduced by S.A Cook to solve the problem P = NP.
A problem L is said to be NP complete if
1) L
NP
2) For every L 1
NP Complete Problems
The following lemma is the basis of the for showing that a problem is NP complete
Lemma: If L is a problem such that L p L for some L NPC then L is NP hard. Moreover If L
NP then L NPC.
Pf : Since L is NP complete, for all L NP , we have L p L. By supposition . L p L and thus
by transitivity we have L p L , which sows that L is NP hard . If L NP , we also have L
NPC.
Theorem 1
Circuit satisfiabilty problem is NP complete.
Circuit satisfiability is a good example of a problem that we don't know how to solve in
polynomial time. In this problem, the input is a boolean circuit: a collection of and, or, and not
gates connected by wires. The input to the circuit is a set of m boolean (true/false) values x1,
xm. The output is a single boolean value. The circuit satisfiability problem asks, given a
circuit, whether there is an input that makes the circuit output True, or conversely, whether
the circuit always outputs False. Nobody knows how to solve this problem faster than just
5
trying all 2m possible inputs to the circuit, but this requires exponential time. On the other
hand, nobody has ever proved that this is the best we can do; maybe there's a clever
algorithm that nobody has discovered yet! But using non deterministic algorithm we can solve
this problem in polynomial time.(Proof not necessary)
Satisfiabilty problem(SAT)
SATISFIABILITY, or SAT is a problem of great practical importance, with applications ranging
from chip testing and computer design to image analysis and software engineering. It is also a
canonical hard problem. Here's what an instance of SAT looks like:
(x y z) (x y) (y z) (z x) (x y z):
This is a Boolean formula in conjunctive normal form (CNF). It is a collection of clauses (the
parentheses), each consisting of the disjunction of several literals, where a literal is either a
Boolean variable (such as x) or the negation of one (such as x).A satisfying truth assignment
is an assignment of false or true to each variable so that every clause contains a literal whose
value is true.
Let x1,x2, xn be n variables which assumes 2 values 0 or 1. Let f(x1,x2,xn) be a function in
Boolean variable and these variables are connected by connectives AND,OR,NOT,
IMPLICATION and IFF . The problem is to find an assignment for the variable x1,x2,xn such
that f(x1,x2..xn) = 1.The satisfiability problem asks whether a given Boolean formula is
satisfiable.
As an example the formula =(( x1x2) ((x1x3)x4))x2 has the satisfying
assignment x1 = 0, x2 =0, x3=0, x4 =1), since = (( 00) ((01) 1))0 =
(1 (1 1))1 = (10)1 = 1 and hence the formula belongs to SAT.
Qn Prove that satisfiabilty problem is NP complete
Proof : In order to prove SAT in NP complete we need to show 1) SAT
To prove SAT
NP 2) SAT is NP HARD
NP
X1,x2..xn are n variable which takes values either 0 or 1.We need to find the assignment of
the variable x1,x2xn with values 0 or 1 so that f(x1,x2,..xn) = 1.In order to find truth
assignment for the variable we have to see the all the possibilities. Since there are 2 n different
possibilities, the time complexity is O(2n) if we apply deterministic algorithm.
So we apply non deterministic algorithm to solve this problem. We arrange each assignment
in a tree as follows.
Suppose n=3, then different assignments are (0,0,0), (0,0,1), (1,0,0), (1,1,0), (1,0,1), (0,1,0),
(1,0,1), (0,1,1).
NP
To prove SAT
Here we prove that CIRCUIT SAT P SAT. In other words any instance of circuit satisfiabilty can
be reduced in polynomial time to an instance of formula satisfiability. For example, we could
transform the given circuit into a formula as follows:
Y8 = y4 y7 y6
=(y1 x2) (y5 y3) x5
=((x1 x4 ) x2) (x2 (y2x3)) x5
= ( x1 x2) (x4 x2) (x2 y2) (x2 x3) x5 which is in CNF.
Now the original circuit is satisfiable if and only if the resulting formula is satisfiable. For each
wire xi in the circuit ,the formula has a variable xi. The proper operation of a gate can now
be expressed a formula involving the variable of its incident wires. If the circuit C has a
satisfying assignment ,each wire of the circuit has a well defined value and output of the
circuit is 1.Therefore the assignment of wire values to variables in makes each clause of
evaluate to 1 and thus conjunction of all evaluates to 1. Conversely if there is an assignment
that causes to evaluate 1,the circuit is satisfiable by an analogous argument. Thus we have
CIRCUIT SAT P SAT.
We have already proved by theorem 1 that CIRCUIT SAT IS NP COMPLETE. Since CIRCUIT SAT
is NP Complete,SAT NP and CIRCUIT SAT P SAT, SAT is also NP Complete
Prove that 3 CNF satisfiabilty( 3 SAT) is NP complete
A literal in a Boolean formula is an occurrence of a variable or its negation. A Boolean formula
is in conjunctive form or CNF if it is expressed as an AND of clauses,each of which is the OR of
one or more literals. A Boolean formula is in 3-conjunctive form or 3 CNF if each clause has
exactly 3 distinct literals. For example the Boolean formula ( x1 x1 x2) ( x3 x2
x4) (x1 x3 x4 ) is in 3 CNF. In 3 CNF-SAT, we are asked whether a given Boolean
formula is satisfiable
To prove 3 CNF NP
The same proof for the SAT NP can be given . Here
literals.
To prove 3-CNF NP hard ,we show that SAT P 3-CNF-SAT . The reduction algorithm can be
broken into 3 basic steps
Step 1: first we construct a binary parse tree for the input formula with literals as leaves
and connectives as internal nodes. The parse tree for the formula =(( x1x2)
((x1x3)x4))x2 is
We introduce a variable yi for the output of each internal node. Then we rewrite the
original formula as the AND of the root variable and a conjunction of clause describing the
operation of each node. The resulting expression corresponding to the formula is
= y1 (y1(y2 x2)
Step 2 : we convert each clause I into conjunctive normal form. We construct a truth table
for i by evaluating all possible assignments to its variable. Each row of the truth table
consists of a possible assignment of the variables of the clause ,together with the value of
the clause under that assignment. Using the truth variable entries that evaluate to 0, we build
a formula in disjunctive form, which is equivalent to
CNF using DeMorgans law. For example we take 1 = (y1(y2 x2) and the truth table
corresponding to this is
y1
y2
x2
(y1(y2 x2)
0
0
0
1
Therefore the DNF is
1 = ( y1 y2 x2) ( y1 y2 x2) (y1 y2 x2)
( y1 y2 x2) we get CNF by applying DeMorgans law . i.e
1 = ( y1 y2
x2) ( y1 y2 x2) (y1 y2 x2) (y1 y2 x2) . Similarly each clause i of
the formula can be converted to i, which is a CNF with almost 3 literals
Step 3 : Each clause has exactly 3 distinct literals
For each clause Ci of , we include following clauses in .
1) If Ci has 3 distinct literals we simply include Ci as a clause of .
2) If Ci has 2 distinct literals, that is if Ci = (l1 l2) then we include (l1 l2 p) (l1 l2
p) as clause of .
3) If Ci has just 1 distinct literal l then we include (l p q) (l p q) (l p
q) (l p q) as clause of ,
We can see that 3-CNF formula is satisfiable iff is satisfiable. The construction of
from in the first step preserves satisfiability. The second step produces a CNF formula
that is equivalent to . The third step produces a 3 CNF formula that is equivalent to .
Hence SAT P 3-CNF-SAT.We have already proved that SAT IS NP COMPLETE. Since 3- CNF
NP and SAT P 3- CNF SAT, 3 -CNF is also NP Complete.
is transformed into the following graph. (Look for the edges that aren't in the graph.)
Now suppose the original formula had k clauses. Then we claim that the formula is satisfiable
if and only if the graph has a clique of size k.
1. k-clique =) satisfying assignment: If the graph has a clique of k vertices, then each vertex
must come from a different clause. To get the satisfying assignment, we declare that each
literal in the clique is true. Since we only connect non-contradictory literals with edges,this
10
declaration assigns a consistent value to several of the variables. There may be variables that
have no literal in the clique; we can set these to any value we like.
2. satisfying assignment =) k-clique: If we have a satisfying assignment, then we can choose
one literal in each clause that is true. Those literals form a clique in the graph.Thus, the
reduction is correct. Since the reduction from 3CNF formula to graph can be done in
polynomial time, so MaxClique is NP-hard.
From (1) and (2) clique problem is NP complete
Hamiltonian cycle problem is NP Complete ;
CIRCUITSAT
SAT
3 CNF
SAT
CLIQU
E
SUBSET SUM
VERTEX
COVER
HAM
CYCLE
TSP
Np COMPLETE PROBLEMS
Explain church Thesis
It says that No computational procedure will be considered an algorithm unless it can be
represented as a Turing machine. In other words we can say any thing which is computable
can be designed using T M. This was given by Alonzo Church in 1936. According to him T M is
equivalent to all computing model .This highlights that T M is the Ultimate for computation
POST CORRESPONDANCE PROBLEM (PCP).
The PCP was first formulated by Emit Post in 1940. Given two sequence of n strings on some
alphabets . Say X = { x1,x2,xn } and Y = {y1 , y2, yn }. Now the problem is ; Does
there exist a non empty sequence of integers i1,i2.ik such that k 1 and
xi1xi2xik =
yi1yi2.yik ?
Example : Let
X1
bc
Y1
ab
x2
ab
y2
x3
b
bca
x1
bc
y3
y1
x4
a
y4
12
y3 =b y4 = a. For the
The problem given an arbitrary instance of PCP, whether that instance has
a solution is undecidable
13