Vous êtes sur la page 1sur 12

MAY 2019 examination (Subject Code: 41005) Model Answer Key

SEIT SEM 4 Automata Theory

Q. Sub Answer Marking


No. Q. Scheme
No.

1 Solve any four 20


marks

a Construct Moore machine equivalent to following Mealy machine. 5M

0
Converting to Moore machine
1. There are 2 incoming transitions to q0
- q0 to q0 on input 1 with output n
- q2 to q0 on input 1 with output n q₁ / n
Since output is same, no need to split 1
0
2. There are 3 incoming transitions to q1
- q0 to q0 on input 0 with output n
- q1 to q1 on input 0 with output n q₀ / n
0 1
- q2 to q1 on input 0 with output n
Since output is same, no need to split
3. There is 1 incoming transition to q2 1
- q1 to q2 on input 1 with output y
No need to split q₂ / y

b Construct a PDA for the following CFG 5M


S → CBAA A → 0A0 | 0 B → 0B | 0 C → 0C1 | 1C0 | ε

Converting CFG to GNF


Let D → 0, and E → 1
Now, C → 0CE | 1CD | ε
B → 0BD | 0
A → 0AD | 0
S → 0CEBAA | 1CDBAA | BAA
Therefore, S → 0CEBAA | 1CDBAA | 0BAA | 0AA

Grammar in GNF
S → 0CEBAA | 1CDBAA | 0BAA | 0AA
A → 0AD | 0
B → 0BD | 0
C → 0CE | 1CD | ε
D→0
E→1
1, E; ε
0, D; ε
ε, C; ε
1, C; CD
0, C; CE
0, B; ε
0, B; BD
0, A; ε
0, A, AD
0, S; AA
0, S; BAA
1, S; CDBAA

c Construct right linear grammar and left linear grammar for the regular 5M
expression 1(01)*0(0+1)*

Left linear grammar Right linear grammar


S → S0 | S1 | A S → 1A
A → B0 A → 01A | B
B → B01 | C B → 0C
C→1 C → 0C | 1C | ε

d Explain the concepts, acceptance by final state and acceptance by empty 5M


stack of a Pushdown automata with suitable example.

A Pushdown Automata (PDA) can be defined as :


• Q is the set of states
• ∑ is the set of input symbols
• Γ is the set of pushdown symbols (which can be pushed and popped
from stack)
• q0 is the initial state
• Z is the initial pushdown symbol (which is initially present in stack)
• F is the set of final states
• δ is a transition function which maps Q x {Σ ∪ ∈} x Γ into Q x Γ*. In a
given state, PDA will read input symbol and stack symbol (top of the
stack) and move to a new state and change the symbol of stack.

Acceptance by Empty Stack


Lets consider pushdown automata for language {anbn | n > 0}
The PDA is given by
δ( q0, a, Z ) = { ( q0, AZ ) }
δ( q0, a, A) = { ( q0, AA ) }
δ( q0, b, A) = { ( q1, ∈) }
δ( q1, b, A) = { ( q1, ∈) }
δ( q1, ∈, Z) = { ( q1, ∈) }
This PDA accepts the input on empty stack.
This type of acceptance is known as acceptance by empty stack.

Acceptance by Final State


The language accepted by PDA, P is the set of all strings consuming which
PDA can move from initial state to final state irrespective to any symbol left on
the stack which can be depicted as:
L(P) = {w |(q0, w, Z) =>(qf, ɛ, s)}
Here, from start state q0 and stack symbol Z, final state qf ɛ F is reached
when input w is consumed. The stack can contain string s which is irrelevant
as final state is reached and w will be accepted.
Pushdown automata for language {anbn | n > 0} using acceptance by final
state is given by:
δ( q0, a, Z ) = { ( q1, AZ ) }
δ( q1, a, A) = { ( q1, AA ) }
δ( q1, b, A) = { ( q2, ɛ) }
δ( q2, b, A) = { ( q2, ɛ) }
δ( q2, ɛ, Z) = { ( q3, Z) }
Here the input is accepted based on whether the PDA reaches its final state or
not, irrespective of the stack being empty or not.

e Construct regular expression for the following FA using state elimination 5M


method.

Eliminating q1
a
a.b*.a

q₀ q₂

b.b*.b
a.b b.a
No more elimination possible.
The R.E. is
((a + ab) + ab*a . (ba)* . bb*b)* . ab*a . (ba + bb*b . (a + ab)* . ab*a)*

2 20
marks

a Write down regular expressions for the following language. 4M


i. L is the language of all strings over {0,1} having odd number of 0’s
and any number of 1’s.
ii. L is the language of all strings over {0,1} having number of 1’s
multiple of three.

i) RE
1*0(1+01*0)*
1 1 0
0
0
0
q₁
q₀ q₁
q₀ 1 1 q₂
0
1
ii) RE
(0 + 10*10*1)*
0
0 0
0 0
q₁ 10*1

q₀ 1 1 q₂ q₀ q₂

1
1
b Construct DFA for following NFA with ε-moves 10 M

ε-closure
State ε-closure
q0 {q0, q1}
q1 {q1}
q2 {q2, q3}
q3 {q3}

New transition table


States 0 1
→ q0 {q1} {q0, q2}
q1 {q1} {q2}
* q2 {q3} {q2, q3}
q3 {} {q2, q3}

NFA without ε-moves


0

1
0 q₁
1
q₀ q₃
1 0, 1

1
q₂ 1

NFA to DFA conversion by subset construction


DFA State 0 1
→ Q0 = {q0} {q1} = Q1 {q0, q2} = Q2
Q1 = {q1} {q1} = Q1 {q2} = Q3
*Q2 = {q0, q2} {q1, q3} = Q4 {q0, q2, q3} = Q5
*Q3 = {q2} {q3} = Q6 {q2, q3} = Q7
Q4 = {q1, q3} {q1} = Q1 {q2, q3} = Q7
Q5 = {q0, q2, q3} {q1, q3} = Q4 {q0, q2, q3} = Q5
Q6 = {q3} {} {q2, q3} = Q7
Q7 = {q2, q3} {q3} = Q6 {q2, q3} = Q7
The DFA
0

Q₁ Q₃ 1
1

0
0
Q₆ 0
0
Q₀

1 1 Q₇

1
Q₂ Q₄
0 1

1 0

Q₅

c Construct NFA with ε-moves for the regular expression ab*(a+b)* + ba* 6M

b a, b

q₁ q₂
ε

a
q₀
b q₃

OR

a
q₄ q₅
b
ε ε

ε ε
q₁ q₂ q₈
a
ε ε

q₀ q₆ q₇
b
b q₃

3 20
marks

a Convert the following CFG into Chomsky Normal Form. 10 M


S → A | C A → aA | a | B B → bB | b | ε C → cC | c | B

Step 1: Eliminate ε-productions


Nothing to be done

Step 2: Eliminate unit productions


Eliminating C → B
C → cB | cC | c
S→A|B|C

Eliminating A → B
A → aA | aB | a
S→A|B|C

Eliminating S → A
S → aA | aB | a

Eliminating S → B
S → bB | b | ε

Eliminating S → C
S → cB | cC | c | ε

Therefore, the grammar is


S → aA | aB | a | bB | b | cB | cC | c | ε
A → aA | aB | a
B → bB | b | ε
C → cB | cC | c

Step 3: Eliminate useless productions


There are none

Step 4: Re-write productions in CNF


Let X → a, Y → b, and Z → c

S → XA | XB | a |
YB | b |
ZB | ZC | c |
ε
A → XA | XB | a
B → YB | b | ε
C → ZB | ZC | c
X→a
Y→b
Z→c

b Construct a CFG for the following PDA. 10 M


Let ( => a, [ => b, ) => c, and ] => d

Consider V0A0
We have the following transitions where A is on top of the stack
(c, A; ε), (a, A; AA), (b, A, BA)
So we get,
V0A0 → c | aV0A0V0A0 | bV0B0V0A0

Consider V0B0
We have the following transitions where B is on top of the stack
(d, B; ε), (b, B; BB), (a, B; AB)
So we get,
V0B0 → d | bV0B0V0B0 | aV0A0V0B0
Consider V0Z1
We have the following transitions where Z is on top of the stack
(b, Z; BZ), (a, Z; AZ), (ε, Z; ε)
So we get,
V0Z1 → bV0B0V0Z1 | aV0A0V0Z1 | ε

Renaming V0Z1 by S, V0A0 by T, and V0B0 by U, we get


The final CFG
S → bUS | aTS | ε
U → bUU | aTU | d
T → aTT | bUT | c

4 20
marks

a Construct a PDA for 10 M

Push all a’s onto the stack (as A).


Change state on encountering b (no change to stack).
Pop one A for every c.
If stack is empty and there is atleast one c in the input, accept the string.

b Design a DFA over {0, 1} which accepts all strings that contain substring ‘11’ 6M
and do not contain the substring ‘00’.
c Give the CFG for the following languages 4M

i) 0n 1n+p+k 0k
S → XYZ
X → 0X1 | ε
Y → 1Y | 1
Z → 1Z0 | ε

ii) S → aaSd | A
A → bbbAc | ε

5 20
marks

a Construct Turing Machine to accept language L = { anb2n+1 | n ≥ 1 }. 10 M

q0 – replace the leftmost a with X, move right; for Y, move right


q1 – skip all a’s and Y’s, replace first b with Y, move right
q2 – replace 2nd b with Y, move left
q3 – skip all a’s and Y’s, move left; on reaching X, move right
q4 – skip all Y’s, on reaching b, go to final state
q5 – accepting state

b Find the equivalent NFA with ε-moves accepting the regular language defined 5M
by the following grammar
S → 01S | 0A A → 10 | 1B | 00A B → 1S | 1B | ε
OR

c Let G be the grammar having following set of production. 5M


S → ABA A → aA | bA | ε B → bbb
For the string “ababbbba”, find a leftmost derivation and rightmost derivation.

Leftmost derivation
S => ABA
=> aABA ; A → aA
=> abABA ; A → bA
=> abaABA ; A → aA
=> ababABA ; A → bA
=> ababBA ;A→ε
=> ababbbbA ; B → bbb
=> ababbbbaA ; A → aA
=> ababbbba ;A→ε

Rightmost derivation
S => ABA
=> ABaA ; A → aA
=> ABa ;A→ε
=> Abbba ; B → bbb
=> aAbbba ; A → aA
=> abAbbba ; A → bA
=> abaAbbba ; A → aA
=> ababAbbba ; A → bA
=> ababbbba ;A→ε

6 20
marks

a Minimize the following DFA M = ({q0, q1, q2, q3, q4, q5}, {0,1}, δ, q0, {q3, q5}), 6M
where δ is given in the following table.

The DFA is

Minimization by table filling method

q1 on 0
q2 on 0 ?
q3 fnf fnf fnf
q4 on 0 ? ? fnf
q5 fnf fnf fnf ? fnf
States q0 q1 q2 q3 q4

So, by merging states q1 – q2 - q4 and q3 – q5, we get


b Construct Turing Machine wherein given an input 1n leaves 13n+1 on the tape. 10 M
Convert the TM design into equivalent function.

q0 – replace leftmost 1 with X, move right; for Y, move left


q1 – skip all 1’s and Y’s, move right; replace blank with Y, move right
q2 – replace blank with Y, move left
q3 – skip all 1’s and Y’s, move left; for X, move right
q4 – skip all X’s, move left; for leftmost blank, move right
q5 – replace all X’s and Y’s with 1; for rightmost blank, write 1
q6 – final state

c What do you understand by closure property? State the various set theoretic 4M
operations under which regular languages are closed. Give suitable example.

Closure properties
Regular languages remain regular when set-theoretic operations are
performed on them. We call such behaviours closure properties since any
number of such operations keep the result still within the class of regular
languages.

The various set-theoretic operations under which regular languages are closed
are as follows:
1. Union of Regular Languages
Set of binary number divisible by 4 is a regular language.
Set of binary number divisible by 6 is a regular language.
Their union, set of binary number divisible by 4 and 6 is also a regular
language.

2. Concatenation of Regular Languages


The set of all strings over {a,b} that begin with aa is a regular
language: aa(a+b)*. The set of all strings over {a,b} that end with bb
is a regular language: (a+b)*bb. The concatenation is also a regular
language: aa(a+b)* . (a+b)*bb or just aa(a+b)*bb.

3. * Closure of Regular Languages


The set of all strings of length 3 over the alphabet {a,b} is a regular
language: (a+b).(a+b).(a+b). The set of all strings of length divisible
by 3 is also a regular language: ((a+b).(a+b).(a+b))*

4. Complement of Regular Languages


The set of all even binary numbers is a regular language: (0+1)*0. The
complement. Set of all binary numbers is also a regular language:
(0+1)*1.
5. Reversal of Regular Languages
The original language
(a+b)*ab(a+b)*c(ab)*
the reversal of the language is
(ba)*c(a+b)*ba
Both are regular.

6. Intersection of Regular Languages


Let L1 be the regular language of all strings over {a,b,c} containing at
least one a: (a+b+c)*a(a+b+c)*. Let L2 be the regular language of all
strings over {a,b,c} containing at least one b: (a+b+c)*b(a+b+c)*.
Their intersection is also a regular language:
(a+b+c)*a(a+b+c)*b(a+b+c)* + (a+b+c)*b(a+b+c)*a(a+b+c)*
7. Difference of Regular Languages
Σ*, being the closure of the alphabet, is a regular language. The
difference between this and any other regular language L, Σ* - L, is
nothing but the complement of the language L. Complement is a
regualr language.

Vous aimerez peut-être aussi