0% found this document useful (0 votes)
163 views

Tutorial 3 (Theory of Computation)

This document discusses several topics in formal language theory and the theory of computation, including: 1) Constructing context-free grammars (CFGs) for various languages and deriving strings using leftmost and rightmost derivations. 2) Capturing expressions using CFGs and drawing parse trees. 3) Converting CFGs to Chomsky normal form. 4) Designing pushdown automata (PDAs) for various languages and testing strings. 5) Proving classes of languages are closed under operations and pumping lemmas. 6) Discussing ambiguous grammars using an example.

Uploaded by

Dipesh Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views

Tutorial 3 (Theory of Computation)

This document discusses several topics in formal language theory and the theory of computation, including: 1) Constructing context-free grammars (CFGs) for various languages and deriving strings using leftmost and rightmost derivations. 2) Capturing expressions using CFGs and drawing parse trees. 3) Converting CFGs to Chomsky normal form. 4) Designing pushdown automata (PDAs) for various languages and testing strings. 5) Proving classes of languages are closed under operations and pumping lemmas. 6) Discussing ambiguous grammars using an example.

Uploaded by

Dipesh Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Tutorial 3 (Theory of Computation)

1. Construct CFG for following Languages. Derive using Leftmost and Rightmost
derivations and also draw parse tree for corresponding strings given.
a. L = {anbn : n ≥ 0} ; String:- “aabb”
b. L = {w: w ϵ{a, b}* , #a = 2(#b) }; String:-“abaaba” [Note: #a means “no. of a”]
c. L = {wwR : w ϵ {a,b}*} ; String:- “abba”
d. L = {w: w ϵ {( , )}*, strings in w has balanced parentheses}; String:- “( )(( ))”
e. L = {w: w ϵ{a, b}* , #a ≤ #b }; String:-“bbab”
f. L = {w: w ϵ{0, 1}* , #0 < #1 }; String:-“011”
g. L = {ambn : m, n ≥ 1, m > n} ; String:- “aaaabb”
2. Using principle of CFG, Capture the expression (x1 + x2 / x1) * (x1 * x2 + x2). Also draw
its parse tree.
3. Convert the following CFGs into CNFs (only set of rules ‘R’ is given here.)
a. R = {S → AbA | B, A → a | e, B → a | b }
b. R = {S → Ab, A → AA | B, B → a }
c. R = {S → AaA | Ba | bA , A → S | e, B → aB | ab }
d. R = {S → A, A → AAB | B | b, B → a }
e. R = {S → aAa | bAb | e, A → SS }
f. R = {S → 1A | 0B, A → 1AA | 0S | 0, B → 0BB | 1 }
g. R = {S → ASB, A → aSA | a | e, B → SbS | A | bb }
4. Design PDAs for following Languages and test your design for corresponding strings.
a. L = {w: w ϵ{a, b}* , #a = #b }; String:-“abab”
b. L = {anbn : n ≥ 1} ; String:- “aabb”

c. L = {a2nb3n : n ≥ 0} ; String:- “aabbb”


d. L = {w: w ϵ{a, b}* , w = wR }; String:-“aabaa”
e. L = {anbncm : m, n ≥ 1} ; String:- “aabbc”

f. L = {anbn or anb2n : n ≥ 0} ; String:- “abb”

g. L = {anbnamb2m : m, n > 0} ; String:- “ababb”


5. Show that the class of Context Free Language are closed under Concatenation
operation but not under Complementation operation.
Tutorial 3 (Theory of Computation)

6. Given two languages:


L1 = {aibjck: i,j,k > 0, i = j } and L2 = {aibjck: i,j,k > 0, j = k }
a. Is (L1 ∪ L2) Context Free? Prove your answer.
b. Is (L1 ∩ L2) Context Free? Prove your answer.
7. Use Pumping Lemma to show whether following Languages are Context free or not.
a. L = { anbncn : n ≥ 0}

b. L = { 0n12n0n : n > 0}
c. L = {ww: w ϵ {a,b}*}
2
d. L = { a n : n ≥ 0}
n

e. L = { a 2 : n > 0}
f. L = {wwRw: w ϵ {a,b}*}
2

g. L = { anb n : n ≥ 0}
8. What is “Ambiguous Grammar”? Explain, why the grammar below is ambiguous?
a. R = {S → 0A | 1B, A → 0AA | 1S | 1, B → 1BB | 0S | 0 }
***

You might also like