Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views3 pages

Test 2 - COM321 Automata Theory and Computation

The document contains model answers for a test on Automata Theory and Computation, covering topics such as regular expressions, context-free grammars, and Turing machines. It includes specific tasks like generating strings from a regular expression, constructing a DFA, proving a language is not regular, and rewriting a grammar in Chomsky normal form. The answers are detailed and demonstrate the application of theoretical concepts in automata and computation.

Uploaded by

bsc-55-20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Test 2 - COM321 Automata Theory and Computation

The document contains model answers for a test on Automata Theory and Computation, covering topics such as regular expressions, context-free grammars, and Turing machines. It includes specific tasks like generating strings from a regular expression, constructing a DFA, proving a language is not regular, and rewriting a grammar in Chomsky normal form. The answers are detailed and demonstrate the application of theoretical concepts in automata and computation.

Uploaded by

bsc-55-20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COM321: Automata Theory and Computation

Test 02 Model Answers


Instruction: Answer all questions.

1. Give the six shortest strings generated by the regular expression 1∗ (001+ )∗ . [6 marks]

, 1, 11, 111, 001, (plus choose any from 1111, 0011, 1001)

2. Construct a regular expression for the language {w|w has an even number of 1’s} over the al-
phabet {0, 1}. [14 marks]

First construct a DFA for the language.

0 0 1 0

Then convert to a 4-state GNFA

 
st 0 ac

1 1

Then rip state 1

0 ∪ 10∗ 1

 
st 0 ac

Finally rip state 0

(0 ∪ 10∗ 1)∗
st ac

3. Construct a context-free grammar for the regular language {w|w contains the substring 101}
over Σ = {0, 1}. [10 marks]

First construct the DFA for the language

1
0 1 0,1

q0 1 q1 0 q2 1 q3

Then using the state to variable mapping

State Variable
q0 A
q1 B
q2 C
q3 D
Then using the variables, the CGF is

A −→ 0A|1B
B −→ 1B|0C
C −→ 0A|1D
D −→ 0D|1D
D −→ 

4. Prove that the language {0n 1n |n ≥ 0} is not regular. [5 marks]

Assume the language A = {0n 1n |n ≥ 0} is regular. Let p be the pumping length in the pumping
lemma. Consider the string w = 0p 1p . Since |w| ≥ p, then by the pumping lemma, w = xyz
such that

(a) xy i z ∈ A, i ∈ {0, 1, 2, . . .}
(b) |y| > 0
(c) |xy| ≤ p

By (b) and (c), y ∈ 0+ . Hence xy 2 z has more 0’s than 1’s. Therefore xy 2 z ∈
/ A, and hence A is
not regular.

5. Rewrite the following context-free grammar in Chomsky normal form. [7 marks]

A −→ BAB|B|
B −→ 00

Add a new start variable.

S −→ A
A −→ BAB|B|
B −→ 00

2
Remove rule A −→ .

S −→ A|
A −→ BAB|B|BB
B −→ 00

Remove unit rule A −→ B.

S −→ A|
A −→ BAB|00|BB
B −→ 00

Remove unit rule S −→ A.

S −→ BAB|00|BB|
A −→ BAB|00|BB
B −→ 00

Splitting BAB.

S −→ BC|00|BB|
A −→ BC|00|BB
B −→ 00
C −→ AB

Finally resolving 00.

S −→ BC|DD|BB|
A −→ BC|DD|BB
B −→ DD
C −→ AB
D −→ 0

6. Describe a Turing machine that recognizes the language {w|w reads the same from left to right
as from right to left. e.g. 1001001 and 010}. [8 marks] Let T be the Turing machine.
T =“On input string w :

(a) Zig-zag across the tape, crossing the first and last uncrossed symbols, if they match. If they
do not match, reject.
(b) Accept the w if at most one uncrossed symbol remain on the tape.”

You might also like