CS3240 Homework 2
Due: Fri, Feb 10 by
Guidelines:
Regular Expressions
Question
1: Consider the concept of “closure”. A set S is said to be closed under a
(binary) operation Å
if and only if applying the operation to two elements in the set results in
another element in the set. For example, consider the set of natural numbers N and the “+” (addition) operation. If we add any two natural numbers, we get
a natural number. Formally x, y are elements of N implies x + y is an element of N. State true or false and explain why
Question 2:
For each of the regular expressions below, state if they describe the same set of strings (state if they are equivalent). If they are equivalent, what is the string they describe?
1. [a-z][a-z]* and [a-z]+
2. [a-z0-9]+ and [a-z]+[0-9]+
3. [ab]?[12]? and a1|b1|a2|b2
4. [ab12]+ and a|b|1|2|[ab12]*
5. [-az]* and [a-z]*
6. [abc]+ and [cba]+
7. [a-j][k-z] and [a-z]
Question 3:
For each of the strings described below, write a regular expression that describes them and draw a finite automaton that accepts them.
1.
The string of zero or more a followed by three b
followed zero or more c
2.
The string of zero or more a, b
and c
but every a
is followed by two or more b
3.
All strings of digits that represent even
numbers
4.
All strings of a’s
and b’s that contain no three
consecutive b’s.
5.
All strings that can be made from {0,
1} except the strings 11 and 111