Kokkk
Kokkk
Q1 Q2 Q1
Q3
b,a; λ λ,z; λ
λ,z;z
a,z;aaaz b,a; λ
a,aaa ;aaaa
S → aABB|aAA,
A → aBB|b,
B → bBB|A
Solution;
,B;A
b,B;BB
b,A;
,z;sz ,z;
Q1 Q21 Q31
a,S;ABB
a,S;AA
a,A;BB
8. Find a context-free grammar that generates the language accepted by the NPDA
solution:
v={M,[q0Aq0],[q0Aq1],[q1Aq0],[q1Aq1], [q0zq0],[q0zq1],[q1zq0],[q1zq1]}
[q0,z,q0]=a[q0,A,q0][q0,z,q0] eliminated
[q0,z,q0]=a[q0,A,q1][q1,z,q0] eliminated
[q0,z,q1]=a[q0,A,q0][q0,z,q1] eliminated
[q0,z,q1]=a[q0,A,q1][q1,z,q1] X=aYZ
[q0,A,q0]=b[q0,A,q0][q0,A,q0] eliminated
[q0,A,q0]=b[q0,A,q1][q1,A,q0] eliminated
[q0,A,q1]=b[q0,A,q0][q0,A,q1] eliminated
[q0,A,q1]=b[q0,A,q1][q1,A,q1] Y=bkF
[q0,A,q1]=a Y=a
So ,the grammer is
X=aYZ
Y=bkF
Y=a
9. Construct a Turing machine that accepts the language L ={a^nb^nc^n,n>0?}
Step 1-2
Reach unmarked 'b' and pass every 'a' and 'Y'(in case) on the way to 'b'
Step 3-4
Reach unmarked 'c' and pass every 'b' and 'Z'(in case) on the way to 'c'
Mark 'c' as 'Z' and move one step left cause now we have to repeat process
Reach unmarked 'X' and pass every 'Z', 'b', 'Y', 'a' on the way to 'X'
Step 5-9
Step 10
When TAPE header reaches 'X' and next symbol is 'Y' that means 'a's are finished
Check for 'b's and 'c's by going till BLANK(in right) and passing 'Y' and 'Z' on the way
If no 'b' and 'c' are not found that means string is accepted
Following Steps:
Following Steps:
a. Mark 'c' with 'Z' and move towards first 'X' (in left)
b. Move towards first 'X' by passing all 'Z's, 'b's, 'Y's and 'a's
c. When 'X' is reached just move one step right by doing nothing.
To check all the 'a's, 'b's and 'c's are over add loops for checking 'Y' and 'Z' after "we get 'X' followed by
'Y'"
To reach final state(qf) just replace BLANK with BLANK and move either direction
10. Design a Turing machine that accepts the language L = {ww : w ∈ {a, b}+}
Step-1:
———————————————
Step-2:
If the symbol is 0 replace it by 0 and move right, remain on the same state
If the symbol is 1 replace it by 1 and move right, remain on the same state
———————————————
Step-3:
If the symbol is 0 replace it by 0 and move left, remain on the same state
If the symbol is 1 replace it by 1 and move left, remain on the same state
———————————————
Step-5:
Step-6:
–––––––––—–––––––––—
Step-7:
–––––––––—–––––––––—
Step-8:
–—––––––––––––––––––
Step-9:
–—––––––––––––––––––
–—––––––––––––––––––