Unit 5 - PPT[1]
Unit 5 - PPT[1]
Introduction to
Computational Complexity
Unit 5
Recap :
1. Definition of Turing machines: high level and low-level descriptions
• is empty?
• is regular?
• has size 2?
Examples:
1. Set of regular languages I
2. Set of context-free languages I
3. Set of all languages I
4. {∅} I
5. ∅
NO
: is accepted by some
Turing machine?
True for all
Turing-acceptable languages
Unit 5 / SRMIST / KTR 29
We can describe a property as the set
of languages that possess the property
Example: : is empty?
YES
NO
NO
Unit 5 / SRMIST / KTR 30
Example: Suppose alphabet is
: has size 1?
NO
YES
NO
NO
Corresponding language:
What do you do when Rice’s theorem does not apply? Fall back on reductions!
Here,
x2x1x3 = ‘aaabbaaa’
x2x1x3 = y2y1y3
• Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have
a Post Correspondence Solution?
Solution for Example 2
• General Objective:
• Specific Objectives
– Define MPCP
• Goal:
– To prove this problem about strings
to be undecidable
Post Correspondence Problem
FORMAL DEFINITION
• lists of strings A and B ( equal length)
Given two
wi1wi2…wim = xi1xi2…xim
Definition:
First pair in the A and B lists must be the first pair in the solution, i.e., the problem
is to determine if there is a sequence of zero or more integers i1, i2, …, im such
that:
w1wi1wi2…wim = x1xi1xi2…xim
Modified Post Correspondence Problem (MPCP)
List A List B
i wi xi
1 10 10
2 110 11
3 11 011
w1 w2 w3 = x1 x2 x3
10 110 11 = 10 11 011
Undecidability of PCP
To show that PCP is undecidable, we will reduce the universal
language problem (Lu) to MPCP and then to PCP:
Universal
A mapping MPCP A mapping PCP
Language
Problem (Lu )
If T accepts w, the two lists can be matched. Otherwise, the two lists cannot be
matched.
Rules of Reducing Lu to MPCP
List A List B
qX Yp from δ(q,X)=(p,Y,R)
ZqX pZY from δ(q,X)=(p,Y,L)
q# Yp# from δ(q,#)=(p,Y,R)
Zq# pZY# from δ(q,#)=(p,Y,L)
List A List B
Xq q
qY q
Xq q
Y
where q is an accepting state, and each X and Y is any
tape symbol except the blank.
• Ending string:
List A List
q## B #
Time complexity
x€0n1n
0 0 0 1 1 1
Length n
Space complexity
x€0n1n
• Make the input tape as read only tape
• How much space it require for computation?
• If it uses tape as a stack it requires O(n) cells
• Add Binary counter logic to the TM so If n=64,it takes
log2(n)=7 bits in binary to keep the count
-
P and NP problems
• P:P problems refer to problems where an algorithm would take a polynomial
amount of time to solve, or where Big-O is a polynomial (i.e. O(1), O(n), O(n²),
etc).
• These are problems that would be considered ‘easy’ to solve, and thus do not
generally have immense run times.
• Examples:
• a. Linear Search
• b. Binary Search
• c. Merge Sort
• d. Quick sort etc.,
P and NP problems
• Can you guess the approximate time complexity of the given problem.
NP-Hard and Complete-Need
• Most of the algorithms are categorized into polynomial time (linear time),
exponential time (2^n)algorithms.
Exponential Algorithms are much more time consuming than Polynomial Algorithms.
The framework for converting Exponential to Polynomial Algorithms is called NP
Hard and Np Complete problems.
P and NP problems
• Non deterministic Polynomial time solving.
• Problem which can't be solved in polynomial time like TSP( travelling salesman problem)
• An easy example of this is subset sum: given a set of numbers, does there exist a subset whose sum is
zero?.
• but NP problems are checkable in polynomial time means that given a solution of a problem , we can check
that whether the solution is correct or not in polynomial time.
NP and P Problems
• P -Deterministic polynomial time Algorithms
• NP-Non Deterministic Polynomial Algorithms
NP
P
NP Hard and NP Complete
• Before knowing about NP-Hard and NP-Complete we need to know
about reducibility:
• Reduction:
• Consider there are two problems, A and B, and we know that the
problem A is NP class problem and problem B is a P class problem.
• If problem A can be reduced, or converted to problem B, and this
reduction takes a polynomial amount of time, then we can say that A
is also a P class problem (A is reducible to B).
NP Hard and NP Complete
• A problem is classified as NP-Hard when an algorithm for solving it
can be translated to solve any NP problem.
• Then we can say, this problem is at least as hard as any NP problem,
but it could be much harder or more complex.
• NP-Complete problems are problems that live in both the NP and NP-
Hard classes.
• This means that NP-Complete problems can be verified in polynomial
time and that any NP problem can be reduced to this problem in
polynomial time.
How to convert Exponential Algorithms to Polynomial
Algorithms?
This can be done in two ways
• By finding Deterministic and Non Deterministic Polynomial Algorithms
• Deterministic –finite solution for every run of the program
• Non Deterministic-random solution for every run of the program(every state has
n number of possible next states)
Or
y=1 y=0
1 0
z=1 0 1 0 1 0 1 0
If this problem is solved all other exponential algorithms can be solved in polynomial time!
Np Hard-Reduction
• SAT is a Np-Hard Problem
• SAT L1,L1 L2 then L2 is also NP Hard hence transitive property holds true.
Np Complete
If a problem comes under Np Hard and if it has a non deterministic algorithm then it is
also called as a Np Complete problem
• SAT will come into P if and only if P=NP, it will become deterministic.
Clique to Vertex Cover
Summary
• NP-Hard
• Np-Complete
• Cook’s Theorem
Hope all our Non Deterministic Algorithms will turn into Polynomial Deterministic
Algorithm i.e.P=NP☺