Tutorial 3 (Theory of Computation)
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”
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 }
***