Professional Documents
Culture Documents
T4 Solutions
T4 Solutions
Week of February 5
T-4-1. For each of the following regular expressions, answer the following questions:
• Is S unambiguous?
• Does S generate all binary strings? If not, then what set of binary strings is generated by
S?
• What generating series does S lead to?
• What does the generating series tell you about the number of strings produced by S?
(a) S = (0 ⌣ 11)∗
(b) S = (00 ⌣ 01 ⌣ 11 ⌣ 10)∗
(c) S = 0∗ (111∗ 00∗ ⌣ 11∗ 000∗ ⌣ 10)∗ 1∗
Solution.
(a) S = (0 ⌣ 11)∗
This is unambiguous (it adds 0 or 11 in each iteration, and there is st most one way to
make each string this way). It doesn’t generate all binary strings; it doesn’t generate 1,
and more generally, it generates all binary strings in which each block of 1s has even
1
length. The generating series is ΦS (x) = 1−x−x 2 and its coefficients tell us the number of
1
MATH 239 Winter 2024 Tutorial 4 Solutions
block of 1s has length at least two, and 11∗ 000∗ if the block of 2s has length at least two).
The generating series that S leads to is
!
1 1 1 1
· x3 x3
= 2 (1 − x2 ) − 2x3
.
1−x 1−x − 2
2 − 2
1 − x (1 − x)
(1−x) (1−x)
Since S is ambiguous, this generating series is not very helpful (its first few terms are
1, 2, 4, 8, 17, 36, . . . ). We could follow along the lines of 3.13 to show that the coefficients
of the generating series are an upper bound for the number distinct of strings of a given
length produced by S.
T-4-2. For each part, write the rational function the regular expression leads to (and simplify the
answer so it is a ratio of two polynomials).
∗
(a) 0 ⌣ 00 111 (11)∗ (0 ⌣ 00) 111(11)∗
∗
(b) ε ⌣ (00 (0000)∗ ) 111 00 (0000)∗ ε ⌣ 111
Solution.
(a)
1 x3
(x + x2 ) · x3 (x+x2 )
·
1− 1 − x2
1−x2
x4 + x5
=
1 − x2 − x4 − x5
(b)
x2
1
1+ · x5
· (1 + x3 )
1 − x4 1−1−x4
(1 + x2 − x4 )(1 + x3 ) 1 + x2 + x3 − x4 + x5 − x7
= =
1 − x4 − x5 1 − x4 − x5
T-4-3. For the languages described below, use either block or prefix decomposition to write an
unambiguous regular expression associated to the language.
Solution.
2
MATH 239 Winter 2024 Tutorial 4 Solutions
(a) We modify the regular expression for all binary strings given by 0∗ (11∗ 00∗ )∗ 1∗ . If a word
given by this expression starts or ends with a block of 1s, then this block of ones could
be of length 1. All other blocks of 1s would be of length at least 2. This gives a block
decomposition
(ϵ ⌣ 10)0∗ (111∗ 0∗ 0)∗ 1∗
(b) We modify the regular expression for all binary strings given by 0∗ (11∗ 00∗ )∗ 1∗ . As we
wish to ensure blocks of 0s are even length we use (00)∗ for the prefix and 00(00)∗ for
the non-empty block of 0s inside the string. We use 1(11)∗ for the non-empty block of 1s
on the inside of the string and 1(11)∗ ⌣ ϵ for the suffix. This gives
(c) We modify the regular expression for all binary strings given by (0∗ 1)∗ 0∗ . This gives
(0∗ 100)∗ 0∗ .