Uploaded by ammar mosani

Automata Theory Practice: CFG, PDA, Turing Machines

advertisement
Theory of Automata Practice Sheet:
Name: Muhammad Fasih Zaheer
ID:F22CSC020
Q.no.1: Give context-free grammars generating the following languages. (1 Mark)
a. The set of strings over the alphabet {a,b} with more a’s than b’s
CFG:
S → aSb | bSa | Sa | aS | a
b. The complement of the language {𝑎 𝑛 𝑏 𝑛 | 𝑛 ≥ 0}
CFG:
S→A|B
A → ba | XA | AX
X→a|b
B → DE | EZ
D → aD | a
E → bE | b
Z → ab | aZb
c. 𝐿 = {w | the length of w is odd and its middle symbol is an ‘a’}
CFG:
S → aSa | bSb | aSb | bSa | a
d. 𝐿 = {w| w contains at least three 1s}
CFG:
A→0A ∣ 1B
B→0B ∣ 1C
C→0C ∣ 1D
D→0D ∣ 1D ∣ 0 ∣ 1
Q.no.2: Construct the Pushdown Automata for the following languages, use JFLAP to draw
the PDAs and run at least 6 inputs, where 3 of them are accepting examples and remaining
3 are for rejection. (2 Marks)
(i) 𝐿 = {𝑎 𝑖𝑏 𝑗 𝑐 𝑘 |𝑖,𝑗, 𝑘 ≥ 0,⋀ 𝑖 = 𝑗 ⋁ 𝑖 = 𝑘} over ∑ = {𝑎, 𝑏}
Test Inputs: ab, ac, aabb, aacc, aabc, abbccc, aabbbc, a
(ii) 𝐿 = {𝑎 𝑖𝑏 𝑗 |𝑖 = 𝑗 ⋁ 𝑖 = 3𝑗 }
Test Inputs: ab, abbb, aabb, aabbbbbb, a, b, abb, aabbb
Q.no:3: Construct Turing Machines for the following languages, use JFLAP to draw the TMs
and run test inputs as provided with each language. (2 Marks) (i) 𝐿 = {𝑎 𝑛𝑏 𝑛 𝑐 𝑛|𝑛 ≥ 0} over ∑
= {𝑎, 𝑏} Test strings: aaabbbccc, abbbccc, aabbc, aabcc, abc
(ii) 𝑈𝑛𝑎𝑟𝑦 𝑆𝑢𝑏𝑡𝑟𝑎𝑐𝑡𝑖𝑜𝑛
Test strings: 1111-11= 11, 11111-11=111, 111-11, 1111-1=111
Download