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

Final Toc Unit Vi

Uploaded by

ayushraskar14
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 views51 pages

Final Toc Unit Vi

Uploaded by

ayushraskar14
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/ 51

Unit-VI

Computability and
Complexity Theory

Class-TE Comp
 Decidable Problems:
 A problem is said to be Decidable if we can always construct
a corresponding algorithm that can answer the problem
correctly.
 We can possibly understand Decidable problems by
considering a simple example.
 Suppose we are asked to compute all the prime numbers in
the range of 1000 to 2000.
 To find the solution of this problem, we can easily devise an
algorithm that can enumerate all the prime numbers in this
range.
 Decidability in terms of a Turing machine, a problem is said
to be a Decidable problem if there exists a corresponding
Turing machine which halts on every input with an answer-
yes or no.
Class-TE Comp
 Undecidable Problems:
 The problems for which we can’t construct an algorithm that
can answer the problem correctly in finite time are termed as
Undecidable Problems.
 These problems may be partially decidable but they will never
be decidable. That is there will always be a condition that will
lead the Turing Machine into an infinite loop without
providing an answer at all.
 popular Undecidable Problem which states that no three
positive integers a, b and c for any n>2 can ever satisfy the
equation: a^n + b^n = c^n.
 If we feed this problem to a Turing machine to find such a
solution which gives a contradiction then a Turing Machine
might run forever, to find the suitable values of n, a, b and c.

Class-TE Comp
 Undecidable Problems:
 Whether a CFG generates all the strings or not?
 As a CFG generates infinite strings, we can’t ever reach up to
the last string and hence it is Undecidable.
➢ Whether two CFG L and M equal?
 Since we cannot determine all the strings of any CFG, we can
predict that two CFG are equal or not.
➢ Ambiguity of CFG?
 There exist no algorithm which can check whether for the
ambiguity of a CFL. We can only check if any particular
string of the CFL generates two different parse trees then the
CFL is ambiguous.

Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
The Church-Turing thesis:
The Church-Turing thesis says that every solvable decision
problem can be transformed into an equivalent Turing machine
problem.
It can be explained in two ways, as given below −
The Church-Turing thesis for decision problems.
The extended Church-Turing thesis for decision problems.
Let us understand these two ways.
The Church-Turing thesis for decision problems:
There is some effective procedure to solve any decision
problem if and only if there is a Turing machine which halts
for all input strings and solves the problem.
The extended Church-Turing thesis for decision problems:
A decision problem Q is said to be partially solvable if and
only if there is a Turing machine which accepts precisely the
elements of Q whose answer is yes. Class-TE Comp
The Church-Turing thesis:
Proof
A proof by the Church-Turing thesis is a shortcut often taken in
establishing the existence of a decision algorithm.
For any decision problem, rather than constructing a Turing
machine solution, let us describe an effective procedure which
solves the problem.
The Church-Turing thesis explains that a decision problem Q has
a solution if and only if there is a Turing machine that determines
the answer for every q ϵ Q. If no such Turing machine exists, the
problem is said to be undecidable.
Class-TE Comp
 Growth Rates:
Algorithms analysis is
all about
understanding growth
rates.
That is as the amount
of data gets bigger,
how much more
resource will my
algorithm require?
Typically, we describe
the resource growth
rate of a piece of code
in terms of a function.

Class-TE Comp
Asymptotic notation
• Big Theta (T)
• Big Oh(O)
• Big Omega ()

Class-TE Comp
Big Oh (O):-
• f(n)= O(g(n)) if there exist positive constants c and n0 such
that f(n) ≤ cg(n) for all n ≥ n0
• O-notation to give an upper bound on a function.
• For example, consider the case of Insertion Sort.
• g(n) is upper bound of the f(n) if there is exists some positive
constants c and n0.It is denoted as f(n)=O(g(n)).

Class-TE Comp
 Omega Notation:-
Big oh provides an asymptotic upper bound on a function.
Omega provides an asymptotic lower bound on a function.
Running time of the algorithm cannot be less than asymptotic lower
bound for sequence of the data.

Class-TE Comp
Theta Notation:-
• Theta notation is used when function f can be bounded both
from above and below by the same function g.
• Running time of the algorithm cannot be less than or greater
than its asymptotic tight bound for random sequence of the
data.

Class-TE Comp
DETERMINISTIC ALGORITHM & NON-
DETERMINISTIC ALGORITHM
DETERMINISTIC ALGORITHM
• In Deterministic algorithm For a particular input the
computer will give same output every time.
• Examples are finding odd or even,sorting,finding max etc.
• Most of the algorithm are deterministic in nature.
• It is solve in polynomial time.

Class-TE Comp
• NON-DETERMINISTIC ALGORITHM:-
• In non deterministic algorithm for a same input the computer
will give different output on different execution.

• This algorithm operates in two phases Guessing and


Verification.
• Randomly picking some elements from the list and check if it
is maximum is non-deterministic.

• It is not solve in polynomial time.

• To specify such non deterministic algorithm there are 3


function used in algorithm.

Class-TE Comp
The following Function
1) Choice()- Select one of the element of set ‘s’.
2) Failure()- Check for unsuccessful completion.
3) Success()- check for successful completion.
Ex) Write algorithm for searching for an element ‘x’ from the given set of element
n.
Solution:-
// A is an array of size n
1) Mid = choice(1,n);--------------------Guessing Stage
2) If A[mid]==x then
{
write(mid);-----------------------------Verification Stage
success();
}
Else
{
Write(0);
Failure();
}

Class-TE Comp
POLYNOMIAL AND NON-POLYNOMIAL
PROBLEMS
The computing time or any algorithm is divided

into two groups

1) POLYNOMIAL Problem:-It is Problem

whose solution times are bounded.

2) Non POLYNOMIAL Problem:-It is

Problem whose solution not times are

bounded. That is output is not predictable.

Class-TE Comp
P-Class Problem:-
• The class P consists of those problems that are solvable in
polynomial time, i.e. these problems can be solved in time
O(nk) in worst-case, where k is constant.
• These problems are called tractable, while others are called

intractable or super polynomial.

• The advantages in considering the class of polynomial-time


algorithms is that all reasonable deterministic single processor
model of computation can be simulated on each other with at
most a polynomial.

Class-TE Comp
NP-Class Problem:-
• The class NP consists of those problems that are verifiable in
polynomial time. NP is the class of decision problems for
which it is easy to check the correctness of a claimed answer,
with the aid of a little extra information.

• Every problem in this class can be solved in exponential time


using exhaustive search.

Class-TE Comp
DIFFERENCE BETWEEN P PROBLEMS AND NP PROBLEMS

Class-TE Comp
Relation between P,NP,NP hard and
NP Complete

Class-TE Comp
DIFFERENCE BETWEEN NP HARD AND NP
COMPLETE PROBLEM

Class-TE Comp
• Examples:

• Knapsack problem

• Hamiltonian path problem

• vertex cover problem

• Boolen satisfiabiltiy problem

• clique problem

Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
Class-TE Comp
3-Satisfiability:-
•Satisfiability's role as the first NP-complete problem implies that the
problem is hard to solve in the worst case, but certain instances of the
problem are not necessarily so tough. .
•Input: A collection of clauses C where each clause contains exactly 3
literals, over a set of Boolean variables V.
•Output: Is there a truth assignment to V such that each clause is satisfied?
Since this is a more restricted problem than satisfiablity, the hardness of 3-
SAT implies that satisfiability is hard. The converse isn't true, as the
hardness of general satisfiability might depend upon having long clauses.
We can show the hardness of 3-SAT using a reduction that translates every
instance of satisfiability into an instance of 3-S.

Class-TE Comp
3-Satisfiability:-
•Theorem: CNF-SAT is in NP complete.
•Proof: Let S be the Boolean formula for which we can construct a simple
non-deterministic algorithm which can guess the values of variables in
Boolean formula and then evaluates each clause of S.
•If all the clauses evaluate S to 1 then S is satisfied.
•Thus CNF-SAT is in NP-complete.

Class-TE Comp
3-Satisfiability:-
•Theorem: 3SAT is in NP complete.
•Proof: Let S be the Boolean formula having 3 literals in each clause for
which we can construct a simple non-deterministic algorithm which can
guess an assignment of Boolean values to S.
•If the S is evaluated as 1 then S is satisfied.
•Thus we can prove that 3SAT is in NP-complete.

Class-TE Comp
Clique Decision Problem:-
What is Clique?
It is sub graph of graph which is complete.

Class-TE Comp
Prove that Clique Decision problem is NP
Hard

Class-TE Comp
Class-TE Comp
Hamiltonian Cycle:-
 Hamiltonian Path in an undirected graph is a path that
visits each vertex exactly once.
 A Hamiltonian cycle (or Hamiltonian circuit) is a
Hamiltonian Path such that there is an edge (in the graph)
from the last vertex to the first vertex of the Hamiltonian
Path.

Class-TE Comp
Hamiltonian Cycle:-
 HAMILTONIAN CYCLE is in NP Complete.
 Proof: Let A be some non-deterministic algorithm to
which graph G is given as input.
 The vertices of graph are numbered from 1 to N. We
have to call the algorithm recursively in order to get the
sequence S.
 This sequence will have all the vertices without getting
repeated.
 The vertex from which the sequence starts must be ended
at the end.
 This check on the sequence S must be made in
polynomial time n.

Class-TE Comp
Hamiltonian Cycle:-
 HAMILTONIAN CYCLE is in NP Complete.
 Now if there is a Hamiltonian cycle in the graph then
algorithm will output "yes".
 Similarly if we get output of algorithm as "yes" then we
could guess the cycle in G with every vertex appearing
exactly once and the first visited vertex getting visited at
the last.
 That means A non-deterministically accepts the language
HAMILTONIAN CYCLE.
 It is therefore proved that HAMILTONIAN CYCLE is in
NP Complete.

Class-TE Comp
Post Correspondence Problem (PCP)
•The Post Correspondence Problem (PCP), introduced by
Emil Post in 1946, is an undecidable decision problem.
•The PCP problem over an alphabet ∑ is stated as follows −
•Given the following two lists, M and N of non-empty
strings over ∑ −
M = (x1, x2, x3,………, xn)
N = (y1, y2, y3,………, yn)
•We can say that there is a Post Correspondence Solution, if
for some i1,i2,………… ik, where 1 ≤ ij ≤ n, the condition
xi1 …….xik = yi1 …….yik satisfies.Class-TE Comp
Post Correspondence Problem (PCP)
Example 1
Find whether the lists
M = (abb, aa, aaa) and N = (bba, aaa, aa)
have a Post Correspondence Solution?
Solution:-

x2x1x3 = ‘aaabbaaa’
and y2y1y3 = ‘aaabbaaa’
We can see that
x2x1x3 = y2y1y3
Hence, the solution is i = 2, j = 1, and k = 3.
Class-TE Comp
Post Correspondence Problem (PCP)
Example 2
Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba,
bab) have a Post Correspondence Solution?
Solution:-

In this case, there is no solution because −


| x2x1x3 | ≠ | y2y1y3 | (Lengths are not same)
Hence, it can be said that this Post Correspondence Problem
is undecidable.

Class-TE Comp
TRAVELLING SALESPERSON PROBLEM

Class-TE Comp
Class-TE Comp
TRAVELLING SALESPERSON PROBLEM

Class-TE Comp
TRAVELLING SALESPERSON PROBLEM

Class-TE Comp
Class-TE Comp
PROF. ANAND GHARU
PVGCOE NASHIK
anandgharu.wordpress.com

Scanned by CamScanner
PROF. ANAND GHARU
PVGCOE NASHIK
anandgharu.wordpress.com

PROF. ANAND GHARU


PVGCOE NASHIK
anandgharu.wordpress.com

Scanned by CamScanner

You might also like