Solutions to Midterm 1 Regular Languages - MDH … · Solutions to Midterm 1 – Regular Languages...

2
CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, 04 02 2010 Solutions to Midterm 1 – Regular Languages Problem 1. (4 points) Circle true statements among the following: 1. The number of outgoing arcs from a state of a DFA is always equal to |Σ|. (True) 2. The number of outgoing arcs from a state of a NFA is always equal to |Σ|. (False) 3. Not all nite languages are regular. (False) 4. If L is regular language, then L R is also a regular language. (True) 5. If L is regular language, then L 2 may not be a regular language. (False) 6. The family of regular languages is closed under intersection. (True) 7. The grammar })} { , }, { }, ({ { a aS Saaa S S a S G = is not regular. (True) 8. The grammar })} { , }, , { }, ({ { λ bS aS S S b a S G = is regular. (True) Problem 2. (6 points) a) Convert the following NFA into regular expression: Solution: Create a new initial state and a new, unique accepting state, neither of which is part of a loop. Remove state 3: Remove state 2: Remove state 1:

Transcript of Solutions to Midterm 1 Regular Languages - MDH … · Solutions to Midterm 1 – Regular Languages...

Page 1: Solutions to Midterm 1 Regular Languages - MDH … · Solutions to Midterm 1 – Regular Languages ... Solution: Create a new ... Rich Elaine, Automata, Computability and Complexity:

CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, 04 02 2010 

Solutions to Midterm 1 – Regular Languages 

Problem 1. (4 points) Circle true statements among the following:  

1. The number of outgoing arcs from a state of a DFA is always equal to |Σ|. (True)

2. The number of outgoing arcs from a state of a NFA is always equal to |Σ|. (False)

3. Not all finite languages are regular. (False) 

4. If L is regular language, then LR is also a regular language. (True) 

5. If L is regular language, then L2 may not be a regular language. (False) 

6. The family of regular languages is closed under intersection. (True) 

7. The grammar  })}{,},{},({{ aaSSaaaSSaSG →=  is not regular. (True) 

8. The grammar  })}{,},,{},({{ λbSaSSSbaSG →=  is regular. (True) 

Problem 2. (6 points)  

a) Convert the following NFA into regular expression:

Solution: Create a new initial state and a new, unique accepting state, neither of which is part of a loop. 

 Remove state 3: 

 Remove state 2: 

Remove state 1: 

Page 2: Solutions to Midterm 1 Regular Languages - MDH … · Solutions to Midterm 1 – Regular Languages ... Solution: Create a new ... Rich Elaine, Automata, Computability and Complexity:

CD5560 Formal Languages, Automata and Theory of Computation, Mälardalen University – School of Innovation, Design and Engineering, 04 02 2010 

b)Let M be the following DFA.  

Minimize M by set partitioning. 

Solution: Initially, we have classes = {[1, 3], [2, 4, 5, 6]}.  At step 1: ((1, a), [2, 4, 5, 6]) ((3, a), [2, 4, 5, 6])         No splitting required here. ((1, b), [2, 4, 5, 6])  ((3, b), [2, 4, 5, 6])  ((2, a), [1, 3])    ((4, a), [2, 4, 5, 6]) ((5, a), [2, 4, 5, 6]) ((6, a), [2, 4, 5, 6]) ((2, b), [2, 4, 5, 6])  ((4, b), [1, 3])    ((5, b), [2, 4, 5, 6])  ((6, b), [1, 3])  These split into three groups:  [2], [4, 6], and [5].  So classes is now {[1, 3], [2], [4, 6], [5]}.  At step 2, we must consider [4, 6]:  ((4, a), [5])    ((6, a), [5]) ((4, b), [1])    ((6, b), [1])  No further splitting is required.  The minimal machine has the states: {[1, 3], [2], [4, 6], [5]}, with transitions as shown above.  Problem 3 (4 points) Regular or not? If regular, construct an automaton, regular expression or a grammar.  

If not regular, use pumping lemma for regular languages. 

a) Set of all strings of form  }810{ =+ lklk  over alphabet Σ = {0, 1}. 

Solution: Regular. A simple finite state machine with finite number of states which takes care of the order of symbols and counts the total 

number of characters. 

 

b) Set of all strings of form  }810{ =− lklk  over alphabet Σ = {0, 1}. 

Solution: 

Not regular.  Language L consists of all strings of the form 0*1* where the number of 0’s is eight more than the number of 1’s.  We can 

show that L is not regular by applying pumping lemma.  Let w = 0m+8 1m.  Since |xy| ≤ m, y must equal 0k for some k > 0.  We can pump 

y out once, which will generate the string 0m+8‐k 1m, which is not in L because the number of 0’s is is less than 8 more than the number 

of 1’s. 

 

References 

Linz Peter, An Introduction to Formal Languages and Automata, Jones & Bartlett, 2006  

Salling Lennart: Formella språk, automater och beräkningar, 2001 

Rich Elaine, Automata, Computability and Complexity: Theory and Applications,  Prentice Hall, 2007