FORMAL Language 2019 Final

Q1.

(10 points) Find an s-grammar for the language

L={anbn+1:n3}.

Solution

SaS1BS1aXABBAaAB|bBbXa


Q2.

(10 points) Convert the following grammar into CNF and GNF.

(a).

SbaABAbAB|λBBAa|A|λ

Solution
First eliminate

λ-productions. This gives
SbaAB|baA|baB|ba,AbAB|bA|bB|b,BBAa|Ba|Aa|A|a.

There is a unit-production,
BA
, so we must remove it from the grammar and get
SbaAB|baA|baB|ba,AbAB|bA|bB|b,BBAa|Ba|Aa|bAB|bA|bB|b|a.

(i) CNF
We can now apply the construction and get
SVbVaAB|VbVaA|VbVaB|VbVa,AVbAB|VbA|VbB|b,BBAVa|BVa|AVa|VbAB|VbA|VbB|b|a,

and
SVcVd|VcA|VcB|VbVa,AVbVd|VbA|VbB|b,BVeVa|BVa|AVa|VbVd|VbA|VbB|b|a,Vaa,Vbb,VcVbVa,VdAB,VeBA,

(ii) GNF


(b).

SAB|aBAabb|λBbbA

Solution
First eliminate

λ-productions. This gives
SAB|B|aB,Aaab,BbbA|bb.

This has introduced a unit-production, which is not acceptable in the construction of using Theorem
6.6
.
SAB|bbA|aB|bb,Aaab,BbbA|bb.

(i) CNF
We can now apply the construction and get
SAB|VbVbA|VaB|VbVb,AVaVaVb,BVbVbA|VbVb,

and
SAB|VcA|VaB|VbVb,AVdVb,BVcA|VbVb,VcVbVb,VdVaVb,Vaa,Vbb.

(ii) GNF
By introducing productions
Vb
, we can convert the grammar into Greibach normal form.
SaVbVbB|bVbA|aB,AaVbVb,BbVbA|bVb,Vbb.


Q3.

(15 points) Use the CYK algorithm to determine whether the string

aabba is in the language generated by the grammar
SABABB|aBAB|b

Solution
For the string

aabba.
Let
wi,j=aiaj
be a substring of
w=aabba
and also let
Vi,j={A:AXY
,
Xwi,k
and
Ywk+1,j}
. Then, we compute
Vij
for
1ij5
. If
w
in
L(G)
,
SV1,5
, otherwise
SV1,5
.

Step 1.

V1,1={A},
V2,2={A}
,
V3,3={B}
,
V4,4={B}
,
V5,5={A}
.

Step 2.

V1,2=,
V2,3={S,B}
,
V3,4={A}
,
V4,5=
.

Step 3.

V1,3={S,B},
V2,4={A}
,
V3,5={B}

Step 4.

V1,4={A},
V2,5={S,B}

Step 5.

V1,5={S,B}

Since

SV1,5, the string
aabba
is in the language.


Q4.

(15 points) Construct npda's that accept the following languages

L={anbn+mcm:n0,m1} on
Σ={a,b,c}

Solution
Start with an initial

z in the stack. Put a mark a on the stack when input alphabet is an a, consume a mark a when input is a
b
. When all
a
's in the stack are consumed, put a mark
b
to the stack when input is a
b
. After input becomes
c
, eliminate a mark on the stack. The string will be accepted if the stack has only
z
left when the input is completed.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


Q5.

(20 points) Show that the following languages on

Σ={a,b,c} are not context free:
(a).L={anbjck:k=jn}

Solution
The language is context-free. A grammar for it is

SaSb|S1,S1bS1a|λ.


(b).L={w:na(w)=nb(w)nc(w)}

Solution
Given

m, we pick
w=am2bmcm
which is in
L
. It is easy to see that the only chance for the adversary to win is to choose
v=ak,y=bl
for
k0,l0
. Then the pumped string is
wi=am2+(i1)kbm+(i1)lcm.
However, for
w0=am2kbmlcm
, we see immediately that
(ml)m=m2ml<m2k.

That means
w0L
, so
L
is not context-free.


Q6.

(10 points) Construct Turing machines that will accept the following language

L={anbm:n2,n=m} on
{a,b}

Solution
A transition graph with

F={q6} is
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


Q7.

(20 points) Design Turing machines to compute the following functions

f(x)= the largest integer less than or equal to
x/2
for
x
and
y
positive integers represented by unary.

Solution
Start by removing the leftmost

1, then move to the rightmost
1
and mark it by replacing it with
x
. The read-write head then moves back to the leftmost
1
and repeat the above process until there are no more
1
's. Finally, we replace all the marked
x
's by
1
's to complete the computation. The transition graph of a Turing machine with
F={q6}
is given below.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →