0% found this document useful (0 votes)
110 views

Chapter Two-Computational Complexity

This chapter discusses computational complexity theory, which attempts to determine how many resources are required to solve computational problems. It introduces two types of computational complexity: time complexity, which measures how fast a program runs based on the number of steps, and space complexity, which measures the total space used by an algorithm based on input size. Computational problems can be classified based on their complexity classes. The chapter then discusses Turing machines as a mathematical model of computation that is used to analyze computability and complexity. It provides examples of constructing Turing machines to solve specific problems and languages.

Uploaded by

Ermias Mesfin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Chapter Two-Computational Complexity

This chapter discusses computational complexity theory, which attempts to determine how many resources are required to solve computational problems. It introduces two types of computational complexity: time complexity, which measures how fast a program runs based on the number of steps, and space complexity, which measures the total space used by an algorithm based on input size. Computational problems can be classified based on their complexity classes. The chapter then discusses Turing machines as a mathematical model of computation that is used to analyze computability and complexity. It provides examples of constructing Turing machines to solve specific problems and languages.

Uploaded by

Ermias Mesfin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Chapter Two

Computational Complexity

Overview
Complexity theory (from elementary Algorithm Analysis) is concerned with
 analyzing a program (or its efficiency),
 figuring out whether the program is correct,
 figuring out whether one program is better than the other and
 representing the program a quantified way.
From programming perspective, there are two main complexities:
Time complexity
 determines how fast your code runs,
 determines how much time it will take (depends on the number of steps).
 is hardware-independent
Space Complexity:
 the total space taken by the algorithm with respect to the input size.
 Space complexity includes both Auxiliary space and space used by input.
o Auxiliary Space is the extra space or temporary space used by an algorithm.
Example of Complexity in Time (execution) and Space (memory) factors:
Example-1: More Complex
i = 1; 1s
while( i <= 10 ) 11s
{
a = 5; 10s
result = i * a; 10s
printf(“\n” /d”, result); 10s
i++; 10s
}
Here, we assume each variable is equal to 2 Bytes. In the above example we use three variables (i,
a, result) which is 6 Bytes.
Execution Time: 52s
Memory (Space): 6 Bytes

Example-2 : Less Complex


a = 5; 1s
i = 1; 1s
while( i<=10) 11s
{
result = i * a; 10s
printf(“\n” /d”, result); 10s
i++; 10s
}
Execution Time : 43s
Memory (Space) : 6 Bytes
Chapter Two: Computational complexity
Compiled by L.N. Page 1
A computational problem: is a problem that may be solved by an algorithm. For example, the
problem of factoring "Given a positive integer n, find a nontrivial prime factor of n” is a
computational problem. It can be viewed as a set of instances or cases together with a, possibly
empty, set of solutions for every instance/case. For example, in the factoring problem, the
instances are the integers n, and solutions are prime numbers p that describe nontrivial prime
factors of n.

The field of computational complexity theory attempts to determine the amount of resources
(computational complexity) solving a given problem will require and explain why some problems
are intractable or undecidable.

Computational problems belong to complexity classes that define broadly the resources (e.g.
time, space/memory, energy, circuit depth) it takes to compute (solve) them with various abstract
machines. For example, the complexity class P for classical machines, and BQP for quantum
machines.

Computability theory: The branch of theory of computation that studies which problems are
computationally solvable using different model. In computer science, the computational complexity,
or simply complexity of an algorithm is the amount of resources required for running it.

Complexity Theory: is concerned with the study of the intrinsic complexity of computational tasks.
Its final goal includes the determination of the complexity of any well-defined task. Computer
science is devoted to complexity theory. Computer scientists use complexity theory to relate and
group problems together. In some cases, if one problem can be solved, it opens up a way to solve
other problems in the complexity class as well.

Problems in Computational Complexity:


Solvable Problems:
 A computational problem that can be solved by a TM. The problem may have a non-binary
output.
 Or A problem is said to be solvable if there exists an algorithm and a potential solution.

Unsolvable Problem:
 An unsolvable problem is one for which no algorithm can ever be written to find the
solution.

Decidable Vs Undecidable Problems:


Solvable problems are divided into two categories –
Decidable Problem: a decision problem that can be solved by an algorithm that halts on all
inputs in a finite number of steps.

Chapter Two: Computational complexity


Compiled by L.N. Page 2
Decision problems
A decision problem has only two possible outputs (yes or no) on any input. In computability theory
and computational complexity theory, a decision problem is a problem that can be posed as a yes-no
question of the input values. Like is there any solution to a particular problem? The answer would be
either a yes or no. A decision problem is any arbitrary yes/no question on an infinite set of inputs.
Decidable problems assume two important terms: procedures and algorithms:
 Procedure: is a step-by-step instruction to solve a problem. A procedure becomes an
algorithm when we determine the approximate time to solve a problem.
 Hence, decidable problems include both algorithms as well as procedures.

Undecidable Problem: is one for which no algorithm can ever be written that will always give a
correct true/false decision for every input value.
 Undecidable problems are a subcategory of unsolvable problems that include only problems
that should have a yes/no answer (such as: does my code have a bug?).

Turing Machine

A TM is a mathematical model of computation. A TM is a general example of a CPU that controls


all data manipulation done by a computer. TM can be halting as well as non-halting and it depends
on algorithm and input associated with the algorithm.

Turing formulated a model of algorithm or computation that is widely accepted. The Church- Turing
thesis states that any algorithmic procedure that can be carried out by human beings/computer can be
carried out by a Turing machine. It has been universally accepted by computer scientists that the
Turing machine provides an ideal theoretical model of a computer.

For formalizing computability, Turing assumed that, while computing, a person writes symbols on a
one-dimensional tape which is divided into cells. One scans the cells one at a time and usually
performs one of the three simple operations, namely
i) writing a new symbol in the cell being currently scanned,
ii) moving to the cell left of the present cell and
iii) moving to the cell light of the present cell. With these observations in mind, Turing
proposed his 'computing machine.'

Chapter Two: Computational complexity


Compiled by L.N. Page 3
In Summary a TM
 was invented by Alan Turing in 1936
 used to accept Recursive Enumerable Languages (generated by Type-0 Grammar).
 Consists of a tape of infinite length and do have read and write operation.
 Each cell either contains input symbol or a special symbol called blank.
 It also consists of a head pointer (tape head) which points to cell currently being read
 The tape head can move in both directions.

The Model
Formally, a TM (TM) is expressed as a 7-tuple (Q, T, B, ∑, δ, q0, F) where:
 Q is a finite set of states
 T is the tape alphabet (symbols which can be written on Tape)
 B is blank symbol (every cell is filled with B except input alphabet initially)
 ∑ is the input alphabet (symbols which are part of input alphabet)
 δ is a transition function which maps Q × T → Q × T × {L, R}. Depending on its present
state and present tape alphabet (pointed by head pointer), it will move to new state, change
the tape symbol (may or may not) and move head pointer to either left or right.
 q0 is the initial state
 F is the set of final states. If any state of F is reached, input string is accepted.

Example 1: Construct a TM for L={0n1n| n>=1}

Q = {q0, q1, q2, q3} where q0 is initial state.


T = {0, 1, X, Y, B} where B represents blank.
∑ = {0, 1}
F = {q3}

Chapter Two: Computational complexity


Compiled by L.N. Page 4
Transition function δ is given in Table as:

Illustration
Let us see how this TM works for 0011. Initially head points to 0 which is underlined and state is
q0 as:

The move will be δ(q0, 0) = (q1, X, R). It means, it will go to state q1, replace 0 by X and head
will move to right as:

The move will be δ(q1, 0) = (q1, 0, R) which means it will remain in same state and without
changing any symbol, it will move to right as:

The move will be δ(q1, 1) = (q2, Y, L) which means it will move to q2 state and changing 1 to Y,
it will move to left as:

Working on it in the same way, the machine will reach state q3 and head will point to B as shown:

Using move δ(q3, B) = halt, it will stop and accepted.


Note:
In non-deterministic TM, there can be more than one possible move for a given state and tape
symbol, but non-deterministic TM does not add any power.
 Every non-deterministic TM can be converted into deterministic TM.

Chapter Two: Computational complexity


Compiled by L.N. Page 5
 In multi-tape TM, there can be more than one tape and corresponding head pointers, but it
does not add any power to TM.
 Every multi-tape TM can be converted into single tape TM.

The transition diagram

Halting Problem in Theory of Computation

The Halting problem – Given a program/algorithm will ever halt or not?

The halting problem is a decision problem about properties of computer programs on a fixed Turing-
complete model of computation, i.e., all programs that can be written in some given programming
language that is general enough to be equivalent to a Turing machine. The problem is to determine,
given a program and an input to the program, whether the program will eventually halt when run
with that input. In this abstract framework, there are no resource limitations on the amount of
memory or time required for the program's execution; it can take arbitrarily long and use an arbitrary
amount of storage space before halting. The question is simply whether the given program will ever
halt on a particular input.

For example, in pseudocode, the program


while (true) continue
does not halt; rather, it goes on forever in an infinite loop. On the other hand, the program
print "Hello, world!"
does halt.

While deciding whether these programs halt is simple, more complex programs prove problematic.
One approach to the problem might be to run the program for some number of steps and check if it
halts. But if the program does not halt, it is unknown whether the program will eventually halt or run
forever. Turing proved no algorithm exists that always correctly decides whether, for a given
arbitrary program and input, the program halts when run with that input. The essence of Turing's
proof is that any such algorithm can be made to contradict itself and therefore cannot be correct.

Chapter Two: Computational complexity


Compiled by L.N. Page 6
So can we have an algorithm that will tell that the given program will halt or not. In terms of TM,
will it terminate when run on some machine with some particular given input string.

The answer is no we cannot design a generalized algorithm which can appropriately say that given a
program will ever halt or not?
The only way is to run the program and check whether it halts or not. We can refrain the halting
problem question in such a way also: Given a program written in some programming
language(c/c++/java) will it ever get into an infinite loop (loop never stops) or will it always
terminate(halt)?
This is an undecidable problem because we cannot have an algorithm which will tell us whether a
given program will halt or not in a generalized way i.e by having specific program/algorithm. In
general we can’t always know that’s why we can’t have a general algorithm. The best possible way
is to run the program and see whether it halts or not. In this way for many programs we can see that
it will sometimes loop and always halt.

Proof by Contradiction –
Problem statement: Can we design a machine which if given a program can find out if that
program will always halt or not halt on a particular input?

Solution: Let us assume that we can design that kind of machine called as HM(P, I) where HM is
the machine/program, P is the program and I is the input. On taking input the both arguments the
machine HM will tell that the program P either halts or not.

If we can design such a program this allows us to write another program we call this program
CM(X) where X is any program(taken as argument) and according to the definition of the program
CM(X) shown in the figure.

In the program CM(X) we call the function HM(X), which we have already defined and to HM() we
pass the arguments (X, X), according to the definition of HM() it can take two arguments i.e one is
program and another is the input. Now in the second program we pass X as a program and X as input
to the function HM().We know that the program HM() gives two output either “Halt” or “Not Halt”.
But in case second program, when HM(X, X) will halt loop body tells to go in loop and when it
doesn’t halt that means loop, it is asked to return.

Chapter Two: Computational complexity


Compiled by L.N. Page 7
Now we take one more situation where the program CM is passed to CM() function as an argument.
Then there would be some impossibility, i.e., a condition arises which is not possible.

It is impossible for the outer function to halt if its code (inner body) is in loop and also it is
impossible for the outer non halting function to halt even after its inner code is halting. So both
conditions result in non halting for the CM machine/program even we had assumed in the beginning
that it would halt. So this is the contradiction and we can say that our assumption was wrong and this
problem, i.e., halting problem is undecidable.
Hence, we proved that the halting problem is undecidable.
Example 2: A single tape TM M has two states q0 and q1, of which q0 is the starting state. The
tape alphabet of M is {0, 1, B} and its input alphabet is {0, 1}. The symbol B is the blank symbol
used to indicate end of an input string. The transition function of M is described in the following
table.

The table is interpreted as illustrated below. The entry (q1, 1, R) in row q0 and column 1 signifies
that if M is in state q0 and reads 1 on the current tape square, then it writes 1 on the same tape
square, moves its tape head one position to the right and transitions to state q1. Which of the
following statements is true about M?

M does not halt on any string in (0 + 1)+


1) M does not halt on any string in (00 + 1) *
2) M halts on all string ending in a 0
3) M halts on all string ending in a 1

Chapter Two: Computational complexity


Compiled by L.N. Page 8
Solution: Let us see whether machine halts on string ‘1’. Initially state will be q0, head will point
to 1 as:

Using δ(q0, 1) = (q1, 1, R), it will move to state q1 and head will move to right as:

Using δ(q1, B) = (q0, B, L), it will move to state q0 and head will move to left as:

It will run in the same way again and again and not halt.
Option D says M halts on all string ending with 1, but it is not halting for 1. So, option D is
incorrect.
Let us see whether machine halts on string ‘0’. Initially state will be q0, head will point to 1 as:

Using δ(q0, 0) = (q1, 1, R), it will move to state q1 and head will move to right as:

Using δ(q1,B)=(q0,B,L), it will move to state q0 and head will move to left as:

It will run in the same way again and again and not halt.
Option C says M halts on all string ending with 0, but it is not halting for 0. So, option C is
incorrect.
Option B says that TM does not halt for any string (00 + 1)*. But NULL string is a part of
(00 + 1)* and TM will halt for NULL string. For NULL string, tape will be,

Using δ(q0, B) = halt, TM will halt. As TM is halting for NULL, this option is also incorrect.
So, option (A) is correct.

Chapter Two: Computational complexity


Compiled by L.N. Page 9
TM for addition
A number is represented in binary format in different finite automata. For example, 5 is represented
as 101. However, in the case of addition using a TM, unary format is followed. In unary format, a
number is represented by either all ones or all zeroes. For example, 5 will be represented by a
sequence of five zeroes or five ones: 5 = 1 1 1 1 1 or 5 = 0 0 0 0 0. Let’s use zeroes for
representation.
For adding 2 numbers using a TM, both these numbers are given as input to the TM separated by a
“c”.
Examples – (2 + 3) will be given as 0 0 c 0 0 0:

Input : 0 0 c 0 0 0 // 2 + 3
Output : 0 0 0 0 0 // 5

Input : 0 0 0 0 c 0 0 0 // 4 + 3
Output : 0 0 0 0 0 0 0 // 7
Approach used
Convert a 0 in the first number in to X and then traverse entire input and convert the first blank
encountered into 0. Then move towards left ignoring all 0’s and “c”. Come the position just next to
X, and repeat the same procedure until the time we get a “c” instead of X on returning. Convert the c
into blank and addition is completed.
Steps –
Step-1: Convert 0 into X and go to step 2. If symbol is “c” then convert it into blank(B), move right
and go to step 6.
Step-2: Keep ignoring 0’s and move towards right. Ignore “c”, move right and go to step 3.
Step-3: Keep ignoring 0’s and move towards right. Convert a blank (B) into 0, move left and go to
step 4.
Step-4: Keep ignoring 0’s and move towards left. Ignore “c”, move left and go to step 3.
Step-5: Keep ignoring 0’s and move towards left. Ignore an X, move right and go to step 1.
Step-6: End.

Chapter Two: Computational complexity


Compiled by L.N. Page 10
TM for subtraction
Problem-1: Draw a TM which subtract two numbers.
Example:

Steps:
 Step-1. If 0 found convert 0 into X and go right then convert all 0’s into 0’s and go right.
 Step-2. Then convert C into C and go right then convert all X into X and go right.
 Step-3. Then convert 0 into X and go left then convert all X into X and go left.
 Step-4. Then convert C into C and go left then convert all 0’s into 0’s and go left then
convert all X into X and go right and repeat the whole process.
 Step-5. Otherwise if C found convert C into C and go right then convert all X into B and go
right then convert 0 into 0 and go left and then stop the machine.

Here, q0 shows the initial state and q1, q2, q3, q4, q5are the transition states and q6 shows the final
state.
And X, 0, C are the variables used for subtraction and R, L shows right and left.

Chapter Two: Computational complexity


Compiled by L.N. Page 11
Problem: Draw a TM which multiply two numbers.

Example:

Steps:
 Step-1. First ignore 0’s, C and go to right & then if B found convert it into C and go to left.
 Step-2. Then ignore 0’s and go left & then convert C into C and go right.
 Step-3. Then convert all X into X and go right if 0 found convert it into X and go to left
otherwise if C found convert it into B and go to right and stop the machine.
 Step-4. If then X found convert it into X and go left then C into C and left then Y into Y and
left.
 Step-5. Then if B found convert it into B and right then if Y into 0 and right or if C into C
and right and go to step 3 and repeat the process otherwise if 0 found after 4th step then
convert it into Y and right then Y into Y and right then C into C and right then 0 into 0 or X
into X and right then C into C and right then 0 into 0 and right then B into 0 and left then 0
into 0 and left then C into C and left then 0 into 0 or X into X and left then C into C and left.
 Step-6. Then repeat the 5th step.

Chapter Two: Computational complexity


Compiled by L.N. Page 12
Here, q0 shows the initial state and q1, q2, ….., q10, q11are the transition states and q12shows the
final state.
And X, Y, 0, C are the variables used for multiplication and R, L shows right and left.

Example 3: Construct a TM for language L = {wwR | w ∈ {0, 1}}

Solution: The language L = {wwR | w ∈ {0, 1}} represents a language where only 2 characters, i.e.,
0 and 1 are employed. The first part of language can be any string of 0 and 1. The second part is the
reverse of the first part. Combining both parts out string will be formed. Any such string which fall
in this category will be accepted by this language. The beginning and end of string is marked by the
B sign.
For example, if first part w = 1 1 0 0 1 then second part wR = 1 0 0 1 1. It is clearly visible that wR is
the reverse of w, so the string 1 1 0 0 1 1 0 0 1 1 is a part of given language.

Examples –
Input : 0 0 1 1 1 1 0 0
Output : Accepted
Input : 1 0 1 0 0 1 0 1
Output : Accepted
Basic Representation –

Assumption: We will replace 0 by Y and 1 by X.


Approach Used –
First check the first symbol, if it’s 0 then replace it by Y and by X if it’s 1. Then go to the end of
string. So the last symbol is same as first. We replace it also by X or Y.
Now again come back to the position next to the symbol replace from the starting and repeat the
same process.
One important thing to note is that since wR is reverse of w of both of them will have equal number
of symbols. Every time replace an nth symbol from beginning of string, replace a corresponding nth
symbol from the end.

Chapter Two: Computational complexity


Compiled by L.N. Page 13
 Step-1:
If symbol is 0 replace it by Y and move right, Go to state Q2
If symbol is 1 replace it by X and move right, Go to state Q1
 Step-2:
If symbol is 0 replace it by 0 and move right, remain on same state
If symbol is 1 replace it by 1 and move right, remain on same state
——————————————————————-
If symbol is X replace it by X and move right, Go to state Q3
If symbol is Y replace it by Y and move right, Go to state Q3
If symbol is $ replace it by $ and move right, Go to state Q3
 Step-3:
If symbol is 1 replace it by X and move left, Go to state Q4
If symbol is 0 replace it by Y and move left, Go to state Q5
 Step-4:
If symbol is 1 replace it by 1 and move left
If symbol is 0 replace it by 0 and move left
Remain on same state
 Step-5:
If symbol is X replace it by X and move right
If symbol is Y replace it by Y and move right
Go to state Q0
 Step-6:
If symbol is X replace it by X and move right
If symbol is Y replace it by Y and move right
Go to state Q6
ELSE
Go to step 1
 Step-7:
If symbol is X replace it by X and move right, Remain on same state
If symbol is Y replace it by Y and move right, Remain on same state
If symbol is $ replace it by $ and move left, STRING IS ACCEPTED, GO TO FINAL
STATE Q7

Chapter Two: Computational complexity


Compiled by L.N. Page 14
Example 4: Construct a TM for language L = {ww | w ∈ {0,1}}
The language L = {ww | w ∈ {0, 1}} tells that every string of 0’s and 1’s which is followed by itself
falls under this language. The logic for solving this problem can be divided into 2 parts:
1. Finding the mid point of the string
After we have found the mid point we match the symbols

Example – Lets understand it with the help of an example. Lets string 1 0 1 1 0 1, so w = 1 0 1 and
string is of form (ww).
The first thing that we do is to find the midpoint. For this, we convert 1 in the beginning into Y and
move right till the end of the string. Here we convert 1 into y.
Now our string would look like Y 0 1 1 0 Y. Now move left till, find a X or Y. When we do so,
convert the 0 or 1 right of it to X or Y respectively and then do the same on the right end. Now our
string would look like Y X 1 1 X Y. Thereafter, convert these 1’s also and finally it would look like
Y X Y Y X Y.
At this point, you have achieved the first objective which was to find the midpoint. Now convert all
X and Y on the left of midpoint into 0 and 1 respectively, so string becomes 1 0 1 Y X Y. Now,
convert the 1 into Y and move right till, find Y in the beginning of the right part of the string and
convert this Y into a blank (denoted by B). Now string looks like Y 0 1 B X Y.
Similarly, apply this on 0 and x followed by 1 and Y. After this string looks like Y X Y B B B. Now
that you have no 0 and 1 and all X and Y on the right part of the string are converted into blanks so
our string will be accepted.

Chapter Two: Computational complexity


Compiled by L.N. Page 15
Assumption: We will replace 0 by X and 1 by Y.
Approach Used
The first thing is to find the midpoint of the string, convert a 0 or 1 from the beginning of the string
into X or Y respectively and a corresponding 0 or 1 into X or Y from the end of the string. After
continuously doing it a point is reached when all 0’s and 1’s have been converted into X and Y
respectively. At this point, you are on the midpoint of the string. So, our first objective is fulfilled.
Now, convert all X’s and Y’s on the left of the midpoint into 0’s and 1’s. At this point the first half
the string is in the form of 0 and 1. The second half of the string is in the form of X and Y.
Now, start from the beginning of the string. If you have a 0 then convert it into X and move right till
reaching the second half, here if we find X then convert it into a blank(B). Then traverse back till
find an X or a Y. We convert the 0 or 1 on the right of it into X or Y respectively and
correspondingly, convert its X or Y in the second half of string into a blank(B).
Keep doing this till you converted all symbols on the left part of the string into X and Y and all
symbols on the right of string into blanks. If any one part is completely converted but still some
symbols in the other half are left unchanged then the string will not be accepted. If you did not find
an X or Y in the second half for a corresponding 0 or 1 respectively in the first half. Then also string
will not be accepted.
Examples:

Input : 1 1 0 0 1 1 0 0
Output : Accepted

Input : 1 0 1 1 1 0 1
Output : Not accepted

 Step-1:
If the symbol is 0 replace it by X and move right
If the symbol is 1 replace it by Y and move right,
Go to state Q1 and step 2
———————————————
If the symbol is X replace it by X and move left or
If the symbol is Y replace it by Y and move left,
Go to state Q4 and step 5

 Step-2:
If the symbol is 0 replace it by 0 and move right, remain on the same state
If the symbol is 1 replace it by 1 and move right, remain on the same state
———————————————

Chapter Two: Computational complexity


Compiled by L.N. Page 16
If the symbol is X replace it by X and move left or
If the symbol is Y replace it by Y and move left or
If the symbol is $ replace it by $ and move left, Go to state Q2 and step 3

 Step-3:
If symbol is 0 replace it by X and move left, or
If symbol is 1 replace it by Y and move left,
Go to state Q3 and step 4

 Step-4:
If the symbol is 0 replace it by 0 and move left, remain on the same state
If the symbol is 1 replace it by 1 and move left, remain on the same state
———————————————
If the symbol is X replace it by X and move right or
If the symbol is Y replace it by Y and move right,
Go to state Q0 and step 1

 Step-5:
If symbol is X replace it by X and move left or
If symbol is Y replace it by Y and move left
Go to state Q4 and step 6

 Step-6:
If symbol is X replace it by 0 and move left, remain on same state
If symbol is Y replace it by 1 and move left, remain on same state
–––––––––—–––––––––—
If symbol is $ replace it by $ and move right
Go to state Q4 and step 7

 Step-7:
If symbol is 0 replace it by X and move right, go to state Q6 and step 8
If symbol is 1 replace it by Y and move right, go to state Q7 and step 9
–––––––––—–––––––––—
If symbol is B replace it by B and move left, STRING ACCEPTED, GO TO FINAL STATE
Q9

 Step-8:
If symbol is 0 replace it by 0 and move right, remain on same state
If symbol is 1 replace it by 1 and move right, remain on same state
If symbol is B replace it by B and move right, remain on same state

Chapter Two: Computational complexity


Compiled by L.N. Page 17
–—––––––––––––––––––
If symbol is X replace it by B and move left
Go to state Q8 and step 10

 Step-9:

If symbol is 0 replace it by 0 and move right, remain on same state


If symbol is 1 replace it by 1 and move right, remain on same state
If symbol is B replace it by B and move right, remain on same state
–—––––––––––––––––––
If symbol is Y replace it by B and move left
Go to state Q8 and step 10

 Step-10:
If symbol is 0 replace it by 0 and move left, remain on same state
If symbol is 1 replace it by 1 and move left, remain on same state
If symbol is B replace it by B and move left, remain on same state
–—––––––––––––––––––
If symbol is Y replace it by Y and move right or
If symbol is X replace it by X and move right
Go to state Q5 and step 7

Chapter Two: Computational complexity


Compiled by L.N. Page 18
Exercise: Construct a TM for
L = {an bm a(n+m) | n, m ≥ 1}

Comparison b/n Finite State Machines and Turing Machines


Difference between Finite Automata and Turing Machine:

Finite Automata Turing Machine

It will recognize not only regular language but also


It recognize the language called regular context free language, context sensitive language and
language. recursively enumerable languages.

In this the input tape is of finite length In this the input tape is of finite length from left but is of
from both left and right side. infinite length from right.

It also contains finite set of tape symbols and a blank


It consists of finite number of states, finite symbol on the tape in addition to finite number of states,
set of input symbols, initial state of finite set of input symbols, initial state of automata and
automata and finite set of transition rules finite set of transition rules for moving from one state to
for moving from one state to another. another.

In this head is able to move in right


direction only. In two way automata, head
is able to move in both directions. In this, head can move in both directions.

Head is only able to read the symbols


from the tape but can not write symbols
on the tape. Head is able to read as well as write symbols on the tape.

It is weak as compare to Turing Machine. It is powerful than Finite Automata.

Designing turing machine is difficult and as well as


Designing finite automata is easier. complex.

The transition function in turing machine can be


represented by :
The transition function in finite automata δ : Q × T → Q × T × {L, R}
where L and R specifies the left and right movement of
can be represented by :
tape head.
δ : Q × Σ* → Q

Exercise: Use the template in the table above to compare PDAs and TMs

Chapter Two: Computational complexity


Compiled by L.N. Page 19

You might also like