Hmw

advertisement
HOMEWORK ON REGULAR EXPRESSIONS
Supply regular expressions for the set of all strings on the alphabet {0,1} which:
1. end in 01
2. contain an even number of 0’s
3. have every 0 followed by at least one 1.
4. Supply a regular expression for the set of strings accepted by the
automaton below. This is a difficult problem. A hint about the way to go
about solving it, is given below. Question 5 is easier. Do it first.
b
a
1
2
a
b
b
3
a
4
a
b
5. Supply a regular expression for the set of strings accepted by:
b
b
a
a,b
a
a,b
Hint re Problem 4. The solution illustrates a general method of contructing a
regular expression for the language accepted by a finite automaton.
By a path from one state to another, I mean a sequence of connected states
which leads from the first state to the other. For instance two paths from
state 1 to state 4 are:
Path 1:
states 1 3 4
The accepted string in this case is the sequence of symbols that take the
automaton from state 1 to state 3 and then to state 4, i.e. : b a
Path 2: states 1 3 3 4 1 2 1 3 4
The accepted string here is: b b a b a a b a
In the path considered in Example 2, the last (i.e. rightmost) occurrence of
state 1 is the 3rd state from the end. The path from that occurrence of state 1
(i.e. 1 3 4 ) does not contain any further occurrences of state 1 other than the
first state. In other words the path 1 3 4 leads from state 1 to an accepting
state without ever returning to state 1. Any path from state 1 to an accepting
must involve some last occurrence of state 1, and so can be broken into two
parts of this kind: a path (the null string if there is only a single occurrence of
state 1) from state 1 to a last occurrence of state1, followed by a path from
state 1 to an accepting state which does not go back to state 1.
Using the above terminology, we can break down the problem as follows:
(a) If S’ of is the set of all paths from state 1 back to state 1
(such as states 1 3 3 4 1 2 1), find a regular expression S for the
corresponding set of sequences of symbols (such as b b a b a a) that cause
the finite automaton to follow a path in S’
(b) If T’ is the set of all paths from state 1 to an accepting state that do not go
back to state 1 (such as states as states 1 3 4), find a regular expression T for
the corresponding set of sequences of symbols (such as b a) that cause the
finite automaton to follow a path in T’
A regular expression for the set of all strings that the finite automaton accepts
is then given by ST.
Evaluating set T is easy. It is simply:
b* a | b b* a a b* | a b*
Evaluating set S. Any sequence in set S’ can be broken up into one or more
successive pieces that go from state 1 back to state1 without going through
state 1 in between. For instance the sequence of states 1 3 3 4 1 2 1 can be
broken up into the sequence 1 3 3 4 1 followed by 1 2 1. It follows that if
S2’ is the set of all strings that lead from state 1 back to state 1 without
passing through state 1 in between, and S2 is a regular expression for the
corresponding sequences of symbols that cause the finite automaton to follow
a path in state S2’, then we can assert that S = S2 * . So now the only
thing left for you to do is to determine what the set S2’ consists of, and then
supply the regular expression S2 .
Good luck!
Download