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

Formal Languages and Automation Assignment

The document provides examples and problems related to formal languages and automata. It includes questions about finding grammars that generate specific string sets over an alphabet, determining the language generated by a given grammar, constructing deterministic finite automata (DFAs) that accept certain languages, designing a nondeterministic finite automaton (NFA) for a language, converting an NFA to an equivalent DFA, finding strings in a language defined by a regular expression, and more. Solutions or partial solutions are provided for each problem.

Uploaded by

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

Formal Languages and Automation Assignment

The document provides examples and problems related to formal languages and automata. It includes questions about finding grammars that generate specific string sets over an alphabet, determining the language generated by a given grammar, constructing deterministic finite automata (DFAs) that accept certain languages, designing a nondeterministic finite automaton (NFA) for a language, converting an NFA to an equivalent DFA, finding strings in a language defined by a regular expression, and more. Solutions or partial solutions are provided for each problem.

Uploaded by

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

Assignment: Formal Languages and Automation Assignment

1) Find grammars for Σ = {a, b} that generate the sets of

(a) all strings with exactly one a.


(b) all strings with at least one a.
(c) all strings with no more than three a’s.
(d) all strings with at least three a’s.
Answer
S → aA, A → aA , A → B, B → bB ,B → λ
a)S → aA → aB → aλ → a (Accepted)
b)S → aA → aB → abB → abλ → ab (Accepted)
c)S → aA → aaA → aaaA → aaaB → aaaλ → aaa (Accepted)
d)S → aA → aaA → aaA → aaaB → aabλ → aaab (Accepted)

2) What language does the grammar with these productions generate?


S  Aa
AB
B  Aa
3) Let Σ = {a, b}. For each of the following languages, find a grammar that generates it.
a L1 = {anbm : n ≥ 0, m > n}.
b L2 = {anb2n : n ≥ 0}.
(c) L3 = {an+2bn : n ≥ 1}.

4) For Σ= {a,b},construct dfa's that accept the sets consisting of


all strings with exactly one a,
(b) all strings with at least one a,
(c) all strings with no more than three a's,
(d) all strings with at least one a and exactly two b’s,

5) Design an nfa with no more than five states for the set {ababn: n >0}∪{aban: n ≥ 0}.
answer
An nfa for the set is given by the following transition graph:
6) Convert the following nfa to into an equivalent dfa

Answer. Following the procedure of converting am nfa to a dfa, we have

δ ∗ (q, 0) 0 1
q0 {q0, q1, q2} {q1, q2}
q1 {q0, q1, q2} {q1, q2}
q2 {q2} {q1}

{q0} ∈ F since λ ∈ L(M); {q1, q2}, {q0, q1, q2} ∈ F since q1 is a final state in M. Thus, the
result dfa is shown as follows.

7) Find all strings in L((a + b) b (a + ab)*) of length less than four.


Answer.
The strings with length 1: {λbλ} = {b};
The strings with length 2: {abλ, bbλ, λba} = {ab, bb, ba};
The strings with length 3: {(aa)bλ,(ab)bλ,(ba)bλ,(bb)bλ,(a)b(a),(b)b(a), λb(ab)} = {aab, abb,
bab, bbb, aba, bba, bab}
8) Find a regular expression for the set {anbm: n ≥ 3,m is even}.
Answer.
There are two cases:
• n and m are even: (aa) ∗ (bb∗ );
• n and m are odd: a(aa) ∗ b(bb∗ ); Thus, a regular expression for the set {a n b m : (n + m) is
even} is (aa) ∗ (bb∗ ) + a(aa) ∗ b(bb∗ ).

9) Find a regular expression for L = {vwv: v, w ∈{a, b}*, |v| =3}.


Answer.
For any string x ∈ {a, b} ∗ , we can treat it as x = λxλ, where v = λ, x = w. Therefore, any string
x ∈ {a, b} ∗ is in L. Thus, L = (a + b) ∗

10) Give regular expressions for the following language on Σ = {a, b, c}. All strings containing exactly
one a.

Solution
(b + c) a(b + c)

Find grammars for∑¿{a , b }that generates the sets of:a.All strings with exactly one a
S →bS∨Sb∨bSb∨ab
.All strings with at least one a S →aS∨Sa∨bS∨Sb∨aSb∨bSa∨ac.
All strings with no more than three a’sS →aAb∨aA∨Aa∨bS∨Sb∨bAa∨a∨b∨λA
→aBb∨bBa∨bA∨Ab∨aB∨Ba∨a∨b∨λB → a ∨b∨λ
16. Find a grammar that generates the language+¿}L={w wR:w ϵ{a , b }¿and give acomplete
justification for your answer.This language is comprised of the repetition of a string in {a, b}+2 or
more times.S→aS | bS | aQ | bQQ→QQ | QTT→TT | TλS will produce a string from {a, b}+,
and will pass that on to T, which will repeat that string

You might also like