You are on page 1of 23

ATC (18CS54) Module-4

Module 4
Algorithms and Decision Procedures for CFLs: Decidable questions, Un-decidable
questions. Turing Machine: Turing machine model, Representation, Language acceptability
by TM, design of TM, Techniques for TM construction. Variants of Turing Machines (TM),
The model of Linear Bounded automata.
Textbook 1: Ch 14: 14.1, 14.2,
Textbook 2: Ch 9.1 to 9.8
RBT: L1, L2, L3

14.1 The Decidable Questions


Decidable
A problem is said to be Decidable if we can always construct a corresponding algorithm that can answer yes (accept)/
no(reject).
14.1.1 Membership
“Given a language L and a string w, is w in L?”.
For every context-free language L, there exists a PDA M such that M accepts L.
But some PDAs are not guaranteed to halt and decide (i.e., always halts and says yes or no appropriately).
There are two alternative approaches to solving this problem, both of which work:
Use a grammar:
Convert grammar to Chomsky normal form,
Derive the string (explore all finite paths) (Path Length = 2* |w| - 1)
Finds one that derives a particular string w iff such a path exists.

Use a PDA:
Create PDA M that is guaranteed to halt on all inputs and that accepts all strings in L and rejects all strings that are not
in L.

Using a Grammar to Decide


Algorithm for deciding whether a string w is in a language L:

decideCFLusingGrammar(L: CFL, w: string) =


1. If L is specified as a PDA, use PDAtoCFG, presented in the proof of Theorem 12.2, to construct a
grammar G such that L(G) = L(M).
2. If L is specified as a grammar G, simply use G.
3. If w = ε then if SG is nullable (as defined in the description of removeEps in Section 11.7.4) then
accept, otherwise reject.
4. If w ≠ ε then:
4.1. From G, construct G’ such that L(G’) = L(G) – { ε }and G’ is in Chomsky normal form.
4.2. If G derives w, it does so in 2∙|w| - 1 steps. Try all derivations in G of that number of
steps. If one of them derives w, accept. Otherwise reject.

The running time of decideCFLusingGrammar.


The time required to build G’ is constant.
Let n = |w|. Let g be the search-branching factor of G’, defined to be the maximum number of rules that share a left-
hand side.
The number of derivations of length 2n-1 is bounded by g2n–1, and it takes at most 2n-1 steps to check each one.
So the worst-case running time of decideCFLusingGrammar is O(ng2n-1).
Theorem 14.1 Decidability of Context-Free Languages
Theorem:
Given a context-free language L (represented as either a context-free grammar or a PDA) and a string w, there exists
a decision procedure that answers the question, “Is w ε L?”

Proof: The following algorithm, decideCFL, uses decideCFLusingGrammar to answer the question:
decideCFL(L: CFL, w: string) =
1. If decideCFLusingGrammar(L, w) accepts, return True else return False.

Using a PDA to Decide


We take a two-step approach.
 We first show that, for every context-free language L, it is possible to build a PDA that accepts L - { ε } and
that has no ε -transitions.
 Then we show that every PDA with no ε -transitions is guaranteed to halt.

Theorem 14.2 Elimination of 𝛆 -Transitions


Theorem: Given any context-free grammar G = (V, Ʃ, R, S), there exists a PDA M such that L(M) = L(G) - { ε } and
M contains no transitions of the form ((q1, ε, 𝛼), (q2, 𝛽)). In other words, every transition reads exactly one input
character.

Proof: The proof is by a construction that begins by converting G to Greibach normal form. Recall that, in any
grammar in Greibach normal form, all rules are of the form X → a A, where a ∈ Ʃ and A ∈ (V - Ʃ)*.

Algorithm cfgtoPDAtopdown, builds PDA M from any context-free grammar G, that on input w, simulates G
deriving w, starting from S.
M = ({p, q}, Ʃ, V, ∆, p, {q}), where ∆ contains:
1. The start-up transition ((p, ε, ε), (q, S)), which pushes the start symbol onto the stack and goes to
state q.
2. For each rule X → s1s2…sn in R, the transition ((q, ε, X), (q, s1s2…sn)), which replaces X by
s1s2…sn. If n = 0 (i.e., the right-hand side of the rule is ), then the transition ((q, ε, X), (q, ε)).
3. For each character c ∈ Ʃ, the transition ((q, c, c), (q, ε)), which compares an expected character
from the stack against the next input character and continues if they match.

The start-up transition, plus all the transitions generated in step 2, are ε -transitions.
If G is in Greibach normal form. If G contains the rule X → c s2…sn (where c ∈ Ʃ and s2 through sn are elements of
V - Ʃ), it is not necessary to push c onto the stack, only to pop it with a rule from step 3. Instead, we collapse the push
and the pop into a single transition. So we create a transition that can be taken only if the next input character is c. In
that case, the string s2…sn is pushed onto the stack.

Now we need only find a way to get rid of the start-up transition, whose job is to push S onto the stack so that the
derivation process can begin. Since G is in Greibach normal form, any rules with S on the left-hand side must have the
form S → cs2…sn. So instead of reading no input and just pushing S, M will skip pushing S and instead, if the first
input character is c, read it and push the string s2…sn.

Since terminal symbols are no longer pushed onto the stack, we no longer need the transitions created in step 3 of the
original algorithm.

So M = ({p, q}, Ʃ, V, ∆, p, {q}), where ∆ contains:


1. The start-up transitions: For each rule S → cs2…sn, the transition ((p, c, ε), (q, s2…sn)).
2. For each rule X → cs2…sn (c ∈ Ʃ and s2 through sn are elements of V - Ʃ,
the transition ((q, c, X), (q, s2…sn)).
The following algorithm builds the required PDA:
cfgtoPDAnoeps(G: context-free grammar) =
1. Convert G to Greibach normal form, producing G’.
2. From G’ build the PDA M described above.

Theorem 14.3 Halting Behavior of PDAs without ԑ -Transitions


Theorem: Let M be a PDA that contains no transitions of the form ((q1, ԑ, s1), (q2, s2)), i.e., no ԑ -transitions.
Consider the operation of M on input w ∈ Ʃ*. M must halt and either accept or reject w. Let n = |w|. We make three
additional claims:
a) Each individual computation of M must halt within n steps.
b) The total number of computations pursued by M must be less than or equal to bn, where b is the
maximum number of competing transitions from any state in M.
c) The total number of steps that will be executed by all computations of M is bounded by nb n.

Proof:
a) Since each computation of M must consume one character of w at each step and M will halt when
it runs out of input, each computation must halt within n steps.
b) M may split into at most b branches at each step in a computation. The number of steps in a
computation is less than or equal to n. So the total number of computations must be less than or
equal to bn.
c) Since the maximum number of computations is bn and the maximum length of each is n, the
maximum number of steps that can be executed before all computations of M halt is nbn.

Second way to answer the question, “Given a context-free language L and a string w, is w in L?” is to execute the
following algorithm:

decideCFLusingPDA(L: CFL, w: string) =


1. If L is specified as a PDA, use PDAtoCFG, as presented in the proof of Theorem 12.2, to construct a
grammar G such that L(G) = L(M).
2. If L is specified as a grammar G, simply use G.
3. If w = ԑ then if SG is nullable (as defined in the description of removeEps in Section 11.7.4) then accept, otherwise
reject.
4. If w ≠ ε then:
4.1. From G, construct G’ such that L(G’) = L(G) – { ε } and G’ is in Greibach normal form.
4.2. From G’ construct, using cfgtoPDAnoeps, the algorithm described in the proof of
Theorem 14.2, a PDA M’ such that L(M’) = L(G’) and M’ has no ε-transitions.
4.3. By Theorem 14.3, all paths of M’ are guaranteed to halt within a finite number of steps.
So run M’ on w. Accept if M’ accepts and reject otherwise.

14.1.2 Emptiness and Finiteness


Theorem 14.4 Decidability of Emptiness and Finiteness
Theorem: Given a context-free language L, there exists a decision procedure that answers each of the following
questions:
1. Given a context-free language L, is L = ԑ?
2. Given a context-free language L, is L infinite?

Since we have proven that there exists a grammar that generates L iff there exists a PDA that accepts it, these
questions will have the same answers whether we ask them about grammars or about PDAs.

Proof:
(1) Let G = (V, Ʃ, R, S) be a context-free grammar that generates L. L(G) = ∅ iff S is unproductive (i.e., not able to
generate any terminal strings). The following algorithm exploits the procedure removeunproductive, defined in
Section 11.4, to remove all unproductive nonterminals from G. It answers the question, “Given a context-free
language L, is L = ∅?”.
decideCFLempty(G: context-free grammar) =
1. Let G’ = removeunproductive(G).
2. If S is not present in G’ then return True else return False.

Proof:
14.2 The Undecidable Questions
There exists no decision procedure for many other questions
Given a context free language L, is L = *?
Given a context free language L, is the complement of L context-free?
Given a context free language L, is L regular?
Given a context free language L1 and L2,, is L1 = L2?
Given a context free language L1 and L2, is L1 L2?
Given a context free language L1 and L2, is L1 L2 = ?
Given a context free language L, is L inherently ambiguous?
Given a context free grammar G, is G ambiguous?

TURING MACHINE
The Turing machine provides an ideal theoretical model of a computer. Turing machines are useful
in several ways:
• Turing machines are also used for determining the undecidability of certain languages and
• As an automaton, the Turing machine is the most general model, It accepts type-0
languages.
• It can also be used for computing functions. It turns out to be a mathematical model of
partial recursive functions.
• Measuring the space and time complexity of problems.
Turing assumed that while computing, a person writes symbols on a one-dimensional paper (instead
of a two dimensional paper as is usually done) which can be viewed as a tape divided into cells. In
Turing machine 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 right of the present cell.

Turing machine model

• Each cel can store only one symbol.


• The input to and the output from the finite state automaton are affected by the R/W head which can
examine one cell at a time.
In one move, the machine examines the present symbol under the R/W head on the tape and the
present state of an automaton to determine:
(i) A new symbol to be written on the tape in the cell under the R/W head,
(ii) A motion of the R/W head along the tape: either the head moves one cell left (L),or one
cell right (R).
(iii) The next state of the automaton, and
(iv) Whether to halt or not.
Definition:
Turing machine M is a 7-tuple, namely (Q, Σ, 𝚪, , q0, b, F), where
1. Q is a finite nonempty set of states.
2. 𝚪 is a finite nonempty set of tape symbols,
3. b∈ 𝚪 is the blank.
4. Σ is a nonempty set of input symbols and is a subset o f 𝚪 and b∉Σ.
5. is the transition function mapping (q,x) onto (q',y,D) where D denotes the direction of
movement of R/W head; D=L orR according as the movement is to the left or right.
6. q0∈ Q is the initial state, and
7. F⊆Q is the set of final states.
Notes:
(1) The acceptability of a string is decided by the reachability from the initial state to some final state.
(2) may not be defined for some elements of QX 𝚪.

REPRESENTATION OF TURINGMACHINES
We can describe a Turing machine employing
(i) Instantaneous descriptions using move-relations.
(ii) Transition table, and
(iii) Transition diagram (Transition graph).
REPRESENTATION BY INSTANTANEOUS DESCRIPTIONS
Definition: An ID of a Turing machine M is a string 𝛼𝛽𝛾, where 𝛽 is the present state of M, the
entire input string is split as 𝛼𝛾, the first symbol of 𝛾 is the current symbol a under the R/W head and
𝛾 has all the subsequent symbols of the input string, and the string 𝛼 is the substring of the input
string formed by all the symbols to the left of a.
EXAMPLE: A snapshot of Turing machine is shown in below Fig. Obtain the instantaneous
description.

The present symbol under the R/W


head is a1. The present state is q3. So a1 is written to the right of q3 The nonblank symbols to the left
of al form the string a4a1a2a1a2a2, which is written to the left of q3. The sequence of nonblank
symbols to the right of a1 is a4a2. Thus the ID is as given in below Fig.
Notes: (1) For constructing the ID, we simply insert the current state in the input string to the left of
the symbol under the R/W head.
(2) We observe that the blank symbol may occur as part of the left or right substring.

REPRESENTATION BY TRANSITION TABLE

We give the definition of in the form of a table called the transition table If (q, a)=(𝛾,𝛼,𝛽). We write
𝛼𝛽𝛾 under the 𝛼-column and in the q-row. So if we get 𝛼𝛽𝛾 in the table, it means that 𝛼 is written in
the current cell, 𝛽 gives the movement of the head (L or R) and 𝛾 denotes the new state into which
the Turing machine enters.
EXAMPLE:
Consider, for example, a Turing machine with five states q1,...,q5 where q1 is the initial state and q5 is
the (only) final state. The tape symbols are 0,1and b. The transition table given below describes :

REPRESENTATION BY TRANSITION DIAGRAM (TD)


The states are represented by vertices. Directed edges are used to represent transition of
states. The labels are triples of the form (𝛼,𝛽,𝛾)where 𝛼,𝛽∈𝚪and𝛾∈{L,R}.When there is a directed
edge from qi to qj with label (𝛼,𝛽,𝛾),it means that (qi,𝛼)=(qj,𝛽,𝛾).
EXAMPLE:
LANGUAGE ACCEPTABILITY BY TURING MACHINES
Let us consider the Turing machine M=(Q,Σ,𝚪,,q0,b,F). A string w in Σ* is said to be
accepted by M, if q0w 𝛼1p𝛼2 for some P∈F and 𝛼1,𝛼2∈𝚪*.
EXAMPLE: Consider the Turing machine M described by the table below

IDs for the strings (a) 011 (b)0011 (c)001

As (q5,1) is not defined, M halts; so the input string 011 is not accepted

M halts. As q6 is an accepting state, the input string 0011is accepted byM.


M halts. As q2 is not an accepting state,001 is not accepted by M.

DESIGN OF TURING MACHINES


Basic guidelines for designing a Turing machine:
1. The fundamental objective in scanning a symbol by the R/W head is to know what to do in
the future. The machine must remember the past symbols scanned. The Turing machine can
remember this by going to the next unique state.
2. The number of states must be minimized. This can be achieved by changing the states only
when there is a change in the written symbol or when there is a change in the movement of the R/W
head.
EXAMPLE 1
Design aTuring machine to recognize all strings consisting of an even number of 1's.
Solution:
The construction is made by defining moves in the following manner:
(a) ql is the initial state. M enters the state q2 on scanning 1 and writes b.
(b) If M is in state q2 and scans 1, it enters ql and writes b.
(c) ql is the only accepting state.
Symbolically M= ({ql,q2},{1,b},{1,b},,q,b,{ql}), Where is defined by ,
EXAMPLE 2: Design a TM that accepts {0n1n| n≥ 0}
Solution: We require the following moves:
(a) If the leftmost symbol in the given input string w is 0, replace it by x and move right till we
encounter a leftmost 1in w. Change it to y and move backwards.
(b) Repeat (a) with the leftmost 0. If we move back and forth and no 0 or 1 remains. Move to a final
state.
(c) For strings not in the form 0n1n, the resulting state has to be non-final.
we construct a TM M as follows:M = (Q, Σ,𝚪, , q0,b, F)
Q = {q0,q1,q2,q3,qf}
F = {qf}
Σ = { 0,1}
𝚪= { 0,1,x,y,b}

Computation sequence of 0011:

q4 is final state, hence 0011 is accepted by M.


TECHNIQUES FOR TM CONSTRUCTION
1. TURING MACHINE WITH STATIONARY HEAD
Suppose, we want to include the option that the head can continue to be in the same cell for
some input symbol. Then we define (q,a) as (q',y,S).This means that the TM, on reading the input
symbol a, changes the state to q' and writes y in the current cell in place of a and continues to remain
in the same cell. In this model (q, a) =(q', y, D) where D = L, R or S.
2. STORAGE IN THE STATE
We can use a state to store a symbol as well. So the state becomes a pair(q,a) where q is the
state and a is the tape symbol stored in (q, a). So the new set of states becomes Qx𝚪.
EXAMPLE: Construct a TM that accepts the language 0 1* + 1 0*.
We have to construct a TM that remembers the first symbol and checks that it does not
appear afterwards in the input string.
So we require two states, q0, q1. The tape symbols are 0,1 and b. So the TM, having the 'storage
facility in state‘, is M=({q0,q1}X{0,1,b},{0,1},{0,1,b},,[q0,b],[q1,b]})
We describe by its implementation description.
1. In the initial state, M is in q0 and has b in its data portion. On seeing the first symbol of the input
sting w, M moves right, enters the state q1 and the first symbol, say a, it has seen.
2. M is now in [q1,a].
(i) If its next symbol is b, M enters [q1,b], an accepting state.
(ii) If the next symbol is a, M halts without reaching the final state (i.e. is not defined).
(iii) If the next symbol is ā, (ā=0 if a=1 and ā=1 if a=0), M moves right without changing
state.
3. Step2 is repeated until M reaches [q1,b] or halts ( is not defined for an input symbol in w).
3. MULTIPLE TRACK TURING MACHINE
In a multiple track TM, a single tape is assumed to be divided into several tracks. Now the
tape alphabet is required to consist of k-tuples of tape symbols, k being the number of tracks. In the
case of the standard Turing machine, tape symbols are elements of r; in the case of TM with multiple
tracks, it is 𝚪k.
4. SUBROUTINES
First a TM program for the subroutine is written. This will have an initial state and a 'return'
state. After reaching the return state, there is a temporary halt for using a subroutine, new states are
introduced. When there is a need for calling the subroutine, moves are effected to enter the initial
state for the subroutine. When the return state of the subroutine is reached, return to the main
program of TM.
EXAMPLE: Design a TM which can multiply two positive integers.
Solution: The input (m,n), m,n being given, the positive integers represented by 0 m10n. M starts
with 0m10n in its tape. At the end of the computation, 0mn (mn in unary representation) surrounded by
b's is obtained as the output.
The major steps in the construction are as follows:
1. 0m10n1 is placed on the tape (the output will be written after the rightmost 1).
2. The leftmost 0 is erased.
3. A block of n 0's is copied onto the right end.
4. Steps 2 and 3 are repeated m times and 10m10mn is obtained on the tape.
5. The prefix 10m1of 10m10mn is erased, leaving the product 0mn as the output.
For every 0 in 0m, 0n is added onto the right end. This requires repetition of step3. We define a
subroutine called COPY for step3. For the subroutine COPY the initial state is q1 and the final state
is q5 is given by the transition table as below:

The Turing machine M has the initial state q0. The initial ID for M is q00m10n. On seeing 0,the
following moves take place

q1 is the initial state of COPY. The following moves take place for M1:

After exhausting 0s, q1 encounters 1. M1 moves to state q4. All 2's are converted back to 0's
and M1 halts in q5. The TM M picks up the computation by starting from q 5 The q0 and q6 are the
states of M. Additional states are created to check whether reach 0 in 0m gives rise to 0m at the end of
the rightmost 1 in the input string. Once this is over, M erases 10n1 and finds 0mn in the input tape.
M can be defined by M=({q0,q1,....q12}{0,1},{0,,2,b},,q0,b,{q12}) where is defined by table given
below:
9.7 VARIANTS OF TURING MACHINES

A multitape TM has a
Q: finite set of states
q0: an initial state,
F ⊆ Q: the set of final states,
Ʃ ⊆ Γ* and b ∉ Ʃ
δ transition function, Q x Γk in to Q x Γk x {L,R,S}k

There are k tapes, each divided into cells. The first tape holds the input string w. Initially, all the
other tapes hold the blank symbol.
Initially the head of the first tape (input tape) is at the left end of the input w. All the other heads
can be placed at any cell initially.
A move depends on the current state and k tape symbols under k tape heads.
In a typical move:
(i) M enters a new state.
(ii) On each tape. a new symbol is written in the cell under the head.
(iii) Each tape head moves to the left or right or remains stationary.
The heads move independently.

The initial ID has the initial state q0, the input string w in the first tape (input tape),
empty strings of b's in the remaining k - 1 tapes.
An accepting ID has a final state and some strings in each of the k tapes.
Theorem 9.1 Every language accepted by a multitape TM is acceptable by some single-tape TM (that
is, the standard TM).

Proof Suppose a language L is accepted by a k-tape TM M.


We simulate M with a single-tape TM with 2k tracks.
The second. fourth, ..., (2k)th tracks hold the contents of the k-tapes.
The first. third, ... , (2k - l)th tracks hold a head marker (a symbol say X) to indicate the position of the
respective tape head.

Initially the contents of tapes 1 and 2 of M are stored in the second and fourth tracks of M1.
The headmarkers of the first and third tracks are at the cells containing the first symbol.

To simulate a move of M, the 2k-track TM M1 has to visit the two headmarkers and store the scanned
symbols in its control.
Keeping track of the headmarkers visited and those to be visited is achieved by keeping a count and
storing it in the finite control of M1

After visiting both head markers, M1 knows the tape symbols being scanned by the two heads of M.

Now M1 will revisits each of the headmarkers:


(i) It changes the tape symbol in the corresponding track of M1 based on the information regarding the
move of M.
(ii) It moves the headmarkers to the left or right.
(iii) M1 changes the state of M in its control.

This is the simulation of a single move of M.

M1 accepts a string w if the new state of M, as recorded in its control at the end of the processing of w.
is a final state of M.

Definition 9.3 Let M be a TM and w an input string.


The running time of M on input w is the number of steps that M takes before halting.
If M does not halt on an input string w, then the running time of M on 'v is infinite.

Definition 9.4 The time complexity of TM M is the function T(n), n being the input size, where T(n) is
defined as the maximum of the running time of M over all inputs w of size n.

Theorem 9.2 If M1 is the single-tape TM simulating multitape TM M, then the time taken by M1 to
simulate n moves of M is O(n2).
9.7.2 Nondeterministic Turing Machines
Definition 9.5 A nondeterministic Turing machine is a 7-tuple (Q, Ʃ,Γ, δ, q0, b, F) where
1. Q is a finite nonempty set of states
2. Ʃ is a finite nonempty set of tape symbols
3. b ∈ Γ is called the blank symbol
4. Ʃ is a nonempty subset of Γ called the set of input symbols. We assume that b ∉ Ʃ.
5. q0 is the initial state
6. F ⊆ Q is the set of final states
7. δ is a partial function from Q x Γ into the power set of Q x Γ x {L,R}

Definition 9.6 w ∈ Ʃ * is accepted by a nondeterministic TM M if q0w |-* xqfy for some final state qf.

Theorem 9.3 If M is a nondeterministic TM, there is a deterministic TM M1 such that T(M) = T(M1)
Proof:
We construct M1 as a multitape TM.

Each symbol in the input string leads to a change in ID. M1 should be able to reach all IDs and stop
when an ID containing a final state is reached.

So the first tape is used to store IDs of M as a sequence and also the state of M. These IDs are
separated by the symbol * (included as a tape symbol). The current ID is known by marking an x
along with the ID-separator * (The symbol * marked with x is a new tape symbol.)
All IDs to the left of the current one have been explored already and so can be ignored subsequently.
Note that the current ID is decided by the current input symbol of w.

1. M1 examines the state and the scanned symbol of the current ID. Using the knowledge of
moves of M stored in the finite control of M1, it checks whether the state in the current ID is
an accepting state of M. In this case M1 accepts and stops simulating M.
2. If the state q say in the current ID xqay, is not an accepting state of M1 and δ(q, a) has k
triples, M1 copies the ID xqay in the second tape and makes k copies of this ID at the end of
the sequence of IDs in tape 2.
3. M1 modifies these k IDs in tape 2 according to the k choices given by δ(q, a).
4. M1 returns to the marked current ID. erases the mark x and marks the next ID- separator *
with x. Then M1 goes back to step 1.

9.8 The Model of Linear Bounded Automaton


Linear bounded automaton (LBA)
(a) Accepts the set of context-sensitive languages
(b) The infinite storage is restricted in size
(c) Linear function is used to restrict (to bound) the length of the tape.

A linear bounded automaton is a non deterministic Turing machine which has a single tape whose
length is not infinite but bounded by a linear function of the length of the input string.

Definition
M = (Q, Ʃ, Γ, δ, q0, b, ¢ $, F)
¢ is called the left-end marker which is entered in the leftmost cell of the input tape and prevents the
R/W head from getting off the left end of the tape.
$ is called the right-end marker which is entered in the rightmost cell of the input tape and prevents the
R/W head from getting off the right end of the tape.

The R/W head should not print any other symbol over both the end markers.

Let input string w with |w| = n - 2.


The input string w can be recognized by an LBA if it can also be recognized by a Turing machine
using no more than kn cells of input tape, where k is a constant specified in the description of LBA
(between 1- n).
The input string is enclosed within the end markers ¢ and $.

There are two tapes: input tape, and working tape.


Input tape the head never prints and never moves to the left.
Working tape the head can modify the contents in any way, without any restriction.

ID of an LBA is denoted by (q, w. k), where q ∈ Q, w ∈ Γ and k is integer between 1 and n.

The transition of IDs is similar except that k changes to k - 1 if the R/W head moves to the left and to k
+ 1 if the head moves to the right.

The language accepted by LBA is defined as the set


{ w ∈ (Ʃ - {¢, $})* | (q0, ¢w$, 1) |-* (q, 𝛼, i) for some q ∈ F and for some integer i between 1 and n},

9.8.1 Relation Between LBA and Context-Sensitive Languages


If L is a context-sensitive language(excluding null strings), then L is accepted by a linear bounded
automaton. The converse is also true.

ADDITIONAL PROBLEMS
1. Design a Turing machine to obtain complement of a binary number.
IDEA OF CONSTRUCTION:
1) If symbol is 0 change it to 1, move read write head to RIGHT
2) If symbol is 1 change it to 0, move read write head to RIGHT
3) Symbol is b (blank) don’t change, move read write head to RIGHT,
and HALT.The construction is made by defining moves in the following
manner:
(a) ql is the initial state. On scanning 1, no change in state and write 0 and move head to RIGHT.
(c) If M is in state q1and scans blank, it enters q2 and writes b move to right.
(d) q2 is the only accepting state.
Symbolically, M=({ql,q2},{1,0,b},{1,0,b},,ql,b,{q2}) Where is defined by:
The computation sequence of 1010:

2. Design a TM that converts binary number into its 2’s complement representation.
IDEA OF CONSTRUCTION:
 Read input from left to right until right end blank is scanned.
 Begin scan from right to left keep symbols as it is until 1 found on input file.
 If 1 found on input file, move head to left one cell without changing input.
 Now until left end blank is scanned, change al 1’s to 0 and 0’s to 1.
We require the following moves:
(a) Let q1 be initial state, until blank is scanned, move head to RIGHT without changing
anything. On scanning blank, move head to RIGHT change state to q 2 without changing the
content of input.
(b) If q2 is the state, until 1 is scanned, move head to LEFT without changing anything. On
reading 1, change state to q3, move head to LEFT without changing input.
(c) If q3 is the state, until blank is scanned, move head to LEFT, if symbol is 0 change to 1,
otherwise if symbol is 1 change to 0.On finding blank change state to q4, move head to LEFT
without Changing input.
(d) q4 is the only accepting state.
We construct a TM M as follows:
M = (Q, Σ,, , q0,b, F)
Q = {q1,q2,q3,q4}
F = {q4 }
Σ = {0,1}
𝚪= {0,1,b}

3.Design a TM that add two integers


IDEA OF CONSTRUCTION:
 Read input from LEFT to RIGHT until blank (separator of two numbers) is found.
 Continue LEFT to RIGHT until blank (end of second number) is found.
 Change separator b to 1 move head to RIGHT.
 move header to Left ( to point rightmost 1)
 Change 1 to b and move right, Halt.

We require the following moves:


(a) In q1 TM skips1’s until it reads b (separator),changes to1and goes to q1
(b) In q2 TM skips1’s until it reads b (end of input), turns left and goes to q3
(c) In q3, TM reads 1 and changes to b go to q4.
(d) q4 is the final state, TM halts.
we construct a TM M as follows: M = (Q, Σ, 𝚪, , q0,b, F)
Q = {q1,q2,q3,q4}
F = {q4}
Σ = { b,1}
𝚪= {1,b}

4. Design a TM that accepts the set of all palindromes over {0,1}*


IDEA OF CONSTRUCTION:
 If it is 0 and changes to X, similarly if it is 1, it is changed to Y, and moves right until it finds
blank.
 Starting at the left end it checks the first symbol of the input,
 Nowmovesonestepleftandcheckwhetherthesymbolreadmatchesthemostrecentlychanged.Ifsoiti
salsochangedcorrespondingly.
 Now machine moves back left until it finds 0 or 1.
 This process is continued by moving left and right alternately until al 0’s and 1’s have been
matched.
We require the following moves:
1. If state is q0and it scans 0.
 Then go to state q1 and change the 0 to an X,
 move RIGHT over al 0’s and 1’s, until it finds either X or Y or B
 Now move one step left and change state to q3
 It verifies that the symbol read is 0, and changes the 0 to X and goes to state q5.
2. If state is q0 and it scans 1

 Then go to state q2 and change the 1 to an Y,


 Move RIGHT over al 0’s and 1’s, until it finds either X or Y or B
o Now move one step left and change state to q4
o It verifies that the symbol read is 1, and changes the 1 to Y and goes to state q5.
3. If state is q5
 Move LEFT over al 0’s and 1’s, until it finds either X or Y.
 Now move one step RIGHT and change state to q0.
 Now at q0 there are two cases:
1. If 0’s and 1’s are found on input , it repeats the matching cycle just described.
2. If X’s and Y’s are found on input, then it changes all the 0’s to X and all the 1’s to Y’s.
The input was a palindrome of even length, Thus, state changed to q6.
4. If state is q3 or q4
If X’s and Y’s are found on input, it concludes that: The input was a palindrome of odd
length, thus, state changed to q6.
We construct a TM M as follows:
M = (Q, Σ, 𝚪, , q0,b,F)
Q = {q0,q1,q2,q3,q4,q5,q6}
F = {q6}
Σ = { b,1,0}
𝚪 = {X,Y,b}

PRACTICE PROBLEMS
1. Design a Turing machine to replace al a’s with X and al b’s with Y.
2. Design a Turing machine to accept anbm n>m.
3. Design a Turing machine to accept anbn n<m.
4. Design a Turing machine to accept (0+1)*00(0+1)* .
5. Design a Turing machine to increment a given input.
6. Design a Turing machine to decrement a given input.
7. Design a Turing machine to subtract two unary numbers.
8. Design a Turing machine to multiply two unary numbers.
9. Design a Turing machine to accept a string 0’s followed by a 1.
10. Design a Turing machine to verify if the given binary number is an even number or not.
11. Design a Turing machine to shift the given input by one cell to left.
12. Design a Turing machine to shift the given input to the right by one cell .
13. Design a Turing machine to rotate a given input by one cell.
14. Design a Turing machine to erase the tape.
15. Design a Turing machine to accept anbncn .
16. Design a Turing machine to accept any string of a’s & b’s with equal number of a’s & b’s.
17. Design a Turing machine to accept anb2n.
18. Design a Turing machine to accept anbkcm: where n=m+k.
19. Design a Turing machine to accept anbkcm: where m=n+k.
20. Design a Turing machine to accept anbkcm: where k=m+n.

You might also like