Formal Languages and Automata Exam: Answer The Following Questions
Formal Languages and Automata Exam: Answer The Following Questions
2- a) Let = {a,b}, draw deterministic finite automata (DFA) that recognize, exactly:
- Language ( (a+b)*(aa+bb)(a+b)* )
- All words with b as the third letter and reject all other words.
- All words that have different first and last letters.
b) Draw the corresponding NFA to the following DFA
0
1
-
0
0 1 1
+ +
0
1
1- a) Consider the language S*, where S = {ab ba}. Write out all the words in S* that
have seven or fewer letters. Can any word in this language contain the substrings aaa
or bbb? Why?
Solution:
- The words of length less than 7 are:
: contains no factors
ab, ba: contains one factor
abab, abba, baab, baba: contains 2 factors
ababab,ababba,abbaab,baabab,bababa,babaab,baabba,abbaba: contains 3 factors
All words contains 4 or more factors have length 8.
- The language words can't contain neither aaa nor bbb. The reason is the blocks that
build the words are only 2. These 2 blocks start with a and end with b or vice versa.
So, the result of combination yields only ab, ba, aa, or bb.
b) Does the two following two regular expressions define the same language:
(a+b)*a(a+b)*a(a+b)* and b*ab*a(a+b)*? Investigate your answer.
Solution:
Yes. Both of them denote all the words with at least two a's.
c) Construct a regular expression defining each of the following languages over the
alphabet = {a b}:
- The language of all strings of a's and b's in which either the strings are all b's
or else there is an a followed by some b's.
- The language of all strings of a's and b's that at some point contain a double
letter.
- All words that contain at least one of the strings s1, s2, s3 or s4.
Solution:
- b*+ab* or equivalently (+a)b*
- (a+b)*(aa+bb)(a+b)*
- (a+b)*(s1+s2+s3+s4)(a+b)*
2- a) Let = {a, b}, draw deterministic finite automata that recognize -exactly- the
following:
- Language ( (a+b)*(aa+bb)(a+b)* )
Solution:
a
a
a, b
b a +
-
b
b
- All words with b as the third letter and reject all other words.
Solution:
a, b
a
a, b a, b
-
b
a, b
+
a a
a
b + a
b
b
b) Draw the corresponding NFA to the following DFA
0
1
-
0
0 1 1
+ +
0
1
Solution:
0
1
-
0
0 1 1
0,1
+ +
0 1 0,1
- +
1 OR
c) If L is the language recognized by the DFA in the figure, Draw DFA to recognize
L', where L' is the complement of L.
Solution:
0
1
±
0
0 1 1
0
1
3- a) State pumping lemma.
Solution:
Let L be any regular language that has infinitely many words. Then there exist
some three strings x, y, z (where y is not the null string) such that all the strings of the
form xynz L, n = 1, 2, 3, …
OR
b) Define ODDPALINDROME to be the language of all strings of a's and b's that
are palindromes and have an odd number of letters. Construct nondeterministic
pushdown automata that accept this language.
Solution:
Any nondeterministic pushdown automata equivalent to the following is sufficient: