CS375 Midterm Exam Solution Set (Fall 2017) Closed book & closed notes October 17, 2017 Name sample 1. (10 points) (a) Put in the following blank the number of strings of length 5 over A={a, b, c} that begins with a and have at least one c. (6 points) 1 (3 4 2 4 ) = 65 (b) Use the pigeonhole principle to determine how many people are needed in a group to say that three were born in the same month. Put your answer in the following blank. (4 points) 25 2. Fill out the following blank with a regular expression for the language: { Ʌ, a, b, aa, bb,, a n, b n, } (4 points) a* + b* 3. Fill out the first blank with a regular expression for the language over the alphabet {a, b} with no string containing the substring bbb, then fill out the second blank with a regular expression for the language over the same alphabet with no string containing the substring bbbb. (6 points ) (a + ba + bba)*(ʌ + b + bb) (a + ba + bba + bbba)*(ʌ + b + bb + bbb) 4. Fill out the following blanks to make it a DFA for the expression: a*bc* + aaac + aac + ac ( 10 points )
5. To get an NFA for the given regular expression: (a + b)b*, the initial step is to put (a + b)b* as the label of an edge between a start state and a final state, as follows. (a + b)b* We then apply R.S to get the following graph. Fill out the blanks in the following graph (2 points) a+b b* The next step is to expand the labels of both edges in the above graph to get the following NFA. Fill out the blanks in the following graph. (4 points) a Ʌ Ʌ b b This is an NFA for the given regular expression. 6. To transform the following NFA into a regular expression,
we first connect a new start state s to the start state of the given NFA and connect each final state of the given NFA to a new final state f as shown below. We then eliminate the states of the given NFA until only state s and state f are left. If we eliminate state 1 first, we would get the following NFA. Fill out the blanks in the following NFA. (4 points) If we then eliminate state 2, we would get the following NFA. Fill out the blanks in this NFA. (4 points) Finally, we eliminate state 0 to get the following NFA. The label of the edge between state s and state f is the regular expression of the given NFA. What is it? (2 point)
7. Given the following NFA over the alphabet {a, b}, to transform the given NFA to a DFA, first construct Ʌ-closures of all the states of the given NFA. Fill out the blanks for state 0 and state 1. (2 points) {0,1,2} {1,2} Next to get the states of the DFA, we construct a tree as follows. Fill out the blanks in the following tree. (6 points) The distinct nodes in the above binary tree are the states of the DFA to be constructed. 8. Given the following DFA, to find a minimum-state DFA, (10 points) we first construct E0
Then construct E1. Out of the following four cases (a), (b), (c) and (d), which one represents the correct E1? Put your answer in the following blank. The correct E1 is: c 9. Fill out the blanks of the following grammar to make it a regular grammar for the given regular expression where S is the start symbol: ab* + c (10 points)
10. To find a regular grammar for the expression a*b + bb + c, we can also transform it into an equivalent NFA as follows first, construct all the Ʌ-closures, build the following tree (fill out the blank in the tree), (2 points) identify the distinct nodes of the tree (fill out the blank in the list), (2 points) construct the following transition table (fill out the blanks in the table), (4 points)
write in simplified form after renumbering the states build the corresponding DFA after removing the don t need portion and renaming, we get a DFA on the right hand side. rename
The regular grammar for this DFA is the one on the left below (fill out the two blanks there). After replacing each C with Ʌ, we get the regular grammar on the right hand side (fill out the two blanks there): (4 points) If we further replace the B in the first line with b and Ʌ respectively, we get the grammar on the left below (fill out the red blanks). Since the portion that is inside the blue box in the first line is the same as the items inside the blue box in the second line, we can replace the items inside the blue box of the first line with A to get the grammar on the right side. This is regular grammar of the expression a*b + bb + c. (4 points) 11. An NFA that can recognize the language of the following regular grammar: S as bs ai, I bj a, J bk a, K Ʌ can be constructed as follows. Fill out the blanks in the following NFA. (5 points) 12. Pumping Lemma cannot be used for languages that are finite. Why? Which of the following three answers is correct? Put your selection in the following blank. (5 points) (a) A finite language cannot be recognized by a DFA or an NFA. (b) A finite language cannot absorb all the distinct strings that can be accepted by a DFA or an NFA. (c) A finite language does not have a regular grammar.
Ans: b