Skip to content
PostTheory Of Computation / Assignment

TOC-As-3

2024-11-27
Back to Blog

TOC-As-3 ​

1. Construct NPDA’s that recognize the following languages over Σ={a,b,c}. (10 pt for each) ​

a. L2={anbmcn+m|n,m≥0} ​

1-a

b. L3={anbn+mcm|n,m≥0} ​

1-b

c. L4={a3bncn|n≥0} ​

1-c

2. Show that the language {an|n=2xfor all x∈N} is not contexr-free. ​

Let L={an|n=2xfor all x∈N}

Assume L is context-free.

Let s=a2p which is a string in L.

And s=wvxyz

Suppose w=ai, v=aj,x=ak,y=al,z=am and i+j+k+l+m=2p

By the pumping lemma,

wv2xy2z=aia2jaka2lam

Because i+j+k+l+m=2p and j+l≥1

Thus j+l<i+j+k+l+m<i+2j+k+2l+m

Therefore i+2j+k+2l+m should at least be 2p+1=2(i+j+k+l+m)

Which means j+l=i+j+k+l+m which is a contradiction.

Therefore wv2xy2z is not in L.

Therefore L is not context-free.

3. Convert the following grammar to an NPDA. (8pt) ​

E→E+E|id

3

4. Let Σ={a,b}. Design a (nondeterministic) TM for each following language. (10 pt each) ​

a. {anbm|m≥n} ​

4-a

b. {w|w is a palindrome} ​

4-b

c. {w|w is not a palindrome} ​

4-c

d. {an|n=2xfor x∈N} ​

4-d

5. Design a TM for each integer subtraction: a−b for a,b∈N. You need to clearly how the input and the side effect are encoded. (8pt each) ​

Let Γ={0,#,−,x}

  • Use 0 to represent positive numbers in the unary system.
  • Use # as a separator between the two numbers.
  • Use - as a special marker to indicate a negative result when b>a.
  • Use x as a symbol to do the subtraction.

Input Format

  • The first part of the tape will consist of a sequence of 0s representing a.
  • The second part, after the separator #, will contain a sequence of 10s representing b.

For example:

  • 000#00 represents 3−2, should be output as 0 (positive result).
  • 00#000 represents 2−3, and should be output as -0 (negative result).

5

6. Let Γ={a,b,⊔} Design a TM which decides whether the symbol b is on the tape. (8pt) ​

6