Uploaded by jorsaca1

CSCI Test 1 Practice Problems

advertisement
CSCI 434 Fall 2021
Test 1 Practice Problems
Study the problems written on the board, in the lecture slides, or in the homework. Also study
each exercise & problem in the textbook with a solution provided by the author; these are the
exercises & problems with an A to the left of the exercise number.
Below are practice problems and actual test questions from previous semesters of this class:
1) Write an RE (with no abbreviations except [0-9] and [1-9]) that generates the language of all
United States financial quantities less than one dollar, such as $0.58 and 5¢. If written in
“dollar” format (with a leading $ sign), then the 0 before the decimal point is optional, but the
two base-ten digits after the decimal point are both mandatory. If written in “cents” format (with
a trailing ¢ sign), then there is no decimal point, and there are either one or two base-ten digits;
the leftmost digit cannot be a 0 except for the special case of 0¢.
2) Write an RE that generates the language of times, in the usual civilian “HH:MMAM/PM”
format, for example 12:34AM and 8:00PM. The tens place of the hour is always omitted for
single-digit hours, but the colon and the other three digits are mandatory, as is the AM/PM
designation. You may not use any shorthand or abbreviations whatsoever, except for [0-X] and
[1-X] where X is a positive single digit integer.
3) Write a derivation of the string aaabbb using the right regular grammar below. Nonterminals
are written in italic.
S  aS | aB | 
B  b | bB | 
4) Draw a parse tree for the string and grammar of the previous problem.
7) Draw a DFA to recognize the following binary language.
{w | w contains an even number of 0’s}
8) Write an RE that generates the language of the previous problem.
9) Draw a NFA with only two states to recognize the binary language of the following RE.
0*(100*)*
10) Use the mechanical RE-to-NFA algorithm to draw an NFA for the following binary RE.
(10  1*0+)*11
11) Describe the language generated by the following binary RE in 10 English words or less.
(0  10)*(1  )
(Answer: The language of all binary strings without any consecutive 1’s.)
12) Draw an NFA with only four states to recognize the following binary language.
{w | w begins with 0 and ends with 11}
13) Convert the NFA of the previous problem into a DFA.
14) Write an RE that generates the language of the previous problem.
15) Write a derivation of the string 00011 using the right regular grammar below. Nonterminals
are written in italic.
S → 0A | 0B
A → 0 | 0A | ε
B → 0B | 0C
C → 1 | 1C | ε
16) Draw a parse tree for your derivation above of the string 00011.
17) Draw an NFA with exactly three states to recognize the following language L. Label the
states.
L = { w | w contains a 1 in the second to last position}
18) Draw a DFA equivalent to the NFA from the previous problem. Label the states of the DFA
each with the corresponding subset of the states of the NFA from the previous problem.
19) Write a regular expression to generate the language recognized by the DFA of the previous
problem.
20) Mechanically convert the following regular expression into an NFA and draw it.
(101+ ∪ (00)*)*
23) Describe the RE below over the alphabet Σ = {0, 1} in 10 English words or less, starting with
the words “all strings with” or the words “all strings without.” (You can do it with 6 total words.)
0* (1(1 ∪ ε)0+)* (1 ∪ ε) (1 ∪ ε)
24) Draw an NFA state diagram to recognize the language generated by the RE below over the
alphabet Σ = {a, b}.
(aa ∪ bb ∪ ε)* ab
Download