Toc 5 TH Unit Notes
Toc 5 TH Unit Notes
Toc 5 TH Unit Notes
Pushdown Automata(PDA)
• Pushdown automata is a way to implement a CFG in the same way we design DFA for a regular
grammar. A DFA can remember a finite amount of information, but a PDA can remember an infinite
amount of information.
• Pushdown automata is simply an NFA augmented with an "external stack memory". The addition of
stack is used to provide a last-in-first-out memory management capability to Pushdown automata.
Pushdown automata can store an unbounded amount of information on the stack. It can access a
limited amount of information on the stack. A PDA can push an element onto the top of the stack
and pop off an element from the top of the stack. To read an element into the stack, the top
elements must be popped off and are lost.
• A PDA is more powerful than FA. Any language which can be acceptable by FA can also be
acceptable by PDA. PDA also accepts a class of language which even cannot be accepted by FA. Thus
PDA is much more superior to FA.
PDA Components:
Input tape: The input tape is divided in many cells or symbols. The input head is read-only and may
only move from left to right, one symbol at a time.
Finite control: The finite control has some pointer which points the current symbol which is to be
read.
Stack: The stack is a structure in which we can push and remove the items from one end only. It has
an infinite size. In PDA, the stack is used to store the items temporarily.
Γ: a stack symbol which can be pushed and popped from the stack
δ: mapping function which is used for moving from current state to next state.
Turnstile Notation:
⊢ sign describes the turnstile notation and represents one move.
For example,
(p, b, T) ⊢ (q, w, α)
In the above example, while taking a transition from state p to q, the input symbol 'b' is consumed,
and the top of the stack 'T' is represented by a new string α.
Acceptance of CFL
Example 1:
Solution: In this language, n number of a's should be followed by 2n number of b's. Hence, we will
apply a very simple logic, and that is if we read single 'a', we will push two a's onto the stack. As
soon as we read 'b' then for every single 'b' only one 'a' should get popped from the stack.
Now when we read b, we will change the state from q0 to q1 and start popping corresponding 'a'.
Hence,
1. δ(q0, b, a) = (q1, ε)
Thus this process of popping 'b' will be repeated unless all the symbols are read. Note that popping
action occurs in state q1 only.
1. δ(q1, b, a) = (q1, ε)
After reading all b's, all the corresponding a's should get popped. Hence when we read ε as input
symbol then there should be nothing in the stack. Hence the move will be:
1. δ(q1, ε, Z) = (q2, ε)
Where
PDA = ({q0, q1, q2}, {a, b}, {a, Z}, δ, q0, Z, {q2})
Now we will simulate this PDA for the input string "aaabbbbbb".
Example 2:
Solution: In this PDA, n number of 0's are followed by any number of 1's followed n number of 0's.
Hence the logic for design of such PDA will be as follows:
Push all 0's onto the stack on encountering first 0's. Then if we read 1, just do nothing. Then read 0,
and on each read of 0, pop one 0 from the stack.
For instance:
This scenario can be written in the ID form as:
Now we will simulate this PDA for the input string "0011100".
1. Acceptance by Final State: The PDA is said to accept its input by the final state if it enters any
final state in zero or more moves after reading the entire input.
Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by the final state can be defined as:
2. Acceptance by Empty Stack: On reading the input string from the initial configuration for some
PDA, the stack of PDA gets empty.
Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by empty stack can be defined as:
• If L = N(P1) for some PDA P1, then there is a PDA P2 such that L = L(P2). That means the language
accepted by empty stack PDA will also be accepted by final state PDA.
• If there is a language L = L (P1) for some PDA P1 then there is a PDA P2 such that L = N(P2). That
means language accepted by final state PDA is also acceptable by empty stack PDA.
Example:
Construct a PDA that accepts the language L over {0, 1} by empty stack which accepts all the string
of 0's and 1's in which a number of 0's are twice of number of 1's.
Solution:
We are going to design the first part i.e. 1 comes before 0's. The logic is that read single 1 and push
two 1's onto the stack. Thereafter on reading two 0's, POP two 1's from the stack. The δ can be
Now, consider the second part i.e. if 0 comes before 1's. The logic is that read first 0, push it onto the
stack and change state from q0 to q1. [Note that state q1 indicates that first 0 is read and still second
0 has yet to read].
Being in q1, if 1 is encountered then POP 0. Being in q1, if 0 is read then simply read that second 0
and move ahead. The δ will be:
The non-deterministic pushdown automata is very much similar to NFA. We will discuss some
CFGs which accepts NPDA.
The CFG which accepts deterministic PDA accepts non-deterministic PDAs as well. Similarly, there
are some CFGs which can be accepted only by NPDA and not by DPDA. Thus NPDA is more
powerful than DPDA.
Example:
Solution:
Suppose the language consists of string L = {aba, aa, bb, bab, bbabb, aabaa, ......]. The string can be
odd palindrome or even palindrome. The logic for constructing PDA is that we will push a symbol
onto the stack till half of the string then we will read each symbol and then perform the pop
operation. We will compare to see whether the symbol which is popped is similar to the symbol
which is read. Whether we reach to end of the input, we expect the stack to be empty.
This PDA is a non-deterministic PDA because finding the mid for the given string and reading the
string from left and matching it with from right (reverse) direction leads to non-deterministic moves.
Here is the ID.
Simulation of abaaba
The first symbol on R.H.S. production must be a terminal symbol. The following steps are used to
obtain PDA from CFG is:
Step 3: The initial symbol of CFG will be the initial symbol in the PDA.
InterConversion
Example 1:
Convert the following grammar to a PDA that accepts the same language.
1. S → 0S1 | A
2. A → 1A0 | S | ε
Solution:
1. S → 0S1 | 1S0 | ε
1. S → 0SX | 1SY | ε
2. X → 1
3. Y → 0
Example 2:
Construct PDA for the given CFG, and test whether 0104 is acceptable by this PDA.
1. S → 0BB
2. B → 0S | 1S | 0
Solution:
Example 3:
1. S → aSb
2. S → a | b | ε
Solution:
If L(A) is a language accepted by a PDA A , it can also be accepted by a DPDA if and only
if there is a single computation from the initial configuration until an accepting one for all strings
belonging to L(A) . If L(A) can be accepted by a PDA it is a context free language and if it
can be accepted by a DPDA it is a deterministic context-free language (DCFL).
Not all context-free languages are deterministic. This makes the DPDA a strictly weaker device than
the PDA.
UNIT VI
Turing Machine
Turing machine was invented in 1936 by Alan Turing. It is an accepting device which accepts
Recursive Enumerable Language generated by type 0 grammar.
The mapping function shows the mapping from states of finite automata and input symbol on the
tape to the next states, external symbols and the direction for moving the tape head. This is known
as a triple or a program for turing machine.
1. (q0, a) → (q1, A, R)
That means in q0 state, if we read symbol 'a' then it will go to state q1, replaced a by X and move
ahead right(R stands for right).
Example:
Solution:
We have already solved this problem by PDA. In PDA, we have a stack to remember the previous
symbol. The main advantage of the Turing machine is we have a tape head which can be moved
forward or backward, and the input tape can be scanned.
The simple logic which we will apply is read out each '0' mark it by A and then move ahead along
with the input tape and find out 1 convert it to B. Now, repeat this process for all a's and b's.
Now we will see how this turing machine work for 0011.
Now, we will see how this turing machine will works for 0011. Initially, state is q0 and head points
to 0 as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A and head
will move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol, remain in the
same state and move to the right as:
The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1 by B and head
will move to left as:
Now move will be δ(q2, 0) = δ(q2, 0, L) which means it will not change any symbol, remain in the
same state and move to left as:
The move will be δ(q2, A) = δ(q0, A, R), it means will go to state q0, replaced A by A and head will
move to the right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A, and head
will move to right as:
The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol, remain in the
same state and move to right as:
The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1 by B and head
will move to left as:
The move δ(q2, B) = (q2, B, L) which means it will not change any symbol, remain in the same state
and move to left as:
Now immediately before B is A that means all the 0?s are market by A. So we will move right to
ensure that no 1 is present. The move will be δ(q2, A) = (q0, A, R) which means it will go to state q0,
will not change any symbol, and move to right as:
The move δ(q0, B) = (q3, B, R) which means it will go to state q3, will not change any symbol, and
move to right as:
The move δ(q3, B) = (q3, B, R) which means it will not change any symbol, remain in the same state
and move to right as:
The move δ(q3, Δ) = (q4, Δ, R) which means it will go to state q4 which is the HALT state and HALT
state is always an accept state for any TM.
The same TM can be represented by Transition Diagram:
The turning machine can be modelled with the help of the following representation.
1. The input tape is having an infinite number of cells, each cell containing one input symbol and
thus the input string can be placed on tape. The empty tape is filled by blank characters.
2. The finite control and the tape head which is responsible for reading the current input symbol.
The tape head can move to left to right.
4. Finite set of symbols called external symbols which are used in building the logic of turing
machine.
Language accepted by Turing machine
The turing machine accepts all the language even though they are recursively enumerable.
Recursive means repeating the same set of rules for any number of times and enumerable means a
list of elements. The TM also accepts the computable functions, such as addition, multiplication,
subtraction, division, power function, and many more.
Example:
Construct a turing machine which accepts the language of aba over ∑ = {a, b}.
Solution:
We will assume that on input tape the string 'aba' is placed like this:
The tape head will read out the sequence up to the Δ characters. If the tape head is readout 'aba'
string then TM will halt after reading Δ.
Now, we will see how this turing machine will work for aba. Initially, state is q0 and head points to
a as:
The move will be δ(q0, a) = δ(q1, A, R) which means it will go to state q1, replaced a by A and head
will move to right as:
The move will be δ(q1, b) = δ(q2, B, R) which means it will go to state q2, replaced b by B and head
will move to right as:
The move will be δ(q2, a) = δ(q3, A, R) which means it will go to state q3, replaced a by A and head
will move to right as:
The move δ(q3, Δ) = (q4, Δ, S) which means it will go to state q4 which is the HALT state and HALT
state is always an accept state for any TM.
States A b Δ
q0 (q1, A, R) – –
q1 – (q2, B, R) –
q2 (q3, A, R) – –
q3 – – (q4, Δ, S)
q4 – – –
Solution:
L = {0n1n2n | n≥1} represents language where we use only 3 character, i.e., 0, 1 and 2. In this, some
number of 0's followed by an equal number of 1's and then followed by an equal number of 2's.
Any type of string which falls in this category will be accepted by this language.
Now, we will see how this Turing machine will work for 001122. Initially, state is q0 and head points
to 0 as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A and head
will move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol, remain in the
same state and move to the right as:
The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B and head
will move to right as:
The move will be δ(q2, 1) = δ(q2, 1, R) which means it will not change any symbol, remain in the
same state and move to right as:
The move will be δ(q2, 2) = δ(q3, C, R) which means it will go to state q3, replaced 2 by C and head
will move to right as:
Now move δ(q3, 2) = δ(q3, 2, L) and δ(q3, C) = δ(q3, C, L) and δ(q3, 1) = δ(q3, 1, L) and δ(q3, B) =
δ(q3, B, L) and δ(q3, 0) = δ(q3, 0, L), and then move δ(q3, A) = δ(q0, A, R), it means will go to state
q0, replaced A by A and head will move to right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A, and head
will move to right as:
The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol, remain in the
same state and move to right as:
The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B and head
will move to right as:
The move will be δ(q2, C) = δ(q2, C, R) which means it will not change any symbol, remain in the
same state and move to right as:
The move will be δ(q2, 2) = δ(q3, C, L) which means it will go to state q3, replaced 2 by C and head
will move to left until we reached A as:
immediately before B is A that means all the 0's are market by A. So we will move right to ensure
that no 1 or 2 is present. The move will be δ(q2, B) = (q4, B, R) which means it will go to state q4,
will not change any symbol, and move to right as:
The move will be (q4, B) = δ(q4, B, R) and (q4, C) = δ(q4, C, R) which means it will not change any
symbol, remain in the same state and move to right as:
The move δ(q4, X) = (q5, X, R) which means it will go to state q5 which is the HALT state and HALT
state is always an accept state for any TM.
Construct a TM machine for checking the palindrome of the string of even length.
Solution:
Firstly we read the first symbol from the left and then we compare it with the first symbol from
right to check whether it is the same.
Again we compare the second symbol from left with the second symbol from right. We repeat this
process for all the symbols. If we found any symbol not matching, we cannot lead the machine to
HALT state.
Suppose the string is ababbabaΔ. The simulation for ababbabaΔ can be shown as follows:
Now, we will see how this Turing machine will work for ababbabaΔ. Initially, state is q0 and head
points to a as:
Example 3:
Construct a TM machine for checking the palindrome of the string of odd length.
Solution:
Firstly we read the first symbol from left and then we compare it with the first symbol from right to
check whether it is the same.
Again we compare the second symbol from left with the second symbol from right. We repeat this
process for all the symbols. If we found any symbol not matching, we lead the machine to HALT
state.
Suppose the string is 00100Δ. The simulation for 00100Δ can be shown as follows:
Now, we will see how this Turing machine will work for 00100Δ. Initially, state is q0 and head points
to 0 as:
Moved right up to Δ
Example 4:
Construct TM for the addition function for the unary number system.
Solution:
The unary number is made up of only one character, i.e. The number 5 can be written in unary
number system as 11111. In this TM, we are going to perform the addition of two unary numbers.
For example
2+3
i.e. 11 + 111 = 11111
If you observe this process of addition, you will find the resemblance with string concatenation
function.
In this case, we simply replace + by 1 and move ahead right for searching end of the string we will
convert last 1 to Δ.
Input: 3+2
Convert 1 to Δ
Thus the tape now consists of the addition of two unary numbers.
Here, we are implementing the function of f(a + b) = c. We assume a and b both are non zero
elements.
Example 5:
Construct a TM for subtraction of two unary numbers f(a-b) = c where a is always greater than b.
Solution: Here we have certain assumptions as the first number is greater than the second one. Let
us assume that a = 3, b = 2, so the input tape will be:
We will move right to - symbol as perform reduction of a number of 1's from the first number. Let
us look at the simulation for understanding the logic:
A recursive language (subset of RE) can be decided by Turing machine which means it will enter
into final state for the strings of language and rejecting state for the strings which are not part of
the language. e.g.; L= {anbncn|n>=1} is recursive because we can construct a turing machine which
will move to final state if the string is of the form anbncn else move to non-final state. So the TM will
always halt in this case. REC languages are also called as Turing decidable languages. The
relationship between RE and REC languages can be shown in Figure 1.
• Union: If L1 and If L2 are two recursive languages, their union L1∪L2 will also be recursive because if
TM halts for L1 and halts for L2, it will also halt for L1∪L2.
• Concatenation: If L1 and If L2 are two recursive languages, their concatenation L1.L2 will also be
recursive. For Example:
• L1= {anbncn|n>=0}
• L2= {dmemfm|m>=0}
• L3= L1.L2
• = {anbncndm emfm|m>=0 and n>=0} is also recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s. L2 says m no. of d’s
followed by m no. of e’s followed by m no. of f’s. Their concatenation first matches no. of
a’s, b’s and c’s and then matches no. of d’s, e’s and f’s. So it can be decided by TM.
• Kleene Closure: If L1is recursive, its kleene closure L1* will also be recursive. For Example:
L1= {anbncn|n>=0}
L1*= { anbncn||n>=0}* is also recursive.
• Intersection and complement: If L1 and If L2 are two recursive languages, their intersection L1 ∩ L2
will also be recursive. For Example:
• L1= {anbncndm|n>=0 and m>=0}
• L2= {anbncndn|n>=0 and m>=0}
• L3=L1 ∩ L2
• = { anbncndn |n>=0} will be recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and then any no. of d’s.
L2 says any no. of a’s followed by n no. of b’s followed by n no. of c’s followed by n no. of
d’s. Their intersection says n no. of a’s followed by n no. of b’s followed by n no. of c’s
followed by n no. of d’s. So it can be decided by turing machine, hence recursive.
Similarly, complementof recursive language L1 which is ∑*-L1, will also be recursive.
Note: As opposed to REC languages, RE languages are not closed under complementon which
means complement of RE language need not be RE.
The Church-Turing thesis states the equivalence between the mathematical concepts of algorithm
or computation and Turing-Machine. It asserts that if some calculation is effectively carried out by
an algorithm, then there exists a Turing machines which will compute that calculation.
The thesis has been wrongly attributed to many controversial claims in philosophy, that although
related are not implied in the original thesis. Some examples are:
• The universe is equivalent to a Turing Machine and non-computable functions are physically
impossible.
• The universe isn’t equivalent to a Turing Machine and incomputable.
• The human mind is a Turing Machine, the human mind and/or consciousness are equivalent to and
can be instantiated by a computer.
• The human mind isn’t a Turing Machine, the human mind and/or consciousness emerge due to the
existence of incomputable process, such as microtubules performing quantum process in the brain.
Counter Machine
Multi-tape Turing Machines have multiple tapes where each tape is accessed with a separate head.
Each head can move independently of the other heads. Initially the input is on tape 1 and others
are blank. At first, the first tape is occupied by the input and the other tapes are kept blank. Next,
the machine reads consecutive symbols under its heads and the TM prints a symbol on each tape
and moves its heads.
A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ, q0, F) where −
Note − Every Multi-tape Turing machine has an equivalent single-tape Turing machine.
Multi-track Turing machines, a specific type of Multi-tape Turing machine, contain multiple tracks
but just one tape head reads and writes on all tracks. Here, a single tape head reads n symbols
from n tracks at one step. It accepts recursively enumerable languages like a normal single-track
single-tape Turing Machine accepts.
A Multi-track Turing machine can be formally described as a 6-tuple (Q, X, ∑, δ, q0, F) where −
δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,....], Left_shift or Right_shift)
Note − For every single-track Turing Machine S, there is an equivalent multi-track Turing Machine
M such that L(S) = L(M).
In a Non-Deterministic Turing Machine, for every state and symbol, there are a group of actions the
TM can have. So, here the transitions are not deterministic. The computation of a non-
deterministic Turing Machine is a tree of configurations that can be reached from the start
configuration.
An input is accepted if there is at least one node of the tree which is an accept configuration,
otherwise it is not accepted. If all branches of the computational tree halt on all inputs, the non-
deterministic Turing Machine is called a Decider and if for some input, all branches are rejected,
the input is also rejected.
A non-deterministic Turing machine can be formally defined as a 6-tuple (Q, X, ∑, δ, q0, B, F) where
−
semi-infinite tape
A Turing Machine with a semi-infinite tape has a left end but no right end. The left end is limited
with an end marker.
It is a two-track tape −
• Upper track − It represents the cells to the right of the initial head position.
• Lower track − It represents the cells to the left of the initial head position in reverse order.
The infinite length input string is initially written on the tape in contiguous tape cells.
The machine starts from the initial state q0 and the head scans from the left end marker ‘End’. In
each step, it reads the symbol on the tape under its head. It writes a new symbol on that tape cell
and then it moves the head either into left or right one tape cell. A transition function determines
the actions to be taken.
It has two special states called accept state and reject state. If at any point of time it enters into
the accepted state, the input is accepted and if it enters into the reject state, the input is rejected
by the TM. In some cases, it continues to run infinitely without being accepted or rejected for some
certain input symbols.
Note − Turing machines with semi-infinite tape are equivalent to standard Turing machines.
A linear bounded automaton is a multi-track non-deterministic Turing machine with a tape of some
bounded finite length.
Here,
Memory information ≤ c × Input information
The computation is restricted to the constant bounded area. The input alphabet contains two
special symbols which serve as left end markers and right end markers which mean the transitions
neither move to the left of the left end marker nor to the right of the right end marker of the tape.
A linear bounded automaton can be defined as an 8-tuple (Q, X, ∑, q0, ML, MR, δ, F) where −
A deterministic linear bounded automaton is always context-sensitive and the linear bounded
automaton with empty language is undecidable..
context-sensitive languages
αAβ→αγβ
where A ∈ N (Non-terminal)
Example
AB → AbBc
A → bcA
B→b