Midterm 1 Solutions – Regular Languages Problem 1. (6 points

CDT314 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, 28 11 2013 Midterm 1 Solutions – Regular Languages Problem 1. (6 points) Consider the following NFA over the alphabet Σ ={a,b}: a) Write the transition function for the NFA. (1 point)
b) Convert the NFA into an equivalent DFA. (3 points)
c) Write the Regular Expression corresponding to the following NFA. (2 points) λ
λ
a
b
λ
λ
λ
a
a
λ
λ
λ
b
b
λ
a
λ
a
b
λ
λ
Solution 1: a) The transition function for the NFA a
b
ε
q0
{q1, q2, q3}
{q1}
{q1}
«
q1
«
{q1, q3}
q2
{q2, q3}
{q3}
{q0, q1, q3}
«
q3
{q2, q3}
{q0, q1, q3}
b) An equivalent DFA a
b
{q0, q1}
{q1}
{q2, q2, q3}
«
{q1}
{q1, q3}
{q1, q2, q3}
{q0, q1, q3}
{q1, q2, q3}
{q1, q3}
{q0, q1, q3}
{q1, q2, q3}
{q0, q1, q3}
{q0, q1, q3}
{q1, q2, q3}
For the details, see the Compendium for Regular Languages, problem 3.14.2. (However, there is an error in compendium describing transitions) c) The NFA corresponds to the Regular Expression ab*aa + bba*ab. CDT314 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, 28 11 2013 Problem 2. (4 points) Let M be the following DFA. Minimize M by set partitioning. Show every step of your minimization. Solution 2: This is the result. For the details, see the Compendium for Regular languages, problem 3.16.2. Problem 3 (4 points) a)
Consider the following language over the alphabet Σ = {0,1} L = {0i 1j⎮ i≤ j ≤ 2i and i ≥ 0}. This is a set of strings where all the 0’s come before all the 1’s, and the number of 1’s is at least the number of 0’s but no more than twice the number of 0’s. Is the language L regular? Justify your answer. b)
Is the following language L regular? Justify your answer. L = {an⎮ n is not prime}. Solution 3: a) We will show that L is NOT REGULAR using the Pumping Lemma. Justification: The Pumping Lemma states that for any regular language there is a number m so that if you pick any string of the language with a length greater than m, then we can always find a non‐empty portion y of the string that appears in the string within the first m characters that can be “pumped”, i.e. repeated as many times as we like, forming strings that are always in the language. The key here is to find a counterexample, a string in the language of length ≥ m, for which to show that there is no way to pump it.
Proof: Assume L is regular. Therefore the Pumping Lemma holds for L. Consider the string 0m12m. This string is clearly longer than m and clearly belongs to the language. By the Pumping Lemma, this string can be represented as xyz with |xy|
≤ m and y non‐empty, so that xyiz is in L for all values of i. But since the length of xy is ≤ m and there are m 0’s at the start of the string, xy (and also y) must consist of only 0’s. So let |y|= b. Now we get, choosing k = 0 in Pumping Lemma xykz = xz = 0m-b12m But 2m >2(m - b) and does not satisfy the condition that j ≤ 2i which means that this string does not belong to L as it has more than twice as many 1’s than 0’s. Therefore the language L is not regular. CDT314 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, 28 11 2013 b)
L = {an⎮ n is not prime}. Even here we will show that L is NOT REGULAR using the Pumping Lemma. Proof: Assume L is regular. From the closure of regular languages under complement, the complemet of this language is regular, so L = {an⎮ n is prime} is regular.Therefore the Pumping Lemma holds for L. But we have shown in the class in Lecture 5 that language L = {an⎮ n is prime} is not regular. Thus contradiction, and the original language is not regular.
References Linz Peter, An Introduction to Formal Languages and Automata, Jones & Bartlett, 2012. Salling Lennart: Formella språk, automater och beräkningar, 2001. FABER Compendium 1, Excercises on Regular Languages.