Unacademy TOC
Unacademy TOC
Chapter 2
2.1 FINITE AUTOMATA
Definitions
FINITE AUTOMATA
Finite Finite
automata automata
without with
output output
Input tape
b a b a a a
Head
q0 b q1 a q2 b q3
Finite
a control
memory
Finite Automata
qn a qn–1 q4
17
Chapter 2
Input tape: It consists of many cells where each cell can have only one
symbol. Input tape contains a single string.
Finite control memory: Memory which is having the finite number of states.
Q× ∑ → Q
↓
Next
State
(A,a)
(A, b) A
(B, a) B
(B, b) C
(C, a)
(C, b)
Fig. 2.2
18
Chapter 2
SOLVED EXAMPLES
Q1
Sol: L = {a, aa, aaa, aaaa, ba, bbbba, bababaaaa,……………} = Set of all strings ends
with ‘a’ over ∑ = {a, b}
Q2
Sol: L = {ba, bab, baa, aba, abaa, abab, ………} = Set of all strings containing “ba”
as a substring over ∑ = {a, b}.
How many number of final state require to accept & in minimal finite
automata?
19
Chapter 2
Minimal DFA: When all the states in a DFA are distinguishable, i.e. no two
states in a final DFA are equivalent. The DFA is known as minimal DFA.
SOLVED EXAMPLES
Q1
Transition table:
Q2
Transition table:
Finite Automata
20
Chapter 2
Q3
Sol:
a, aa, aaa, aaaa, ................
ab, aab
L = aba
abb
DFA:
a, b
q0 a q1
Dead
q2
State
a,b
y If any string starts with ‘a’, then it will be accepted by the DFA.
Let’s consider an example.
String w = aab
d (q0, a) = q1
d (q1, a) = q1
d (q1, b) = q1 (accepted by DFA)
y But if the string starts with ‘b’, it directly goes to the dead state and get
rejected by the DFA.
Let’s consider an example.
String w = ba
d (q0, b) = q2
d (q2, a) = q2 (Dead state)
Thus, string ba is rejected (not accepted by DFA).
Dead state: It is a rejecting state i.e a non final state from which there is
no path to the final state.
Finite Automata
Once we reach to dead state, there is no way to reach the final state.
21
Chapter 2
Transition table:
Q4
a b
q0 q1 q2
b a
q3
a,b
Transition table:
Q5
a b
Finite Automata
q0 q1 q2
22
Chapter 2
Q6
q0 a q1
Q7
q0 b q1 a q2
b
a
1 (GATE 2009)
1 0
0 0
1
The above DFA accepts the set of all strings over {0, 1} that
1) Begin either with 0 or 1 2) End with 0
3) End with 00 4) Contain the substring 00
Sol: 3)
Finite Automata
23
Chapter 2
Q8
a b
a b q2
q0 q1
a
b
q3
a,b
Q9
a q1 b
q0 q2
a
b
b q3
b a
q4
a
Finite Automata
24
Chapter 2
Q10
a b
q0 a b
q1 q2
b a
b q3
a b
q4
Q11
b a, b
a a a q3 a q4
q0 q1 q2
b
b
b
Finite Automata
25
Chapter 2
Q12
a q1 a q2 a q3
q0
b
a b
b a b
q4 q5
b
Q13
q0 a b q2
q1
b a
q3
Q14
Finite Automata
26
Chapter 2
Sol: L = {aaaab, baaab, …………………}
DFA:
a, b
q6
a, b
Q15
Sol:
b
b a
a a b
q0 q1 q2 q3
Q16
i) L
ii) L
iii) L
a, b a, b a, b
q0 q1 q2 q3
Finite Automata
27
Chapter 2
a, b a, b
q0 q1 q2
q0 a, b q1 a, b q2 a, b q3
Note:
Q17
L
L
L
|w| mod 2 = 0
L = { ∈ , aa, bb, ab, …………..}
28
Chapter 2
DFA:
a, b
q0 q1
a, b
a, b
q0 q1
a, b
iii) { }
All strings whose length is divisible by 3 over ∑ = a,b
|w| mod 3 = 0
q0 a, b q1 a, b
q2
a, b
Note:
Q18
Finite Automata
29
Chapter 2
b b b a, b
a a a
q0 q1 q2 q3
a a
q0 q1 q2
a q1 a q2 a
q0 q3
Note:
d
A
A
Finite Automata
30
Chapter 2
Grey Matter Alert!
{ }
Number of states in minimal DFA which accepts all the strings over ∑ = a,b such
that:
a)
Number of a’s is ‘atleast m’ and number of b’s is ‘atleast n’ = (m + 1)(n + 1)
b)
Number of a’s is ‘exactly m’ and number of b’s is ‘exactly n’ = (m + 1) (n + 1) + 1
(because of trap state, we require one more state).
c)
Number of a’s is ‘atmost m’ and number of b’s is ‘atmost n’ = (m + 1)(n+1) + 1
L= { { }
w 1aw2 | w 1 , w2 ∈ a,b *,| w 1 |= }
2,| w2 | ≥ 3 is ________
SOLVED EXAMPLES
Q19
Sol:
= L {a bn m
| n,m ≥ 1}
{ }
= ab, aab, abb, aabb, ..................
DFA:
a b
a b
b
a
Finite Automata
a, b
31
Chapter 2
Q20
Sol:
= L {a bn m
| n,m ≥ 0 }
{
= ∈, a,b, ab, aa,bb, ................... }
DFA:
a b a, b
b a
Q21
Sol:
=L {a b c | n,m,l ≥ 1}
n m l
{
= abc, aabc, abbc, abcc, .................... }
a b c
a b c
c a
b,c a,b
a,b,c
Q22
Sol: i) L= {a n
n ≥ 0,n ≠ 3 }
{
= ∈, a, aa, aaaa, ................. }
Finite Automata
32
Chapter 2
a
a a a a
Not
accepting
3a’s
ii) L= {a n
n ≥ 0,n ≠ 2,n ≠ 4 }
{
= ∈, a, aaa, aaaaa, ................. }
a
a a a a a
Not Not
accepting accepting
2a’s 4a’s
Construct the minimal DFA’s for the language L = (ab | n20) u (b’a | n21}
SOLVED EXAMPLES
Q1
q0 1 q1
33
Chapter 2
Q2
0
Sol: Divisible by 3, so remainders are 1
2
DFA:
0 1
1 0
q0 q1 q2
1 0
Transition table:
Q3
0
Sol: Divisible by 4, so remainders are 1
2
3
Finite Automata
Transition table:
34
Chapter 2
Here, we can merge q1 and q3 states as one state.
DFA:
0 1
1 0
q0 q13 q2
1
Q4
Finite Automata
35
Chapter 2
Q5
Note:
Finite Automata
36
Chapter 2
SOLVED EXAMPLES
Q1
Input = {0, 1, 2}
Transition table:
0
0 2 0 2
1 1
q0 q1 q2 q3
1
2 1
2
0
Operations on DFA:
Union:
DFA which accepts all strings starting and ending with different symbols
{ }
over ∑ = a,b .
37
Chapter 2
a b
a b
q0 q1 q2
b a
q3
a,b
b a
q0 q1 q2
b
a
q3
a,b
q0 a q1 b q2
b a
b q3
a b
q4
Finite Automata
Concatenation:
38
Chapter 2
{ }
DFA that accepts all strings over ∑ = a,b which starts with a and ends
with b.
L1 = {Starting with a}
= {a, aa, ab, aab, ……………………}
a, b
q0 a q1
a, b
L2 = {Ending with b}
= {b, ab, bb, aab, ……………………}
a
b
q1 b q2
a b
a b
q0 q1 q2
a
b
a, b
Finite Automata
Cross product:
39
Chapter 2
SOLVED EXAMPLES
Q1
A B
C D
Cross product:
{A, B} × {C, D} = {AC, BC, AD, BD}
Where final state = {AC} because A and C are both final states in
respective DFA for L1 and L2.
Initial State = {AC} because A and C are both initial states in
respective DFA for L1 and L2.
AC BC
a
b b b b
a
AD BD
a
Finite Automata
40
Chapter 2
Q2
a a
b b b b b b
a a
Complementation:
eg 1: L = set of all strings over ∑ = {a, b} of even length
= { ∈, ab, aa, bb, aaaa, ……………………….}
Sol: DFA:
a, b
A B
a, b
L=
2
L=
1
Complement of L 1
A B
Finite Automata
a, b
41
Chapter 2
a
A B
a, b
L=
2
L=
1
Complement of L 1
= Set of all strings over ∑ ={a,b} not starting with ‘a’
= { ∈ , b, ba, …………………..}
DFA for complement of L1:
a, b
a
A B
a, b
Note:
Finite Automata
42
Chapter 2
Previous Years’ Question
{ }
Let L be the language represented by the regular expression ∑ *0011 ∑ * where ∑ = 0, 1
Reversal:
Reversing a language meSol: reverse all strings present in the language.
Steps:
a) Draw the state as it is.
b) Make final state as initial state and initial state as final state.
c) Reverse the edges.
d) Remove all the unreachable state and its transition from initial state.
Note:
DFA for the set of string over ∑ ={a,b} which start with ‘a’.
L1 = {a, aa, ab, aab,……………..}
DFA:
a, b
q0 a
q1
q2
a, b
43
Chapter 2
a, b
q0 a q1
a, b
q2
q0 a q1
a, b
X
Can never reach this state from Non-Deterministic
initial state. Finite Automata (NFA)
Fig 2.3
Q1 Counting DFA:
Number of 2-state DFA with designated initial state that can be constructed
over ∑ = a,b .{ }
Sol: q0 q1
44
Chapter 2
y q0 on ‘a’ can either go to the state q0 or q1. q0 on ‘b’ can either go to the
state q0 or q1.
y Similarly, q1 on ‘a’ can either go to the state q0 or q1. q1 on ‘b’ can either
go to the state q0 or q1.
Total number of ways to construct 2-state DFA with designated initial
{ }
state over ∑ = a,b = 22 * 24 = 26 = 64
Q2 Number of 3-state DFA with designated initial state that can be constructed
{ }
over ∑ = a,b .
Sol: q0 q1
q2
q0 q1 q2 0 final state
q0 q1 q2
q0 q1 q2 1 final
state
q0 q1 q2
q0 q1 q2
2 final
q0 q1 q2
state
q0 q1 q2
Finite Automata
q0 q1 q2 3- final state
45
Chapter 2
Note:
Given: | ∑ |=m
|Q| = number of states = n
y Number of ways, we can construct final states = 2n
Total cells in δ = n × m
=m×n
and each cell can be filled in ‘n ways’
So, Total possibility = nm×n
Q × ∑ → 2Q
= 2n × nm×n
46
Chapter 2
Q3 Number of 2-state DFA’s with a designated initial state accepting φ over
{ }
∑ = a, b
q0 q1
a, b b
a
q0 q1
a, b 4 possibility
a
b
q0 q1
a, b
a, b
q0 q1
47
Chapter 2
a, b a, b
q0 q1
a, b b
q0 a q1
4 possibility
a, b a
q0 b q1
a, b
q0 a, b q1
q0 q1
.
When both q0 and q1 states are final states, then it will accept ∑ * in 16
possible ways.
Finite Automata
48
Chapter 2
Minimization of DFA:
Definitions
Minimization of DFA meSol: trSol:forming a given DFA into an equivalent DFA that has
a minimum number of states.
i) Remove all the unreachable states (i.e. states which are not reachable from initial
state).
ii) Separate all final states in one set and all non-final states in another set.
iii) Two states p and q of a DFA are called Indistinguishable if δ * (p, w) ∈ Final state
⇒ δ * (q, w) ∈Final State
and δ * (p, w) ∉Final State ⇒ δ * (q, w) ∉Final State
for all w ∈ ∑ *
iv) On the other hand, if there exists some string w ∈ ∑ * such that δ * (p, w) ∈Final State
and δ * (q, w) ∉Final State or vice-versa, then the states p and q are said to be
distinguishable by a string ‘w’.
v) Identify distinguishable states and use the logic known as seperating the states.
It meSol: in each step if the two states in a set are distinguishable seperate them.
vi) Stop the algorithm once find no change in partition.
SOLVED EXAMPLES
Q1
Sol:
Finite Automata
49
Chapter 2
{( ) ( )} [0 equivalence class]
π0 = A,B , C
Q2
Finite Automata
50
Chapter 2
Sol:
{ }
π0 =(A), (B, C,D)
π2 =π1
Q3 Finite Automata
51
Chapter 2
Sol:
π0 = (q , q
0 1 2 3, q , q ), (q )
4
(g 1 ) (g2 )
π1 =(q0 , q1 , q2 ), (q3 ), (q4 )
(g 1 ) (g2 ) (g3 )
{
π2 =(q0 , q2 ), (q1 ), (q3 ), (q4 ) }
So, q0 = q2
π3 =π2
Finite Automata
52
Chapter 2
Q4
53
Chapter 2
{
∏2 =(q0 ), (q1 ), (q2 ), (q3 ) } ⇒ q0 ≠ q1
∏3 =∏2
N
= (Q, ∑, δ, q0 ,F )
where δ : Transition function
a
eg: A A
a
B
i.e. state A on seeing input a, goes to more than one state which is A and B.
{ }
Let Q = A,B and ∑ = a,b { }
Finite Automata
Q × ∑ → 2Q
54
Chapter 2
A, a
φ
{A}
A, b
{B}
B, a
{A,B}
B, b
Fig. 2.4
Note:
SOLVED EXAMPLES
Q1
Sol: L = {a, aa, ab, ……………………..}
NFA:
a, b
q0 a q1
Q2
Sol: L = {a, aa, ba, ab, ……………………..}
NFA:
a, b a, b
q0 a q1
Finite Automata
55
Chapter 2
Q3
Sol: L = {a, aa, ba, aba, ……………………..}
NFA:
a, b
q0 a q1
Q4
Sol: L = {ab, aba, abb, ……………………..}
NFA:
a, b
q0 a q1 b q2
Q5
q0 a q1 b q2
Q6
Sol: L = {aabb, aabba, aabbb, ……………………..}
NFA:
a, b
q0 a q1 a q2 b q3 b q4
Finite Automata
56
Chapter 2
Q7
q0 a a q2
q1
Q8
q0 a q1 a q2
a, b
b b
q3
a, b
Q9
a q1 b
q0 q2
b a
q3
Finite Automata
a, b
57
Chapter 2
Q10
l r
a, b q1 a, b q2 a, b q3 a, b q4 b q5
q0
Q11
r l
a a, b a, b q3 a, b q4 a, b q5
q0 q1 q2
Q12
a q1 a q2
q0
Q13
a a
q0 q1 q2
Finite Automata
58
Chapter 2
Q14
Q15
Sol: Length of string is atleast 4 meSol: |w| ³ 4.
a, b a, b a, b a, b
q0 q1 q2 q3 q4
Q16
Note:
If the given NFA accept set of all the strings over ∑ = a,b , where { }
Case I: Length of the string is exactly n
Case II: Length of the string is atleast n
Case III: Length of the string is atmost n
Finite Automata
59
Chapter 2
Q17
Sol: L = {a, b, aaaa, abab, …………………..}
NFA:
a, b a, b
q0 q1 q2
a, b
Draw NFA with 3 states that accepts the language L = {a” In 21}{ba
Imzo,k 20}
Let N be an NFA with n states. Let K be the number of states of minimal DFA which is
equivalent to N. Which of the following is necessarily True? (GATE 2018)
1) K ≥ 2n 2) K ≥ n
3) K ≤ n2 4) K ≤ 2n
Sol: 4)
a a
q1 q2 q3
a
q0
a
a
q4 q5
Finite Automata
60
Chapter 2
2.2 COMPARISON OF DFA AND NFA
Table 2.1
Conversion from NFA to DFA:
Procedure:
Let N = (Q, ∑ , δ , q0, F) → NFA
M = (Q’, ∑ ’, δ ’, q0’, F’) → DFA
i) There is no change in the initial state i.e. q0' = q0
ii) Start the construction of δ ' with initial state and continue it for every
new state which will come under input column.
Terminate this process when no more new state appears in the input
column.
iii) Every set which contains final state of NFA as subset, will be the final
state for corresponding DFA.
Note:
Q1
Sol: { }
L 1 = a, aa, ab, ............
NFA:
Finite Automata
a, b
q0 a q1
61
Chapter 2
q0 a q1
a, b
Q2
Sol:
Finite Automata
62
Chapter 2
DFA diagram:
a a b
b q1 a q0 q1 b q1 q2 b q0q1q2
q0
a
b a b a
q2
Q3
Sol: {
L = aa,ba,bab, aab, ................ }
NFA:
a, b
q0 a, b q1 a q2
63
Chapter 2
DFA diagram: a, b
a, b a q2
q0 q1
a, b
Q4
Sol: {
L = aaaa, aaab,baab,babb, ................}
NFA:
a, b
q0 a q1 a, b q2 a, b q3
Transition table:
64
Chapter 2
a
b a
b a a b
a
b b
Q5
Sol:
Since constructing NFA is easy, first Construct NFA where each string contain
“101” as a substring
NFA:
0, 1 0, 1
q0 1 q1 0 q2 1 q3
Finite Automata
65
Chapter 2
DFA:
0 1 1 0
1 0 1 0 0
A B C D E F
1
0 1
Minimal DFA:
{
∏0 =(A,B, C), (D,E,F) }
∏ 1 ={(A,B), (C), (D,E,F)}
1 0 1
A B C DEF
Now, complement the above DFA to get the minimal DFA that accepts all the
{ }
strings over Σ = 0, 1 where each string “do not contain “101” as a substring.”
0 1 0, 1
Finite Automata
1 0 1
A B C DEF
66
Chapter 2
2.3 EPSILON NON-DETERMINISTIC FINTE AUTOMATA (Î
Î-NFA)
Specification of epsilon NFA:
y ( )
Epsilon- NFA ∈ − NFA is the NFA which contains ∈ - moves/Null moves.
y This automation allows ∈ as possible transition.
y ∈ -NFA is defined as 5-tuple:
(Q, ∑ , δ , q0, F)
Where transition function:
δ: {}
Q × Σ ∪ ∈ → 2Q
q0
∈ ∈
q1 q3
a a
a
q4 a
q2
q5
∈ -closure
Definitions
The ∈ -closure of the state q, is the set that contains q along with all states which can
be reached by only getting any number of ∈ from state q.
Finite Automata
67
Chapter 2
q0
q1 q2
a a
a
q5
q3 a
q2
q4
Procedure:
Let N1 = (Q', S', d', q0', F') is the ∈–NFA.
N2 = (Q, S, d, q0, F) is the equivalent NFA.
i) Initial state:
q0 = q0'
ii) d Construction:
∀i∈Σ
∀q∈Q δ(q, i) Î-closure [d' (Î-closure(q), i)]
=
iii) Final state: Find Î-closure of each state, if it contains any of the final
state of N1, then those state(s) will be the final state(s) in equivalent
NFA N2.
SOLVED EXAMPLES
Q1
Finite Automata
68
Chapter 2
Sol: ∈–closure (q0) = {q0, q1}
∈–closure (q1) = {q1}
∈* 0 ∈*
q0 q0 q0 q0
0 q1
q1 φ
∈* 1
q0 q0 φ
1 ∈*
q1 q1 q1
∈* 0
q1 q1 φ
∈* 1 ∈*
q1 q1 q1 q1
∈ -NFA to NFA
Transition table:
NFA:
0 1
0, 1
q0 q1
Note:
Finite Automata
69
Chapter 2
Q2
A
∈* 0 ∈*
A A A, B, D
0 ∈*
B C C
D 0 D ∈* D
∈* 1
A A φ
B 1 φ
D 1 D
∈*
D
B
∈* 0 ∈*
B C C
0 ∈*
D D D
∈* 1
B B φ
1 ∈*
D D D
∈* 0
C C φ
∈* 1 ∈*
C C B B
∈* 0 ∈*
D D D D
Finite Automata
∈* 1 ∈*
D D D D
70
Chapter 2
∈ -NFA to NFA:
Transition table:
NFA:
0,1
0 0,1
0 0,1
A B D
0 1
0
C 1
Q3
q0 ∈* a ∈*
q0 q0 q0 ,q,q
1 2
q1 a φ
q2 a φ
q0 ∈* b
q0 φ
b ∈*
q1 q1 q1 ,q2
q2 b φ
q0 ∈* c
q0 φ
Finite Automata
q1 c φ
q2 c q2
∈* q2
71
Chapter 2
q1 ∈* a
q1 φ
q2 a φ
q1
∈* b
q2 φ
b ∈*
q1 q1 q1,q2
q1
∈* c
q1 φ
q2 c q2
∈*
q2
∈* a
q2 q2 φ
∈* b
q2 q2 φ
∈* c ∈*
q2 q2 q2 q2
∈ -NFA to NFA
Transition table:
NFA:
a b c
a,b b,c
q0 q1 q2
a,b,c
Note:
72
Chapter 2
Previous Years’ Question
Let δ denote the transition function and δ̂ denotes the extended transition function
of the ∈ -NFA whose transition table is given below: (GATE-2017 Set-2)
3) {q0 , q1 , q2 } 4) {q0 , q2 , q3 }
Sol: 3)
q0 = ( )
∈ −closure q0'
eg:
0 1 2
q0
∈ q1
∈ q2
ii) δ Construction:
Finite Automata
� Start Constructing δ with initial state and continue for every new
state that appears under the input column.
� Terminate this process when no new state appears.
73
Chapter 2
SOLVED EXAMPLES
Q1
q0q1 b
q1
a,b
Finite Automata
74
Chapter 2
Q2
Initial state
q0q1 a q0,q1, q2
q0q1 b q1
q0q1q2 a q0 ,q1, q2
q0q1q2 b q1,q2
q1 a q1,q2
q1 b q1
q1q2 a q1,q2
q1q2 b q1,q2
DFA:
a a, b
q0 q1 a q0 qq b q1q2
1 2
b a
Finite Automata
q1
75
Chapter 2
Note:
Q3
Initial state
q0q1q2 a q0q1q2
q0q1q2 b q1q2
q0q1q2 c q2
76
Chapter 2
q2 a Dead State ‘D’
q2 b Dead State ‘D’
q2 c q2
DFA:
c
a b c
q0q1q2 b q1q2 c
q2
a
a, b
a, b, c
Note:
Finite Automata
77
Chapter 2
What is the complement of the language accepted by the NFA shown below? Assume
{}
Σ = a and ∈ is the empty string. (GATE-2012)
a ∈
∈
1) φ 2) {∈}
3) a* 4) {a,∈}
Sol: 2)
Note:
Definitions
Finite state trSol:ducer is a finite state automaton which produces output on reading
any input.
Moore machines
Definitions
Finite Automata
Moore Machines are finite state machines with output value associated with states.
78
Chapter 2
It can be defined as –
(Q, Σ, δ, q0 , ∆, λ ) where
Q: Finite set of states
Σ: Input alphabets
δ: Transition function
Q×Σ → Q
q0 Initial state
∆: output alphabets
λ : output function which maps Q → ∆
eg:
a b
q0, 1 b q1, 0
Input: ab
a b
q0 q0 q1
1 1 0
Note:
SOLVED EXAMPLES
Q1
=Σ {a,b=
} ∆ {0, 1}
79
Chapter 2
b a
a b
A, 0 B, 0 C, 1
0 0 1 (Output)
Input2: abab
a b a b
A B C B C
0 0 1 0 1
Q2
Sol: ∑ ={a,b}
Take D = {0, 1}
a b
A, 0 b B, 0 a C, 0 a D, 1
0 0 0 0 1
Finite Automata
80
Chapter 2
Q3
Sol: ∑ ={0, 1}
∆ = {A, B, C}
0 1
1 1
q0, C q1, C q2,B
0 1
0
0
q3,A
C C B
1 1 0
Input 2: 110 q0 q1 q2 q3
C C B A
Q4
0
Sol: ∑ ={0, 1} Remainder: Binary number %3 1
2
∆ ={0, 1, 2}
Represents states equal to the number of remainders when any binary number
Finite Automata
divisible by 3
81
Chapter 2
0 0 1
1 0
q0, 0 q1, 1 q2,2
Mealy machine:
Definitions
Mealy machines are finite state machines, where output depends upon the present
input symbol and present state of the machine.
y (
It can be defined as: Q, Σ, δ, q0 , ∆, λ , ) where
Q×Σ → Q
q0 : Initial state
∆ : Output alphabet
l: Output function Q × ∑ → ∆
a/1 b/0
b/0
eg: q0 q1
a/1
Input: ab a b q1
q0 q0
Finite Automata
1 0 (output)
82
Chapter 2
Note:
SOLVED EXAMPLES
Sol: ∑ ={0, 1}
{ }
∆ = 0, 1
1/1 q1
q0
1/0
83
Chapter 2
The finite state machine described by the following state diagram with A as starting state,
where an arc label is x/y and x stands for 1-bit input and y stands for 2-bit output
(GATE-CS-2002)
1) Outputs the sum of the present and the previous bits of the input.
2) Outputs 01 whenever the input sequence contains 11
3) Outputs 00 whenever the input sequence contains 10
4) None of the above
Sol: 1)
SOLVED EXAMPLES
Q1
Sol:
We have to construct a Moore machine which counts the number of a’s is divisible
by 3.
b b b
a a
Finite Automata
q0, 0 q1 , 1 q 2, 2
84
Chapter 2
When convert moore to mealy, then q0 state on input a goes to
q1 states and output associated with state q1 is 1 so, it will go
onto the transition in equivalent mealy machine. Apply similar
concepts for every state.
a/1 a/2
q0 q1 q2
a/0
x y
q0 , 0 q1, 0 q 2, 1
x
y
Finite Automata
85
Chapter 2
SOLVED EXAMPLES
Q1
Sol: i) State q1 on getting input 0 goes to state q2 and the output present
in this transition gets associated with states q2 in the corresponding
equivalent moore machine.
ii) State q1 on getting input 1 goes to state q3 and the output present in
this transition i.e. ‘z1’ gets associated with state q3 in the corresponding
equivalent moore machine.
iii) We will follow this above procedure for other states as well as the new
states we are getting.
Finite Automata
86
Chapter 2
Rack Your Brain
y/1
Finite Automata
87
Chapter 2
Chapter Summary
88
3
Regular Expression, Grammar
and Language
Chapter 3
3.1 REGULAR EXPRESSION
y Regular expression represents a regular language.
y For every regular expression, regular language can be generated and for
every regular langauge, a regular expression is possible.
y Similar to arithmetic, where operations + and × are used to build up
expressions such as (5 + 3) × 4;
Regular operations are used to build up expressions which describe
languages are known as a regular expression.
Example: (0+1)0*
� The notation involves a combination of strings of symbols from some
alphabets ∑, parentheses and the operators +, . and *
Example: If L = {∈, aa, aaaa, aaaaaa, ........} then L can be expressed as (aa)*.
Application of regular expression:
a) In Unix grep or equivalent commands for finding strings.
b) In lexical analyser generators such as Lex or flex.
Definition
a)
b)
c)
89
Chapter 3
2) Concatenation
� If R1, R2 are any two regular expressions, then their concatenation (R1.
R2) will also be a regular expression.
3) Kleene closure
� If R1 is any regular expression, then Kleene closure of R1 (R1*) will also
be a regular expression.
There are three operations on languages that the operators of regular
expressions represent. These operations are:
1) Union
� The union of two languages L1 and L2 denoted as L1 ∪ L2.
� L1 ∪ L2 means a set of strings are either in L1 or L2 or both.
Example: L1 = {10, 111}
L2 = {∈, 01}, then L1 ∪ L2 = {∈, 01, 10, 111}
2) Concatenation
� The concatenation of two languages L1 and L2 is denoted as L1 . L2.
� L1 .L2 is the set of all strings that can be formed by taking any string
from language L1 and concatenating it with any string from language L2.
Example: L1 = {001, 10, 111}
L2 = {∈}
L1 .L2 = L1 L2 = {001, 10, 111}
Note:
L° = { ∈ }
L1 = L
L2 = L.L
Li = L.L.L……… i times
90
Chapter 3
y The language L(r) denoted by any regular expression ‘r’ is defined as:
i) φ is regular expression denoting { } i.e empty set.
ii) ∈ is a regular expression denoting { ∈ }.
iii) For every a ∈ ∑ , a is a regular expression denoting {a}.
yIf r1 and r2 are two regular expressions, then:
i) L(r1 + r2) = L(r1) ∪ L(r2)
ii) L(r1.r2) = L(r1).L(r2)
iii) L((r1)) = L(r1)
{If r1 is a regular expression, then (r1), a parenthesized r1, is also a
regular expression denoting the same language as r1.}
*
iv) L(r1* ) = (L(r1 ) )
These four rules are used to reduce L(r) to simpler components recursively.
Examples:
i) r = a*
L(r) = L(a*) = { ∈ , a, aa, aaa, ………}
ii) r=a+b
L(r) = {a, b}
iii) r = ab
L(r) = {ab}
iv) r = (a + b)*
L(r) = { ∈ , a, b, aa, ab,………}
v) r = a+ = a.a*
L(r) = {a, aa, ……………}
vi) r = a* + ba
L(r) = { ∈ , a, aa, aaa, ………,ba}
Example: (a+b.a)* 1
2
3
91
Chapter 3
Note:
SOLVED EXAMPLES
LHS = RHS
Option 2) is correct.
Regular Expression, Grammar and Language
LHS = RHS
2) LHS: r*. r* = {∈, r, rr, ……}. {∈, r, rr, ……}
= {∈, r, rr, ……}
RHS: r = {r, rr, rrr, ……}
+
LHS ≠ RHS
Option 2) is incorrect.
92
Chapter 3
Sol: If r = f, then r* = f* = {∈}
If r = ∈, then r* = ∈* = {∈}
Option 1) True.
Sol: Given:
r1 = (a*b)* and r2 = (a+b*)*
L(r1) = {∈, b, ab, aab,…….}
L(r2) = {∈, a, b, aa, ab, ba, bb, aab,………….}
So, L(r1) ⊂ L(r2)
Option 2)
93
Chapter 3
Option 3) : (ab*+ a)* (ab)* b*a* = {∈, a, b, aa, bb, ab, ba,
baa, abba,…..}
It can generate string containing ‘baa’ as a
substring.
Option 4) : (bba*+ b)* a = {a, ba, bba, bbaa, ……….}
It can also generate string containing ‘baa’
as a substring.
Which of the following statements is TRUE about the regular expression 01*0?
(GATE IT-2005)
1) It represents a finite set of finite strings
2) It represents an infinite set of finite strings
3) It represents a finite set of infinite strings
4) It represents an infinite set of infinite strings
Sol: 2)
Equivalence between regular language and regular expression:
y For every regular language, there is a regular expression and for every
regular expression, there is a regular language.
Regular Language
Fig. 3.1
Regular Expression, Grammar and Language
Theorem
“Let r be a regular expression, then there exists some non-deterministic
finite acceptor that accepts L(r). Consequently, L(r) is a regular language.”
Example:
q0 q0
NFA accepts φ
q0 a q0
94
Chapter 3
SOLVED EXAMPLES
= a(a + b)*
RE
ii) L = {b, ab, bb, …………}
= (a + b)* b
RE
95
Chapter 3
RE= (a + b+ ∈)(a + b+ ∈)
A
A
A
A
A
A
96
Chapter 3
Sol: i) Even length string
L = {∈, aa, ab, ba, bb, ……….}
RE =( (a + b)(a + b) )
∗
v) all the strings the where the number of a’s are exactly 2.
L={aa,aab,aba,baa.......}
RE = b*ab*ab*
vi) all the strings where the number of a’s are ‘at least 2’.
L = {aa, aab, aba, aaa, ……….}
=RE b*ab*a(a + b)*
vii) all the strings where the number of a’s are ‘atmost 2’.
L = {∈, a, ab, ba, aa, …….}
RE= b* (∈ +a)b* (∈ +a)b*
viii) all the strings where the number of a’s are even.
L = {∈, b, bb, aa, aab, aba …….}
97
Chapter 3
RE = (aa)*(bb)* + (aa)*a(bb)* b
Case 1 Case 2
RE = (aa)*a(bb)* + (aa)*(bb)*b
Case 1 Case 2
Regular Expression, Grammar and Language
RE = a ( ( a + b ) ( a + b ) )
*
Note:
98
Chapter 3
Properties of regular expressions:
Let r, s and t be some regular expression.
i) Commutativity:
In this property, after changing the position of operands result will
remain the same.
r +s = s+r
r.s ≠ s.r
ii) Associativity:
Properties which allow us to regroup the operands when the operand
is applied twice.
r + (s + t) = (r + s) + t
r.(s.t) = (r.s).t
iii) Distributive:
Property which involves two operators and states that one operator
can be pushed down to be applied to each argument of the other
operator individually.
Left distributive : r(s + t) = rs + rt
Right distributive : (s + t)r = sr + tr
Note:
v) Annihilator:
99
Chapter 3
vi) Idempotent:
An operator is idempotent; if we apply it to two same operands, the
output will be that operand itself.
r +r =r (Idempotence law for union)
vii) Closure:
*
� φ = ∈
� φ+ =φ
� ∈+ =∈
� ∈* =∈
� ∈ + rr* =r*
� (r* )* = r*
� r+ = rr* = r*r
� (r+)*= r*
� (r*)+= r*
� (r+)+= r+
� r*r* = r*
� r+r* = r+
� r*r+ = r+
(pq)* q ≠ p(qq)*
� (pq)* p = p(qp)* but * *
(pq) r ≠ p(qr)
Note:
Regular Expression, Grammar and Language
Which one of the following regular expressions represents the language; set of all
binary strings having two consecutive 0’s and two consecutive 1’s?(GATE-2016 (set-1))
1) (0+1)* 0011(0+1)*+ (0+1)*1100(0+1)*
2) (0+1)* (00(0+1)* 11+ 11(0+1)*00)(0+1)*
3) (0+1)* 00(0+1)*+ (0+1)*11(0+1)*
4) 00(0+1)* 11+11(0+1)*00
Sol: 2)
100
Chapter 3
Rack Your Brain
Which one of the following languages over the alphabet {0,1} is described by the
regular expression :
(O+1)* 0(0+1)*0(0+1)*? (GATE-2009)
1) The set of all strings containing the substring 00
2) The set of all strings containing at most two 0’s
3) The set of all strings containing at least two 0’s
101
Chapter 3
i) For every language, for which we have finite automata, there exists a
regular expression also.
ii) Similarly, for every language, for which we have a regular expression
there exists a finite automata also.
Rules:
1) There should be only one initial and final state.
∈ ∈
∈ ∈
,then
∈
∈
Start
∈
then
Regular Expression, Grammar and Language
A B
r2
r3
Then,
r1 + r2 + r3
A B
4) Elimination of nodes/states.
102
Chapter 3
Example:
i) q0 r1 q1 r2 q2 ⇒ q0 r1r2 q2
r2
r1 r3 r1r2*r3
ii) q0 q1 q2 ⇒ q0 q2
r1 (r1r2)
q0 q1
iii) ⇒ q0
r2
r2 r1r2*r3
r1
q0 q1 q0
iv) ⇒
r3
r1 r2 r3
r1 + r2r3*r4
v) q0 q1 ⇒ q0
r4
r1 r2
r1
r1r3
q1 q2
r3 q2
vi) q0 q1 ⇒
r1
i) ⇒ r1*
103
Chapter 3
r1, r2
r1r2
r
iv) ⇒ r
r1
r2
v) ⇒ r1*r2
r2
r1
vi) ⇒ r1r2*
r1 r3
r2
vii) ⇒ r1*r2r3*
Arden’s method:
Let P, Q be the regular expression over ∑.
If P does not contain ∈, then Regular expression R can be written as:
Regular Expression, Grammar and Language
Note:
If P contains , then regular expression R will have an infinite number of solutions.
104
Chapter 3
Put R = Q + RP again. On solving, it recursively
R = Q + QP + QP2 + QP3 + ………………………..
R = Q (∈ + P + P2 + ……………………………….)
R = QP*
Note
We can write equation for every other state and start state based on all incoming arrows.
SOLVED EXAMPLES
Sol: A=∈
B = Aa + Ba + Ca
C = Ab
A =∈
C=
∈ .b =
b
B = ∈ .a + Ba + ba (Put values of A and C in B’s equation)
105
Chapter 3
*
⇒ B
= Ab + Ba = a
b+B
a (P does not contain ∈ )
R Q RP
B = (a*b)a*
⇒ C = B(a+b) + Cb
*
=C
(a b)a* (a + b) + Cb (P does not contain ∈ )
R Q RP
=C a*ba* (a + b)b*
Regular Expression, Grammar and Language
106
Chapter 3
A = ∈ + Ab + Aab*a
A + A(b
=∈ + ab*a) (P does not contain ∈ )
R Q RP
∈ (b + ab*a)*
A=
= (b + ab*a)* ab*
B
∈ (a + ba)*
A=
⇒ B = Ab
107
Chapter 3
r r
i) f
ii) a a
iii) b b
iv) ab a b
Regular Expression, Grammar and Language
v) a* ∈
∈ a ∈
vi) ab* b
108
Chapter 3
Regular Expression Finite Automata
a
vii) (ab)*
a
a b
Table 3.1
SOLVED EXAMPLES
Sol: q0 ab*c
q2 RE = ab*c
109
Chapter 3
a a, b
Sol: q0 aba
q2
Sol: 1 0, 1
0 0
A B C
01 1
*
0, 1
01*0
⇒ A C
Regular Expression, Grammar and Language
01 1
*
=
⇒ RE (01* 1)* 01*0(0 + 1)*
110
Chapter 3
Sol:
b ∈
a c ∈
d
∈
a b, c, d
RE= a(b + c + d)
Sol: c
b d
A B C
ab
111
Chapter 3
c+ab
b d
A B C
b(c+ab)*d
A C
= b(c + ab)* d
RE
Sol: 0
1
0
A B
1
0
10 *1
Regular Expression, Grammar and Language
= (0 + 10* 1)*
RE
112
Chapter 3
Sol:
0 0 0
1 1
A B C
10 *10*1
⇒ (0+10*10*1)*
(0 + 10 10 1)
*
* *
RE
=
3) 4)
Sol:
113
Chapter 3
Which regular expression best describes the languages accepted by the non-
deterministic automaton below? (GATE (IT) 2006)
1) 2)
1) (a + b)* a(a + b) b 2) (abb)*
3) 4)
3) (a+b)*a(a + b)*b (a+b)* 4) (a+b)*
Sol:Sol:
1)
Regular Grammar
Fig. 3.2
Regular Expression, Grammar and Language
114
Chapter 3
where A, B ∈ V (Variables) and x ∈ T* (T = terminals)”
Note
A regular grammar is one that is either right linear or left linear.
Reason:
Even though here every production is in right or left linear form, but the
grammar itself is neither right linear nor left linear. So, it is not Regular
grammar.
Note
The above example is linear grammar.
A regular grammar is always linear, but not all linear grammars are regular
Note:
The language generated by the right linear grammar is always regular.
115
Chapter 3
DFA or NFA
Regularexpressions
Regular Grammar
Fig. Fig.
3.1 3.3 Conversion of
: Conversion of Regular
Regular expressions,
expressions,
Regular Grammar and Finite automata
Regular Grammar and Finite automata
“TRUE”?
1) 2)
Regular Expression, Grammar and Language
2) 4)
Sol:
116
Chapter 3
Rack
RackYour
YourBrain
Brain
SOLVED EXAMPLES
Sol: i) L = a*
S → Sa| ∈
(OR)
S → aS | ∈
ii) L = a+
S → Sa|a
(OR)
S → aS | a
Sol: ∑ = {a, b}
Regular expression = (a + b)* , L = { ∈ , a, b, aa, ab, ………}
Sol: ∑ = {a, b}
Regular expression = (a + b)+ , L = {a, b, aa, ab, ………}
S → aS|bS|a|b
117
Chapter 3
Grammar:
S → aA
A → aA|bA| ∈
Conversion from finite automata to regular grammar:
a, b
a
A B
∈
[α ]
Regular Expression, Grammar and Language
[S]
a
[aα] [α]
a
[a] [∈]
118
Chapter 3
SOLVED EXAMPLES
[S]
∈ [bbaS]
b
[baS]
b
[aS]
a
[a] [E]
δ ( S, ∈) =[bbaS]
δ ( S, ∈) =[a]
δ (bbaS,b ) =
[baS]
δ (baS,b ) =
[aS]
δ ( aS, a ) =
[S]
δ ( a, a ) =
[E]
[S]
∈ [01S]
0
[1S]
1
[1] [E]
119
Chapter 3
δ ( S, ∈) =[01S]
δ ( S, ∈) =[1]
δ ( 01S, 0 ) =
[1S]
δ ( 1S, 1) =
[S]
δ ( 1, 1) =
[E]
SOLVED EXAMPLES
Sol: Step-1: Reverse the right-hand side of every production and get the right
linear Grammar.
S → 011S|0
Step-2: Obtain ∈–NFA
Q(States) = {[S], [011S], [11S], [1S], [0], [E]}
∈ 0 1
Regular Expression, Grammar and Language
0
[0] [E]
Step-3:
Make the initial state as final state and the final state as initial
state.
Step-4: Change the direction of the edges.
120
Chapter 3
1
[S]
∈ [011S]
0
[11S]
1
[1S]
[0] 0 [E]
Sol: Step-1 : Reverse the right-hand side of every production and get Right Linear
Grammar.
S → 001S|1
Step-2 : Convert to ∈ –NFA
Q(States) = {[S], [001S], [01S], [1S], [1], [E]}
1
∈ 001S
0
01S
0
1S
S
1 E
1
121
Chapter 3
q2
∈ 001S
0
01S 0 1S
S
q3 q4 q5
∈
1
1 E
q1 q0
1 ∈ ∈ 0 0
q0 q1 q2 q3 q4 q5
Definition
A language L is called regular if and only if there exists some deterministic finite
acceptor M such that L = L(M).
Note:
Regular Expression, Grammar and Language
122
Note:
Chapter 3
Closure properties of regular language
Closure properties of regular languages are defined as the certain operation
on regular language, which when applied to the language, results into the
language of the same type.
i) Closure under union:
Theorem:
“If L1 and L2 are regular languages, then L1 ∪ L2 will also be a regular
123
Chapter 3
Definition
124
Chapter 3
Example: The function h given by h(0) = abb and h(1) = ba is a
homomorphism which replaces each 0 by abb and each 1 by ba. Thus,
h(1011) = baabbbaba.
Theorem:
“If L is a regular language over alphabet ∑, and h is a homomorphism
on ∑, then h(L) is also regular.”
L h h(L)
h–1 (L) h L
125
Chapter 3
126
Chapter 3
by regular language of another alphabet ‘∆’
Regular sets are closed under substitution.
Example: ∑ = {a, b}
f(a) = 0*
f(b) = 01*
L = a + b*
f(L) = 0* + (01*)*
which is again a regular expression, which will accepted by some
finite Automata.
Note:
Example: L1 = {ab}
L2 = {a2b2}
L3 = {a3b3} ………………..so on
L = L1 ∪L2∪L3 ∪ ……………………………….
= {anbn | n ≥ 1} which is not regular.
Note:
127
Chapter 3
Operations Yes/No
1) Union Yes
2) Substitution Yes
3) Complementation Yes
4) Set-difference Yes
5) Concatenation Yes
6) Reversal Yes
9) Subset (L) No
128
Chapter 3
i) Testing emptiness of regular languages:
Emptiness problem of Regular Language is decidable.
EDFA = {<D>| D is a DFA and L(D) = φ}
Algorithm:
Step 1: Select the states which are not reachable from the
initial state and delete those states and corresponding
transitions.
Step 2: In the remaining finite Automata, if we find at least one
final state, then the language accepted by the given finite
Automata is non-empty otherwise, empty.
Is L1 = L2 ?
FA 1 FA2
For regular language L1, we can make a Finite Automata FA1 and
similarly for regular language L2. We can make finite Automata FA2.
So, corresponding DFA will exist for both languages, which can be
further minimised.
Thus, whether two regular languages are equal or not is decidable.
129
Chapter 3
Note:
Pumping lemma:
y It is evident from the many examples that Regular languages can be
infinite.
y However, the regular language associated with automata having finite
memory imposes restrictions on the structure of Regular language.
y Pumping lemma is a theorem about regular languages which is used to
prove that some of the languages are not regular.
Theorem:
“If L is an infinite regular language. Then there exists some positive integer
n such that any w ∈ L , | w | ≥ n can be decomposed as:
w = xyz such that
i) | y |≥ 1
ii) |xy| ≤ n
iii) for all i ≥ 0 , the string xyiz is also in L.”
Regular Expression, Grammar and Language
Note:
Example: L = {anbn| n ≥ 1}
Sol: Let’s assume L is a regular language (proof by contradiction)
w∈L
w ∈ akbk
Choose a ‘k’ such that |akbk|. Here 2k ≥ n
w = akbk
130
Chapter 3
z
x y bk
a
k–1
a
|xy| = |ak–1a| = |ak| (Here k ≤ 2k)
| y |≠ 0
Hence, xyiz ∈ L ; ∀ i ≥ 0
For i = 2, ak–1 a2bk = ak+1 bk ∉ L
∴ L is Non-Regular.
Note:
131
Chapter 3
1) 2)
3) 4)
Sol:
1) 2)
3) 4)
Sol:
Regular Expression, Grammar and Language
Myhill-nerode theorem
y Myhill-Nerode Theorem provides a necessary and sufficient condition
for a language to be a regular.
y The Myhill-Nerode Theorem states that L is regular if and only if RL has
a finite number of equivalence classes and moreover that the number
132
Chapter 3
of states in the minimal DFA recognizing L is equal to the number of
equivalences classes in RL.
y The language L defines over the alphabet ‘ ∑ ’ is Regular iff the number
of equivalence classes with respect to ‘L’ is finite.
y In minimal finite automata, some language can be defined at each and
every state. These languages are mutual disjoint and they are known as
equivalence classes.
y Union of all these equivalence classes = ∑*
y Union of some of the equivalence classes = Language ‘L’ accepted by
finite automata.
Example 1:
a, b
a
A B
a, b
A = {∈}
*
B a(a + b) Equivalence Classes
=
C b(a + b)*
=
133
Chapter 3
a
A B
b a
a, b
134
Chapter 3
Chapter Summary
y Regular expression: Regular expression is one way to describe the regular languages
via the notation.
y Operators of regular expression: Union, Concatenation, Closure (Kleene Closure/
Star Closure).
y Order of precedence of regular expression operators:
* > • > +
y Equivalence between regular language and regular expression: For every regular
language, there exists a regular expression and for every regular expression, there
is a regular language.
y Properties of regular expression: Commutativity, Associativity, Distributive, Identity,
Idempotent, Closure.
y Equivalence between regular expression and finite automata: Every language
defined by a regular expression and a regular expression is defined by Finite
Automata.
y Conversion of finite automata to regular expression: i) State Elimination Method
and ii) Arden’s Method.
y Regular grammar: Another way of describing the regular languages. It is also known
as Type 3 grammar in Chomsky Hierarchy.
y The Grammar ‘G’ is said to be type 3 or Regular if every production is in the form:
A → xB | x or A → Bx|x, where A, B ∈ V, x ∈ T*
y Types of regular grammar: Right linear Grammar and left linear Grammar.
y Regular Language: The language which is accepted by finite Automata, generated
by Regular expression and generated by Regular Grammar is known as Regular
135
4 Context-Free Language and
Pushdown Automata
Chapter 4
4.1 CONTEXT-FREE GRAMMAR
y Context-free grammars are a more powerful method of describing
languages.
y The productions in a regular grammar are restricted in two ways:
The left side must be a single variable, while the right-hand side of the
production has a constraint as we know for RLG: A → xB|x and for LLG:
A → Bx|x where A, B∈V and x∈T*.
y To create grammars which are more powerful, we must relax some of
these restrictions.
y By retaining the restriction on the left side but permitting anything on
the right, we get context-free grammar.
Definition:
y A grammar G = (V,T,S,P) is said to be context-free if all productions in P
have the from:
A→x
Where, A ∈ V and x ∈ (VUT)*
Where,
T = Terminals.
V = Non-Terminals or variables.
S = Start symbol.
P= Finite set of rules or productions that represent the recursive
definition of a language.
y Each production consists of:
a) A variable that is being (partially) defined by the production. This
137
Chapter 4
Definition
A derivation is said to leftmost if in each step, the leftmost variable in the sentential form is
replaced. If in each step, the rightmost variable is replaced, derivation is known as rightmost.
138
Chapter 4
Previous Years’ Question
Identify the language generated by the following grammar, where S is start variable.
(GATE-2017 (Set-2))
S→XY
X→zX|a
Y→aYb|∈
1) {ambn|m ≥ n, m > 0} 2) {ambn|m ≥ n, n ≥ 0}
3) {ambn|m > n, m ≥ 0} 4) {ambn|m ≥ n, n > 0}
Sol: Option 3)
Derivation trees:
A second way of showing derivations, independent of the order in which productions are
used; is by a derivation tree or parse tree.
Definition
A derivation tree is an ordered tree in which nodes are labelled with the left sides of
production and in which the chileren of a node represent its corresponding right sids
139
Chapter 4
Example: A → abABc
a b A B c
Let G = (V, T, S, P) be a context free grammar. An ordered tree is a derivation tree for G
if and only if it has the following propertie:
a) The root is labeled S.
b) Every leaf has a label from T∪{∈}.
c) Every interior vertex (a vertex that is not a leaf) has a label from V.
d) If a vertex has label A ∈ V, and its children are labelled (from left to right) a1, a2, ..........
an, then P mustcontain a production of the form.
A → a1, a2, ........... an
e) A leaf labeled ∈ has no siblings, that is a vertex with a child labeled ∈ can have no
other children.
a A B
b B b A
∈ b B b
140
Chapter 4
Rack Your Brain
A CFG G is given with the following productiions where S is the start symbol, A is non-
terminal and a and b are terminals. (GATE-IT-2008)
S→aS|A
A→aAb|bAa|∈
Which of the following strings is generated by the grammar above?
1) aabbaba 2) aabaaba
3) abababb 4) aabbaab
Sol: Option 4)
Ambiguity in grammar:
When a grammar fails to provide a unique structure, it is sometimes possible
to redesign the grammar to make the structure unique for each string in
the language; but sometimes we cannot. That is known as ambiguity in
Ambiguous grammar:
Definition
Note:
Ambiguity implies the existence of two or more leftmost or rightmost
derivations.
Example: E → E+E | E * E
Consider the sentential form E + E * E.
It has two derivations from E:
141
Chapter 4
1st 2nd
E⇒E+E E⇒E*E
⇒E+E*E ⇒E+E*E
E E
E E E E
+ *
E E E E
* +
(a) a) b) (b)
Fig. 4.1 Two Parse Trees with the Same Yield.
y Derivation 1st says that the second and third expressions are multiplied
and the result is added to the first expression.
y Derivation 2nd adds the first two expressions and multiplies the result
by the third.
Example: 1+2*3
1st derivation gives output = 1+(2*3)=7
2nd derivation gives output = (1+2)*3 = 9
y Hence, we can say that there is an ambiguity.
142
Chapter 4
Example of an unambiguous grammar:
Example 1: Example 2: Example 3:
E→E+T S → aAB X → AB
T→T*F A → bBb A → Aa|a
F → id B → A|∈W B→b
A CFG G is given with the following productions where S is the start symbol, A is non-
terminal and a and b are terminals. (GATE-IT-2008)
S→aS|A
A → aAb|bAa|∈
For the string, “aabbaab” how many steps are required to derive the string and how
143
Chapter 4
Definition
Note:
A variable is nullable if it can derive E directly or indirectly.
Eliminating ∈ productions:
y A grammar may generate a language not containing ∈ , but can have some
∈ -production or nullable variables. In such a case, the ∈ -productions can be removed.
Example: S → ABC
A → BC|a
B → bAC|∈
C → cAB|∈
contains ∈–productions.
Context-Free Language and Pushdown Automata
Step 1: Find all the nullable variables or null variables. Remove all the null production
from the grammar.
Step 2: Replace the right-hand side of the production with and without ∈ ; wherever
nullable variables or null variables are present on the RHS of production.
Step 3: After this, whatever grammar we get, that grammar is without ∈ - production.
Note:
If start symbol (S → ∈) contain ∈ - production i.e.
if the language contain ∈, then we cannot eliminate ∈ - productions, totally.
144
Chapter 4
Sol: Step 1: Nullable or null Variable = {B, C, A}
B contains ∈ production, so it is a nullable variable, similarly C is also a nullable
variable.
A contains production A → BC, where B and C both are null variables. Thus A is
also deriving epsilon. Hence A is also a nullable variable.
A ® BC
A ® B [Substitute C ® ∈ ]
A ® C [Substitute B ® ∈ ]
B ®b
C ®D
D ®d
145
Chapter 4
A ® BC | B | C | a
B ® bAC | bA | bC | b
C ® cAB | cA | cB | c
146
Chapter 4
Eliminating unit productions:
Definition
SOLVED EXAMPLES
Q1 S → Aa | B
B → A | bb
A → a | bc | B
Eliminate unit-production from the given grammar.
S B bb
a
S BA
bc
147
Chapter 4
Q2 S → AB
A→a
B → C|b
C→D
D→E
E→a
S, A, B, C, D, E E Variables and T = {a, b}
Eliminate Unit - Productions from the given grammar.
i) B C D E a
Add all this production in grammar
ii) C D E a
obtained in step 1
iii) D E a
Context-Free Language and Pushdown Automata
148
Chapter 4
Eliminating useless symbols:
y Symbol X is a useless symbol for a grammar G = (V,T,P,S) if that symbol can never take
part in any derivation.
Example: S → aSb|∈|A
A → aA
y Here, the production S → A is useless as A cannot be transformed into a terminal string.
y Removing this production S → A leaves the language unaffected and is a simplification
by any definition.
Note:
A variable is useful if it is reachable from the start state and is also able to derive some
terminal or some strings of terminals.
SOLVED EXAMPLES
Sol: Here, we can remove B → bA, since B is not reachable from the start state.
Final grammar is
S→A
A → aA|Î
Sol: � Initially, only B and C be the non-terminal symbols that directly generates
terminal strings; hence useful symbol.
� S is useful because the rule S → aBC
� A is useful because the rule A → aS
� D does not generate terminal strings; thus, it is a useless symbol.
� Eliminate D and those productions involving D, we get grammar:
S → aAa|aBC
149
Chapter 4
A → aS
B → aBa | b
C → abb
B → bbA | aaB| AB
All are reachable from the start symbol S.
What will be the final grammar after removing the useless symbols
from the given grammar:
S → aS|A|C
A→a
B → aa
C → aCb
150
Chapter 4
Theorem:
Let G = (V,T,S,P) be a context-free grammar. Then there exists an equivalent
grammar G ˆ = (V,
ˆ T, ˆ ˆ that does not contain any useless variables or
ˆ S,P)
productions.
Note:
When we want to convert any CFG into an equivalent CFG that has no
useless symbols, ∈-productions and unit-productions. Some care must be
taken in order of application of the consturction.
A safe order is:
i) Eliminate E-production.
ii) Eliminate unit production.
iii) Elminiate useless-symbols.
Normal forms:
When working with context-free grammar, it is often
convenient to have them in simplified form. There are two
types of normal forms of context-free grammar.
Normal Forms
151
Chapter 4
Definition
Note:
In addition, we permit the rule S → ∈, where S is the start symbol in
Chomsky Normal Form.
Example: S → AS | a
A → SA | b
is in Chomsky Normal Form.
Whereas the grammar:
S → AS | AAS
A → SA | aa
is not in Chomsky Normal Form; both productions S → AAS and A → aa
violate the condition of the definition of Chomsky Normal Form.
Theorem:
Any context-free language is generated by a context-free grammar in
Chomsky’s normal form.
Context-Free Language and Pushdown Automata
152
Chapter 4
= 2|w| – 1
= 2×2 – 1 = 3
iv) It is easy to apply the CYK membership algorithm, which is of the
polynomial type having time complexity = O(n3)
Note:
Given any Chomsky Normal Form Grammar, CYK membership algorithm
can parse it.
CYK algorithm:
This algorithm is only applicable if the given grammar is in CNF.
Check whether the string “baaba” is a valid member of the following CFG.
S → AB|BC
A → BA|a
B → CC|b
C → AB|a
153
Chapter 4
\ (1,3) = f
Similarly, we can fill the other entries in the table.
(1,5) can be generated by ‘S’ (Starting symbol)
\ baaba can be generated by grammar.
What is the substring of “baaba” that can be derived from this grammar?
From the table entries, we select the entries that have ‘S’ (starting symbol)
(1, 2) ® ‘S’ can generate ‘ba’
(2, 5) ® ‘S’ can generate ‘aaba’
(3, 4) ® ‘S’ can generate ‘ab’
Time complexity:
We are filling n2 cells.
For each cell, in the worst case, we might need O(n) time.
154
Chapter 4
Total complexity
= O(n2 ) × O(n)
= O(n3 )
Note:
Every context free grammar can be transformed into an equivalent
grammar in Greibach Normal Form.
SOLVED EXAMPLES
155
Chapter 4
Sol: As required, the grammar does not have any ∈ -productions or any
unit productions.
Step 1: Introduce new variables Na, Nb, Nc and replace a with Na, b
with Nb, c with Nc.
S → ABNa
A → NaNaNc
B → ANc
Na → a
Nb → b
Nc → c
Step 2: Introduce additional variables to get the first two
productions into Normal form:
S → AD1
D1 → BNa
A → NaD2
D2 → NaNb
B → ANc
Na → a
Nb → b
Nc → c
Note:
CNF produces the same language which is generated by CFG (Context
Free Grammar).
Context-Free Language and Pushdown Automata
Sol: As required, the grammar does not have any ∈ -productions or any
unit productions.
Step 1: Introduce new variables Na, Nb.
S → NbA | NaB
A → NbAA | NaS | a
B → NaBB | NbS | b
156
Chapter 4
Na → a
Nb → b
Step 2: Introduce additional variables C1 and C2.
S → NbA | NaB
A → NbC1 | NaS | a
B → NaC2 | NbS | b
Na → a
Nb → b
C1 → AA
C2 → BB
Note:
For a given grammar, more than one CNF can be possible.
SOLVED EXAMPLES
Sol: In GNF:
S → aSB | aB
B→b
157
Chapter 4
Sol: In GNF:
S → bAB | cB
A→b|c
B→c
Sol: In GNF:
S → mSA | mA
A→n
Context-Free Language and Pushdown Automata
Sol: In GNF:
S → aBX | bCY
B → bBY | b
C → bCY | a
X→b
Y→a
158
Chapter 4
4.2 PUSHDOWN AUTOMATA
Definition
A pushdown Automata is a non-deterministic finite automaton coupled with a stack that
can be used to store a string of arbitrary length. The stack can be read and modified only
at its top.
(OR)
The automaton which defines context-free languages is known as pushdown Automata.
A Non-deterministic pushdown Acceptor (NPDA) is defined by the set tuples:
M (Q, Σ,τ, δ, q0, Z, F)
Where,
Q : A finite set of states,
Σ : A finite set of input symbols.
τ : A finite stack alphabet.
(set of symbols that we are allowed to push into the stack)
δ : Q × (Σ ∪ {∈}) × τ → set of finite subsets of Q × τ* is the transition function.
q0 ∈ Q is the initial state of the control unit.
Z0 : Z0 ∈ τ is the stack start symbol.
F : F ⊆ Q is the set of final states.
Finite State
Control
159
Chapter 4
Example: L = {anbn | n ≥ 1}
We cannot construct the finite Automata corresponding to this language.
L is context-free language.
We can construct a push down Automata for Language L.
(a, a | aa)
δ(q0 , b, a) = (q,1 ∈) a
Z0
pop ‘a’
δ(q1 , b, a) = (q,1 ∈)
Z0
pop ‘a’
160
Chapter 4
Pushdown automata acceptance can be done in 2 ways:
1) acceptance by final state:
Let P = (Q, ∑, τ, δ, q0, z0, F) be a PDA.
Then language accepted by P is the set
L(P) = {W | (q0, w, z0) (qf, ∈, s)}
161
Chapter 4
SOLVED EXAMPLES
(∈, z0 |z0 )
q0 qf
(a, a | aa)
(b, b | bb)
(a, b | ∈)
(b, a | ∈)
δ(q0, b, a) = (q0, ∈)
z0
pop ‘a’
Context-Free Language and Pushdown Automata
b
δ(q0, b, b) = (q0, bb) b
z0
push ‘b’
δ(q0, a, b) = (q0, ∈) b
z0
pop ‘b’
162
Chapter 4
δ(q0, a, b) = (q0, ∈)
z0
pop ‘b’
Sol:
(a, a | aa)
(a, z0 | az0 ) (b, a | a) (c, a |∈)
163
Chapter 4
Consider the transition diagram of a PDA given below with input alphabet ∑ = {a, b} and
stack alphabet τ = {X, Z}, Z is the initial stack symbol.
Let L denote the language accepted by the PDA.
Context-Free Language and Pushdown Automata
164
Chapter 4
Sol: Push 2 a’s onto stack on seeing 1 a in input
(a, z0 | aaz0) (b, a | ∈)
(b, a | ∈) (∈, z0 | z0 )
q0 q1 q2
(a, a | aaa)
a
δ(q0, a, a) = (q0, aa) a Push ‘a’
z0
a
δ(q0, b, a) = (q1, a) a Do Nothing (Skip)
z0
165
Chapter 4
Sol: On input ‘a’ perform push operation onto the stack. On input ‘c’, skip (i.e., do nothing).
On input ‘b’ and ‘a’ on top of stack, perform pop operations.
(a, z0 | az0) (b, a | ∈ )
(c, a | a) (∈, z0 | ∈ )
q0 q1 q2
(a, a | aa)
Context-Free Language and Pushdown Automata
a
δ(q0, a, a) = (q0, aa) a
z0
a
δ(q0, c, a) = (q1, a) a Do Nothing
z0
166
Chapter 4
δ(q1, b, a) = (q1, ∈) Pop ‘a’
z0
Sol:
(a, a | aa)
(a, z0 | az0) (a, a | ∈ )
(c, z0 | z0 )
(c, a | a) (∈, z0 | z0 )
q0 q1 q2
(c, b | b)
ab c ba
Consider a string =
w c wR
167
Chapter 4
Consider the Pushdown Automaton (PDA) below which runs over the input alphabet
(a, b, c). It has stack alphabet {z0, x} where z0 is the bottom-of-stack marker. The set
of states of the PDA is (s, t, u, f) where s is the start state and f is the final state. The
PDA accepts by final states. The transitions of the PDA given below are depicted in a
standard manner. For example, the transition (s, b, x) → (t, xz0) means that if the PDA
is in state s and the symbol on the top of the stack is x, then it can read b from the
input and move to state t after popping top of stack and pushing the symbols z0 and x
(in that order) on the stack. (GATE IT 2006)
(s, a, z0) → (s, xxz0)
(s, ∈, zo) → (f, ∈)
(s, a, x) → (s, xxx)
(s, b, x) → (t, ∈)
(t, b, x) → (t, ∈)
(t, c, x) → (u, ∈)
(u, c, x) → (u, ∈)
(u, ∈, z0 ) → (f, ∈)
The language accepted by the PDA is:
1) {albmcn | l = m = n}
2) {albmcn | l = m}
3) {albmcn | 2l = m + n}
4) {albmcn | m = n}
Context-Free Language and Pushdown Automata
Sol: Option 3)
168
Chapter 4
Sol: We cannot construct deterministic pushdown Automata for the
given language L = {wwR | w∈{a, b}*}.
Here Non-determinism comes into picture since on same state, on
same input more than one transition will be defined.
169
Chapter 4
Sol:
δ : Q × {Σ ∈} × τ → Q × τ * δ : Q × {Σ ∈} × τ → set of
finite subsets of Q × τ *
Context-Free Language and Pushdown Automata
170
Chapter 4
Previous Years’ Question
Consider the NPDA < Q = {q0, q1, q2}, ∑ = {0, 1}, τ = {0, 1, ⊥}, δ, q0, ⊥, F = {q2} >
Where (as per usual convention) Q is the set of states, ∑ is the input alphabet, τ is the
stack alphabet, δ is the state transition function, q0 is the initial state, ⊥ is the initial
stack symbol, and F is the set of accepting states. The state transition is as follow:
( GATE 2015 (Set-1))
Which one of the following sequences must follow the string 101100 so that the overall
string is accepted by the automaton?
1) 10110 2) 10010
3) 01010 4) 01001
Sol: Option 2)
4) L = {anbpcn | p, n ≥ 1}
Grammar Corresponding to given CFL:
S → aSc|aAc
A → bB|b
5) L = {ambn | m > n; m,n ≥ 1}
Grammar Corresponding to given CFL:
S → aSb|aAb
A → aA|a
6) L = {ambn | m ≠ n; m,n ≥ 1}
Cases: m > n or m < n
S → S1 | S2
S1 → aS1b|aAb
A → aA |a
S2 → aS2b|aBb
B → bB|b
7) L = {w| |wa| = |wb|, w∈{a, b}*} (number of a’s and number of b’s should be
equal)
Grammar Corresponding to given CFL:
S → SaSbS | SbSaS | ∈
172
Chapter 4
Thus, context-free language is not closed under intersections.
Again, L1 ∩ L2 = L1 ∪ L2
If the family of context-free languages was closed under complementation,
then the right side of the above expression would be a context-free language
for any context-free L1 and L2.
But this contradicts since we have shown, the intersection of two context-
free languages is not necessarily context-free. Thus, the family of context-
free languages is not closed under complementation.
Note:
If L is a CFL and R is a regular language, then L ∩ R is a context free
language.
Let L1 be a regular language and L2 be a context free language. Which of the following
173
Chapter 4
Let L1, L2 be any two context free languages and R be any regular language, then which
of the following is/are CORRECT? (GATE 2017 (Set-2))
I) L1 ∪ L2 is context free.
–
II) L1 is context free.
III) L1 – R is context free.
IV) L1 ∩ L2 is context free.
1) I, II and IV only 2) I and III only
3) II and IV only 4) I only
Sol: Option 2)
Definition
174
Chapter 4
y In DPDAs, at each step of its computation, the DPDA has at most one
way to proceed according to its transition function.
Example: L = {0n1n | n ≥ 0} is DCFL.
Note:
Every language accepted by DPDA is also accepted by NPDA but converse
need not to be true.
175
Chapter 4
If L1 and L2 are context free languages and R a regular set, one of the languages below
is not necessarily a context free language? (GATE -1996)
Which one?
1) L1.L2 2) L1 ∩ L2 3) L1 ∩ R 4) L1 ∪ L2
Sol: Option 2)
Let L be a context free language and M a regular language. Then the language L ∩ M is:
(GATE-2006)
1) always regular
2) never regular
3) always a deterministic context free language
4) always a context free language
Sol: Option 4)
2) Finiteness problem
3) Membership problem
Emptiness problem:
Given a context-free grammar G = (V, T, S, P), there exists an algorithm for
deciding whether L (G) is empty or not; hence this is a decidable problem.
ECFG = { <G> | G is a CFG and L(G) = φ }
Finiteness problem:
Given a context-free grammar G = (V, T, S, P), there exists an algorithm for
determining whether L(G) is infinite or not.
Membership problem:
Given a context-free grammar G = (V, T, S, P), there exists an algorithm, for
deciding whether a given word w is in the language defined by a context-
free grammar.
176
Chapter 4
Proof:
y Start by converting whatever representation of L is given into a CNF
grammar for L.
y As the parse trees of a Chomsky-normal form grammar are binary
trees, if w is of length n then there will be exactly 2n-1 nodes labelled
by variables in the tree.
y The number of possible trees and node-labellings is thus only
exponential in n. List them all and check if any of them yields w.
Note:
There is much more efficient technique based on the idea of dynamic
programming, known as table filling algorithm or tabulation.
This algorithm is CYK algorithm; used to test membership in a context
free language.
177
Chapter 4
and |vy| ≥ 1
Such that
uvi xyiz ∈ L
for all i = 0, 1, 2, …
This is known as the pumping lemma for context-free languages.
Note:
Pumping lemma for context free language are used negatively to show
that a given language does not belong to context free language family.
178
Chapter 4
such that
w ∈ L with |w| ≥ m
w = akbkck
Here 3k ≥ m
Now, split akbkck in uvxyz.
|vxy| = k + 1 ≤ m
Hence, uvixyiz ∈L ∀ i = 0, 1, 2, …
for i = 2, ak–1 a2 bk ∈ ck
⇒ ak+1 bk ck which does not belong to given language
\ L = {anbncn | n ≥ 0} is not context-free language.
Note:
If Σ = {a} i.e. singleton set and language L is defined over L then Lis context free language
if and only if the length of strings in L are in arithmetic progression.
eg. 1: L = {a3n-1| n ≥ 1}
={aaaa, aaaaaaa, ........}
context free language. (Following arithmetic progression)
eg. 3: L ={an2In ≥ 1}
={a, aaaa, .........}
Not context free languages (Not following arithmetic progression)
eg.4: L={an1In ≥ 1}
={a, aa, aaaaaa, ........}
Not context free langauge (Not following arithmetic progression)
179
Chapter 4
Definition
The definition shows clearly that this grammar is non contracting in the sense
that the length of successive sentential forms can never decrease.
All such grammars can be rewritten in a normal form in which all productions
are of the form:
xAy → xvy
This is equivalent to saying that the production
A→ v
can be applied only in the situation where A occurs in a context of the string x
on the left and the stringy on the right.
eg. : S → abc/aAbc
Ab → bA
Ac → Bbcc
bB → Bb
Context-Free Language and Pushdown Automata
Context-sensitive languages:
The language generated by the context-sensitive grammar is known as
context-sensitive languages.
Definition
180
Chapter 4
allowed so that a context-sensitive grammar can never generate a
language containing the empty string.
y Every context-free language without ∈ can be generated by a special
case of a context-sensitive grammar, say by one in Chomsky or
Greibach’s normal form. Both satisfy the condition of context-free
grammar defined earlier.
Note:
By including the empty string in the definition of a context sensitive
language. We can claim that the family of context free language is a
subset of the family of context sensitive languages.
Note:
The language in the previous example is not context free, we can say
that the family of context free languages is a proper subset of the
family of context sensitive languages.
181
Chapter 4
Example 2 : T
he language L={anbmcndm |n,m ≥ 1} is a Context-Sensitive
language. Context-Sensitive grammar exists for this language
is:
S → aAB | aB
A → aAX | aX
B → bBd | bYd
Xb → bX
XY → Yc
Y → c
Derivation of string aabbbccddd as follows:
S ⇒ aAB
⇒ aaXB
⇒ aaXbBd
⇒ aaXbbBdd
⇒ aaXbbbYddd
⇒ aabXbbYddd
⇒ aabbXbYddd
⇒ aabbbXYddd
⇒ aabbbYcddd
⇒ aabbbccddd
182
Chapter 4
Theorem:
For every Context-Sensitive language L not including ∈, there exists some
linear bounded automaton M such that L = L(M).
Theorem:
If a language L is accepted by some linear bounded automaton M, then
there exists a Context-Sensitive grammar that generates L.
Theorem:
Every Context-Sensitive language is recursive.
Theorem:
There exists a recursive language that is not Context-Sensitive.
Note:
183
Chapter 4
Which one of the following language over Σ = {a, b} is NOT context free?
(GATE (CSE) -2019)
1) {wwR I W∈{a, b}*}
2) {wanbnwR Iw∈{a, b}*, n ≥ O}
3) {wanwRbn Iw∈{a, b}*, n ≥ O}
4) {anbi |i ∈{n, 3n, 5n}, n ≥ O}
Sol: Option 3)
Note:
The family of context sensitive language is not closed under
Homomorphism.
Context-Free Language and Pushdown Automata
Intersection No No Yes
Set-difference No No Yes
184
Chapter 4
Kleene closure No Yes Yes
Homomorphism No Yes No
185
Chapter 4
Chapter Summary
186
5 Turing Machine
Chapter 5
5.1 BASICS OF TURING MACHINE
Introduction:
y A Turing machine is a control unit with a finite number of states and
unbounded tape(s).
y Although, the Turing machine seems to be very simple from the
structural point of view, it is as powerful as simple it looks.
y There are so many problems that are unsolvable by push down
automaton. Such problems are solved using a Turing Machine.
y According to the Turing thesis, the only general type of automaton
whose power almost matches with a computer is nothing but the
Turing machine.
Where
Q is the set of finite states,
∑ is the set of input alphabets,
Γ is a finite set of symbols called the tape alphabet,
δ is the transition function, defined as
δ: Q × Γ → Q × Γ × {L, R}
where L = left movement & R = right movement,
B ∈ Γ is a special symbol called the blank,
Turing Machine
187
Chapter 5
SOLVED EXAMPLES
Sol:
Transition diagram
Turing Machine
188
Chapter 5
The transition means q0 by getting ‘a’; it is replacing ‘a’ with
‘X’ & going to state q1 and read-write head move one cell right.
We can even give transition table for L = anbn/n ≥ 1 as shows below:
δ(q0, a) → (q1, X, R)
δ(q0, Y) → (q3, Y, R)
δ(q1, a) → (q1, a, R)
δ(q1, Y) → (q1, Y, R)
δ(q1, b) → (q2, Y, L)
δ(q2, a) → (q2, a, L)
δ(q2, Y) → (q2, Y, L)
δ(q2, X) → (q0, X, R)
δ(q3, Y) → (q3, Y, R)
δ(q3, B) → (q4, B, L)
If the string will be in language then it will get accepted and halt at state q4
otherwise it will either go dead state or dead configuration.
Note: The transition table and transition diagram both are equivalent in power.
Sol:
Transition diagram
Turing Machine
189
Chapter 5
δ(q0, Y) → (q4, Y, R)
δ(q4, Y) → (q4, Y, R)
δ(q4, Z) → (q4, Z, R)
δ(q4, B) → (qf, B, L)
δ(q1, b) → (q2, Y, R)
δ(q1, a) → (q1, a, R)
δ(q1, Y) → (q1, Y, R)
δ(q2, b) → (q2, b, R)
δ(q2, Z) → (q2, Z, R)
δ(q2, c) → (q3, Z, L)
δ(q3, b) → (q3, b, L)
δ(q3, Z) → (q3, Z, L)
δ(q3, Y) → (q3, Y, L)
δ(q3, a) → (q3, a, L)
δ(q3, X) → (q0, X, R)
Transducer:
This is a more general automaton,which is able to produce strings of symbols as output and
it is called a transducer.
SOLVED EXAMPLES
Sol:
Turing Machine
190
Chapter 5
Sol:
Note: Always, the read-write head of Turing machine will point to starting of the input.
Sol: Ex.: 3 + 4 can be represented as input tape as BB00010000BB and the output will
be BB0000000BB.
So, it is the same as a concatenation of two numbers.
191
Chapter 5
Note:
Sol:
Turing Machine
192
Chapter 5
Rack Your Brain
1) For ∑ = {0, 1}, design a Turing machine that accepts the language
denoted by the regular expression 00*.
2) What language is accepted by the Turing machine whose transition
graph is in the figure below?
Computable:
The necessary condition of Turing computable or computable for a function
with a given domain is, there should be some Turing machine M(Q, ∑, Γ, δ,
q0, B, F) such that,
Turing Machine
193
Chapter 5
Halting problem:
y There are some Turing machines which never halt. It may go into infinite
loop.
Example:
y In a Turing machine, the not halting issue i.e whether the TM is ever
halted or not, which is commonly known as the halting problem.
y This type of problem does not occur either in Finite Automata and
Pushdown Automata because there we have only one move in a forward
direction.
y So, when input gets over, either the FA or PDA will definitely halt, but in
the case of TM it can go either forward or backwards.
y Anyway, this option will not add extra power to the automaton.
194
Chapter 5
Turing machines with semi-infinite tape:
y The tape is bounded only in one direction.
y Let’s visualize a tape with a left boundary.
195
Chapter 5
δ : Q × Γ → Q × Γ × {L,R,U,D}
where, U represents the up movement of the read-write head and D represents the down
movement.
Turing Machine
196
Chapter 5
Jumping turing machine:
y In this jumping TM, instead of moving just one step ahead either to the
left or to the right, it can move many steps in one go.
y Here, the δ is given below
δ : Q × Γ → Q × Γ × {L,R} × {n}
↑
Here, ‘n’ number of steps.
y This jumping TM is also equivalent in power to standard TM.
Multihead TM:
y This modified TM have more than 1 read-write head.
y Multiple heads simultaneously look after the scanned symbol and make
the needful, i.e. move or write onto the tape independently.
y A Single head Turing machine can simulate a multi head Turing machine.
197
Chapter 5
Where
Q = finite set of internal states
∑ = finite set of input alphabets
Γ = Finite set of symbols or tape alphabets
δ = the transition function
δ : Q × Γ → 2QxΓ×{L,R}
Note: A NPDA with one extra independent stack. The δ is given below:-
δ: Q × (U{∈}) × Γ × Γ 2Q×Γ*×Γ*
This is also equivalent to standard TM.
Multistack machines:
y The tapes of a multi tape Turing machine in such a way, that it starts
behaving like a stack.
y A one-stack machine is a DPDA, while a machine with two stacks is a
Turing Machine
Turing Machine.
198
Chapter 5
Grey Matter Alert!
199
Chapter 5
Γ = {a , a ,......,a },
1 2 m
Fig. 5.6
Note:
y It follows from this that any turing machine has a finite encoding as
a string on {0,1}+ and that, given any encoding of M, we can decode it
uniquely.
y But any combination of strings will not represent any Turing machine
(e.g. the string 00011).
Turing Machine
200
Chapter 5
Working procedure of universal turing machine:
y The encoded definition of M will be kept in the tape 1, given an input M
and w.
y The tape symbols of M will be placed in the tape 2 and tape 3 will
contain the states of M.
y The universal Turing machine identifies the configuration of M by looking
at the tape 2 and tape 3.
y The tape 1 will help for the transition by seeing tape 2 and tape 3.
y Finally, the changes will be reflected on the tape 2 and tape 3, the
results will be reflected in tape 2.
y As it can be implemented using any programming language, we can
implement the same using any standard Turing machine also.
A single tape Turing Machine 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. (GATE-2003)
201
Chapter 5
Note:
y FA + tape = FA + 2stack = FA + queue = TM
y TM = FA+ 2 stack
= FA +3 stack
= FA + 4 stack
.
.
.
= FA+ n stack (n ≥ 2)
Recursively enumerable:
y To ensure a language L is recursively enumerable, we have to find a
Turing machine for it.
y Recursive Enumerable can be defined as a Turing machine M, where, for
every w ∈ L,
q0w |-*M x1 qf x2,
with qf a final state.
y If string w is not in the language, then the definition doesn’t say whether
it will go in a non-final state and halt or it may go into an infinite loop.
Fig. 5.7
Recursive language:
1) A formal language for which a standard Turing machine exists, i.e., any
Turing Machine
strings from that language will be accepted by the Turing machine and
the machine halts as well is called recursive language.
202
Chapter 5
2) “The Turing machine that always halt is called Halting TM/decider/Total
Turing machine.”
Fig. 5.8
Conclusion
Fig. 5.9
203
Chapter 5
Chomsky hierarchy:
1) All formal languages are divided into 4 classes by Chomsky and those
class hierarchy known as “Chomsky Hierarchy”.
Fig. 5.10
Note:
Recursive language is not type (0) language. Only recursively enumerable
language is type (0) language.
Turing Machine
204
Chapter 5
Extended Version of Chomsky Hierarchy:
Fig. 5.11
Turing Machine
Fig. 5.12
205
Chapter 5
Theorem 1:
“If a language L and its complement L are both recursively enumerable
then both languages are recursive.”
Theorem 2:
“If L is recursive, then L is also recursive and consequently both are
recursively enumerable.”
Ex.: S → S1B
S1 → aS1b
bB → bbB
aS1B → aa
B→∈
Closure properties of Recursive and Recursive Enumerable Language
Turing Machine
206
Chapter 5
l
Theorem 1:
“For all recursive language ‘L’ there is an enumeration technique for it.”
Proof:
m
Turing Machine
Fig. 5.13
207
Chapter 5
~
If the alphabet is {a, b} then M enumerate strings as follows:
‘a’
‘b’
‘aa’
‘ab’
‘ba’
‘bb’
‘aaa’
‘aab’
…
Enumeration Procedure
Repeat:
~
M generates a string w
M checks if w ∈ L
Yes: Print w to output
No: Ignore w
End of proof.
~
M L(M) Enumeration Output
b b b
aa
ab ab ab
ba
bb bb bb
aab
208
Chapter 5
Note:
Theorem 2:
“A language is recursively enumerable if and only if there is an enumeration
procedure for it.”
209
Chapter 5
y If we limit the Turing machine to use only finite amount of cell and only
unidirectional tape movement is allowed then it can converges into
finite automata.
y If we limit tape of Turing machine to use only that part of the tape
where the input is present and not beyond it, then it converge to LBA
(Linear Bounded Automata).
y A linear bounded automata is designed with an unbounded tape. It
extents up to which the tape needs to be made use of purposely, with
an instant of the input. Practically, the unbounded tape is restricted by
the input string.
y To enforce this, we can envision the input as bracketed by the two
special symbols, the left-end marker and the right-end marker.
y LBA is less powerful than TM and it is more powerful than PDA. Ex.:
anbncn | n ³ 1 is accepted by LBA but not by PDA.
y Here, we don’t know whether the deterministic LBA are equivalent in
power to non-deterministic LBA. It is undecidable.
y Complement of the CFL is CSL.
y Language accepted by LBA is called context sensitive language.
y LBA is halting, Turing machine as context sensitive language is also a
recursive language.
Countability
210
Chapter 5
Hence, the set of odd number is countable.
Uncountable set definition: “A set is uncountable if it is infinite and not
countable.”
Output : 0 2 4 6 8 ...
Steps : 1 2 3 4 5 ...
Output : 1 3 5 7 9 11 ...
Steps : 1 2 3 4 5 6
Turing Machine
211
Chapter 5
SOLVED EXAMPLES
Sol: T he set S is countable since we are having an enumeration procedure for set S.
ere, we don’t go either in increasing order of numerator or denominator, we just
H
add numerator and denominator and we just go in the increasing order of sum.
Here, the smallest number is 1/1.
So, the 1st sum is 2.
Within the sum we can enumerate in increasing order.
1 1 2 1 2 3
So, the enumeration order is , , , , , , ...
1 2 1 3 2 1
Hence, it is countable.
Lexicographic ordering:
y Lexicographic ordering is nothing but the alphabetical order, i.e., the sequence of letters
present in the dictionary.
y Suppose we have a set S = {a, b} and S* in lexicographical order will be {∈, a, b, aa, ab,
ba, bb, aaa, aab, …}
Note:
y Set of all string possible over any alphabet is countable.
y So, Σ* = set of all string over Σ is countable.
y Every subset of countable set is either finite or countable.
y Since every language is a subset of Σ*. Therefore, every language is countable.
y It means given any language it is definitely either countable language or finite language.
Turing Machine
212
Chapter 5
Sol: Since every Turing machine can be encoded as a string of 0’s and 1’s.
Let S = {0, 1} then S* = set of all strings over {0, 1}.
Since, S* is countable and T is subset of S*.
Hence, T = set of all Turing machines.
Implication of the fact that the set of all turing machines are countable:
y Since we know that the set of Turing machines are countable, then the set of recursively
enumerable language are also countable.
y Since the set of recursive language is subset of the set of recursively enumerable
language. Hence, a set of recursive languages is countable.
y Similarly, a set of context free language, a set of context sensitive language, and the set
of regular language are also countable.
y We can also modify a turing machine in such a way that it can act as
PDA. Therefore, if set of TM is countable it implies that the set of PDA is also countable.
y Since, all machines are subset of set of Turing machine. So, the set of LBA, and set of
FA are also countable.
Turing Machine
Fig. 5.14
213
Chapter 5
Theorem:
“set of all languages are uncountable”.
Proof:
Suppose there is a set S = {a, b}.
We need to prove that, 2S* is uncountable.
Let us assume, 2S* is countable.
As, S = {a, b}
S* = {∈, a, b, aa, ab, ba, bb, aaa, aab,....}
Note:
This kind of argument, because it involves a manipulation of the diagonal
elements of a table is called diagonalization.
Turing Machine
214
Chapter 5
Note:
Theorem:
“There exists a recursively enumerable language whose complement is not
recursively enumerable.”
Theorem:
“There exists a recursively enumerable language that is not recursive i.e., the
family of recursive languages is a proper subset of the family of recursively
enumerable languages.”
y Diagonalization method is used to prove that a language is not
recursively enumerable because if for a language, we proved that it
is not countable then it means there is no enumeration procedure for
that language.
And theorem says that a language is Recursive Enumerable Language if
and only if there is enumeration procedure for it. Hence, that language
is not recursively enumerable.
Theorem:
“If S1 and S2 are countable sets, then S1 U S2 and S1 × S2 are countable and
union and cross-product can be extended to any number of finite sets.”
Theorem:
“The set of all languages that are not recursively enumerable is uncountable.”
Proof:
The set of all languages is 2S* (set of all subsets of S*), and out of that some
languages are already recursive enumerable, because if there is TM for a
language then that language is recursively enumerable and we already know
that the number of TM is countable. Therefore, the number of languages in
the total language which is recursively enumerable are countable and that
will be equal to a number of Turing machines.
And in the remaining set, we don’t know anything, so we are just assuming
that it is countable. So, the resulting set is the union of a countable set;
therefore overall, that should be countable. And if that is true, then our
*
initial proof that 2Σ is uncountable is a failure as we know that set of
*
all languages 2Σ is uncountable. Therefore, our assumption that, the
remaining language i.e., the set of all languages that are not- recursively
enumerable is countable, is false. So, set of all languages which are not
recursively enumerable, must be uncountable.
Turing Machine
215
Chapter 5
216
Chapter 5
Grey Matter Alert!
Function
y If f denotes a function, then the first set is called the domain of f and the second
set is its range. We write
f : S1 → S2
to indicate that the domain of f is a subset of S1 and that the range of f is a subset
of S2.
y If the domain of f is all of S1, we say that f is a total function on S1, otherwise f is
said to be a partial function.
Turing Machine
217
Chapter 5
SOLVED EXAMPLES
Sol: 1) E xplanation: It is a CSL because we can give a linear bound automata. We cannot
compare number of X’s and number of Y’s using one stack here.
Turing Machine
218
Chapter 5
Sol: 2) E xplanation: Statement S1 is incorrect because set of all irrational number are
uncountable.
Statement S2: Since L is finite language. So, it is regular. All regular language
are recursively enumerable language and recursively enumerable language are
closed under Kleene closure. Hence, L* is recursively enumerable language.
Sol: 3) Explanation:
S1 : L2 − L1 =
L2 L1
= REL Rec L
= REL Rec L
= RE L.
So, statement S1 is correct.
S2 : L = {wwwk | w∈ (a, b)+} is CSL because for this we can give a LBA.
It needs more than one stack to accept this language L, so it is CSL.
Turing Machine
219
Chapter 5
Sol: 3) Explanation:
L = (L2 L1 ) − L3
= (Rec L REL) − CFL
= (Rec L ∩ REL) – CFL
= REL (CFL)
= REL ∩ CSL = REL.
[Here, Rec L means recursive language,
REL means recursively enumerable language,
CFL means context free language,
Turing Machine
220
Chapter 5
Sol: 1) Explanation: The given grammar is in the form of u → v
where u belongs to (V+T)+ v belongs to (V+T)*
here, V is set of non-terminals and T is set of terminals
Hence, it is unrestricted grammar or type-0 grammar.
Sol: 1) E xplanation:
Recursively enumerable language is not closed under
“complementation” and it is closed under “union”, “intersection”, “concatenation”,
etc.
Sol: 1) E xplanation: In the definition of Turing machine, ‘Q’ represents the “Set of finite
number of states”. Turing Machine
221
Chapter 5
Chapter Summary
222
y Unrestricted Grammar/Type 0 Grammar: A grammar is called unrestricted if all Chapter 5
the productions are of the form X → Y
y where X is in (V + T)+ and Y is in (V + T)*
[Here, V indicates set of variables and T indicates set of terminals]
y Closure Property of Recursive and Recursively Enumerable Language
Turing Machine
223
Chapter 5
y Linear Bound Automata: If we limit the tape of the Turing machine to use only
where the input is present and not beyond it, then it converges to LBA.
y In LBA, whether deterministic LBA is equivalent to non-deterministic LBA is not
known.
y Language accepted by LBA is called context-sensitive language.
y Countable Set: If there persists a one-to-one mapping from the elements of a set
to the set of positive integers, such a set is classified as countable.
y Uncountable Set: A set S is uncountable if it is infinite and not countable.
Turing Machine
224
Chapter 5
y Set of all languages possible is uncountable.
y There exists a recursively enumerable language whose complement is not
recursively enumerable.
y There exists a recursively enumerable language that is not recursive i.e., the family
of recursive language is a proper subset of the family of recursively enumerable
language.
y If S1 and S2 are countable sets, then S1 U S2 and S1 × S2 are countable, and union
and cross-product can be extended to any number of finite sets.
y The set of all languages that are not recursively enumerable is uncountable.
Turing Machine
225
6 Decidability
Chapter 6
What is a decision problem:
A decision problem is a set of related statements, each of which must be
either true or false.
For example:
“For context-free grammar (G), the language L(G) is ambiguous or not?
For some context-free grammar (G), this is true, and for some, it is false.
But we can clearly say that the statement is either true or false.
Basically, we have two kinds of problems:
Fig. 6.1 Decidability
Note:
y For decidable problem, the Halting Turing Machine (HTM) exist.
y For undecidable problem\s, the Halting Turing Machine (HTM) does
not exist, but Turing Machine (TM) may or may not exist.
y If a problem is not recursive enumerable (RE), then no Turing Machine
exists for that problem.
Language:
The set of all strings that can be generated from the grammar.
Language can be finite or infinite. If a language consists of a finite number
Decidability
227
Chapter 6
Fig. 6.2
Example:
Consider a String w and a language L
1) If
For both the cases, we have logic, then the language is decidable.
2) If
Logic exists for valid strings. So, the language is Recursively Enumerable
but not Recursive.
3) If
For both the cases, we do not have logic, then the language is not
Recursively Enumerable.
Encoding a turing machine (TM):
Each Turing Machine with input alphabet {0, 1} may be thought of as a
binary string.
To represent a Turing Machine (M)= (Q, Σ, Γ, δ, q,B,F) as a binary string where
Decidability
Σ ={0, 1} .
228
Chapter 6
First, assign integer to the tape symbols, states and directions Left (L) and Right (R).
Let the states be: q1, q2, q3, q4 …qk.
Here q1 is a Starting state, q2 is a Final State and q3, q4 … qk are other states.
Let tape symbols are: X1, X2, X3, …Xm.
X1 = 0
X2 = 1
X3 = B (Blank)
Let the direction left be D1 and the direction Right be D2.
δ(qi , X j ) =
(qk , Xl ,Dm ) for some integers i, j, k, l and m.
Now, code this rule by the string- 0i10j10k10l10m
where i, j, k, l, m should be greater than 0 (i, j, k, l, m > 0).
There should not be two consecutive 1’s within the code for a single transition.
The code for the entire Turing Machine will be:
Q1 11 Q2 11 Q3 11 … Qn
Each transition is separated by two consecutive 1’s and Q1,Q2…Qn are the transition of Turing
Machine.
Example:
Consider the Turing Machine (TM)
M = ({q1, q2, q3, q4, q5}, {0, 1}, {0, 1, B}, δ , q0, B, {q2})
where δ consists of the rules:
δ(q1 ,B) =
(q5 ,B,L)
δ(q4 , 1) =
(q3 ,B,R)
δ(q5 ,B) =
(q4 , 1,R)
δ(q3 , 1) =
(q2 , 1,L)
229
Chapter 6
Ld = {w ∈ (0 + 1)
i
+
}
| wi ∉ L(Mi )
Let,
∑ ={a,b}
*
And we know, ∑* is countable; now we must prove 2∑ is uncountable.
Prove by contradiction:
*
Let 2∑ is countable and it has one-one mapping.
We know,
Σ* =∈, a,b, aa, ab,ba,bb, aaa
Let,
L1 = {∈, a}
L2 = {a,b}
= {∈, a, aa}
Decidability
L3
230
Chapter 6
L4 = {b, ab,ba}
L5 = {aa,ba,bb}
231
Chapter 6
Case 1:
A Turing machine will necessarily halt for strings that are not inclusive to a
given language. However, it may or may not enter into an accepting state.
Case 2:
Let us consider a scenario where recursively enumerable languages are
involved. The Turing machine will necessarily halt if the input string is
inclusive to the language. However, for excluded input strings, the Turing
machine may get inter-wined into an infinite loop or halt.
Recursive languages:
A recursive language L If L = L(M) for some Turing Machine (M) such that:
1) w ∈ L ⇒ Halts and accepts
2) w ∉ L ⇒ Halts and rejects
Note:
Recursive language is always decidable. If language is not recursive, then
it is undecidable/semi decidable.
232
Chapter 6
Fig. 6.4 Relationship between recursive and RE and not RE languages
Note:
The Recursive languages are closed under complement.
M is guaranteed to halt. So, we can say M1 will also halt. M1 accept only
those strings that M will never accept.
233
Chapter 6
complement of L (L ) .
If both the language L and its complement are Recursive Enumerable (RE),
then language L is Recursive.
Proof as consider:
M1 and M2 are Turing Machines which are simulated in parallel by a Turing
Machine (M).
Let,
L = L(M1) and L = L(M2 )
We can make Turing Machine (M) a two-tape Turing Machine and then it is
converted into a single tape Turing Machine for simplicity.
Tape one of the Turing machines (M) simulate the tape of M1, while tape two
of the Turing machine (M) simulate the tape of M2.
If
Input w ∈ L(M) → M1 will accept → M accepts and halts
Thus, for all inputs, M halts, and L(M) is the same as L. Since M always halts, and
L(M) = L. So, we can say that L is Recursive.
Decidability
234
Chapter 6
Turing machine halting problem:
“Does a Turing Machine (M) halt on input w?”
OR
“Is w ∈ L(M)?”
We know that Turing Machine has three possibilities.
D ⇒ Decidable
UD ⇒ Undecidable
235
Chapter 6
Note:
y For Regular Languages, all the given problems are decidable.
y For Recursive Enumerable Language (REL), all given problems are
undecidable.
Definitions
Examples:
• {<M>|M has 15 states}
This is a Property of Recursive Enumerable Language (REL) but not a
language.
• {<M>|L(M) is infinite}
• {<M>|L(M) is regular.}
Trivial property:
A property is trivial if it is satisfied by all Recursive Enumerable Languages
or it is not satisfied by any Recursive Enumerable Language (REL).
• If all the elements of the Recursive Enumerable Language (REL) set have
the property → Trivial property
Decidability
236
Chapter 6
• If all the elements of the Recursive Enumerable Language (REL) set do
not have the property → Trivial property
Non-trivial property:
A property is non-trivial if it is satisfied by some Recursive Enumerable
Languages (REL) and are not satisfied by others.
• If at least one Recursive enumerable language (REi) has the property and
one Recursive enumerable language (REi) does not have the property,
then the property is said to be non-trivial.
Example:
=L {W | W ∈ 1 *}
Let’s find a REj that does not have the property:
{L(REj) is finite}
REj_NO = {1},
Turing Machine accepts language,
=L {W | W ∈ 1}
∴ Hence, we can find REi_YES (REi that has the property) and REi_NO(REi
that does not have the property).
Hence, it is a Non-Trivial property of Recursively Enumerable Language. So,
by Rice Theorem, we can say that the language is undecidable.
even semi-decidable.
237
Chapter 6
Note:
y Recursive ⇒ Decidable
y Semi decidable ⇒ Recursive Enumerable but not REC.
This theorem is used for proving if the language is not semi-decidable (Not
Recursive Enumerable).
Let’s discuss the non-monotonic properties.
A property of recursively enumerable language is non-monotonic if any set
(REi) having the property is PROPER SUBSET of any set (REj) that does not
have the property.
Example:
238
Chapter 6
Example:
L = {<M>|L(M) is infinite}
This is monotonic property since an infinite set can never be a subset of a
finite set. So, we cannot apply Rice Theorem Part-II here.
We can use reduction to prove language is not Recursive Enumerable (RE).
It proves RICE Theorem Part-II is not the necessary condition for language
to be NOT Recursive Enumerable (RE). It is a sufficient condition.
Reducibility:
Let us have two problems, A and B. If we have an algorithm to convert
instance of problem A to instance of problem B that have the same answer,
then we say
A reduces to B
or
A is polynomially reduced to B
or
A is many to one reducible to B
or
A ≤B
or
A ∝p B
or
A ≤m B
or
B is at least as hard as A.
Let, L 1 ≤ L2
Decidability
239
Chapter 6
240
Chapter 6
Note:
Decidability
241
Decidability Chapter 6
242
Chapter 6
SOLVED EXAMPLES
Sol: 3 to 3
Explanation:
All the statements is correct.
Recursive language is called decidable language because, for
the recursive language, we have halting Turing Machines.
For recursively enumerable language, we have a Turing machine
and Turing machine may or may not halt, but TM always halts for
string belongs to the language.
Hence, Recursively enumerable languages are semi-decidable.
Partially decidable and semi decidable means the same only.
Decidability
243
Chapter 6
Sol: d)
CFL are decidable on membership problem, emptiness problem, finiteness
problem because we have analgorithm for all the problems.
Push down automata or CYK is analgorithm for membership problems.
For Emptiness problem algorithm is the simplification of CFG.
The Dependency tree lets us know whether the grammar is finiteness or not.
Hence, d) is the correct option.
Chapter Summary
y Decision problem:
A decision is a set of related statements, each of which must be either true or
false.
i) For decidable problems, Halting Turing Machine (HTM) exists.
ii) For undecidable problem, Halting Turing Machine (HTM) does not exist, but
Turing Machine (TM) may exist.
iii) If a problem is not recursive enumerable (RE), then no Turing Machine exists for
that problem.
Decidability
244
Chapter 6
y Language:
The set of all strings that can be generated from the grammar.
Fig. 6.10
Ld = {w ∈ (0 + 1)
i
+
}
| wi ∉ L(Mi )
y Recursive languages:
A recursive language L If L = L(M) for some Turing Machine (M) such that:
1) w ∈ L ⇒ Halt and accept
2) w ∉ L ⇒ Halt and reject
245
Chapter 6
y Trivial property:
A property is trivial if either it is satisfied by all Recursive Enumerable Languages
or it is not satisfied by any Recursive Enumerable Language (REL).
Decidability
246
Chapter 6
y Non-trivial property:
A property is non-trivial if it is satisfied by some Recursive Enumerable Languages (REL)
and are not satisfied by others.
y Reducibility:
Let us have two problems, A and B. If we have an algorithm to convert an instance of
problem A to instance of problem B that has the same answer, then we say A reduce
to B
Decidability
247