Computer Science B36 November 5, 2014 Scarborough Campus University of Toronto

Computer Science B36
Scarborough Campus
November 5, 2014
University of Toronto
Homework Assignment #5
Due: November 26, 2014, by 2:30pm
(in the drop box for your tutorial section)
Appended to this document is a cover page for your assignment. Fill it out, staple your answers to it,
and deposit the resulting document into the course drop box. drop box for your tutorial section. Please
do not enclose your assignment in an envelope. An assignment submitted on behalf of two students will
be returned to the tutorial in whose box it was deposited.
Question 1. (10 marks) For each of the following assertions, state whether it is true or false, and justify
your answer.
a. (3 marks) For any regular expressions R and S, (R + S)∗ ≡ R∗ + S ∗
b. (3 marks) For any regular expressions R and S, R∗ (R + S)∗ S ∗ ≡ (R + S)∗ .
c. (4 marks) For any regular expressions R, S, and T , if RS ≡ RT and R 6≡ ∅, then S ≡ T .
Question 2. (10 marks) For each of the languages described below, give a DFSA that accepts the
language and a regular expression that denotes it. For each automaton and regular expression give an
informal but convincing argument to justify its correctness.
a. (3 marks) {x ∈ {0, 1}∗ : x = 0m 1n for some m, n ∈ N such that m · n ≥ 3}.
b. (3 marks) {x ∈ {0, 1}∗ : every 0 in x is immediately preceded and followed by a 1}.
c. (4 marks) {x ∈ {0, 1}∗ : both 00 and 11 appear as substrings of x}.
Question 3. (10 marks) Let L be a language over alphabet Σ that is accepted by some FSA. Prove that
each of the following languages is also accepted by some FSA.
a. (3 marks) The set of prefixes of the strings in L:
Prefix(L) = {x ∈ Σ∗ : for some y ∈ Σ∗ , xy ∈ L}.
b. (3 marks) The set of reversals of the strings in L:
Reversal(L) = {x ∈ Σ∗ : for some y ∈ L, x = (y)R }.
(Recall that the reversal of a string y, denoted (y)R , is the string y written backwards — see Example 7.1
in the notes.)
c. (4 marks) For any symbol a ∈ Σ, the set of strings obtained by inserting exactly one a in any position
of any string in L:
Inserta (L) = {x ∈ Σ∗ : for some y, z ∈ Σ∗ , x = yaz and yz ∈ L}.
1
Question 4. (10 marks) Let L4 = {x ∈ {0, 1}∗ : x = y1z, for some y, z ∈ {0, 1}∗ such that |z| = 3}.
That is, L4 is the set of strings with at least 4 symbols, where the 4th symbol from the end is 1.
a. (1 marks)
Give a regular expression for L4 .
b. (1 marks)
Give a nondeterministic FSA that accepts L4 .
c. (2 marks)
accepts L4 .
Apply the subset construction on the NFSA from part (b) to get a deterministic FSA that
d. (4 marks) Prove that every deterministic FSA that accepts L4 must have at least 16 states. (Hint:
Prove that in any deterministic FSA that accepts L4 , distinct input strings of length 4 must lead from the
initial state to distinct states.)
e. (2 marks) Explain how to generalise this language to show that for every positive integer n, there is
a language Ln that is accepted by some NFSA with n + 1 states, but is not accepted by any DFSA with
fewer than 2n states. You don’t need to provide any detailed proofs here; just a high-level outline of how
this result can be shown.
Note: This demonstrates the power of nondeterminism for finite state automata: There are languages
accepted by “small” (in the number of states) NFSA, but are only accepted by DFSA with exponentially
more states.
Question 5. (10 marks) For any x ∈ {0, 1}∗ , let diff(x) be the absolute value of the difference between
the number of 0s and the number of 1s in x.
a. (5 marks) Give a DFSA that accepts L = {x ∈ {0, 1}∗ : for every prefix y of x, diff(y) ≤ 2}. Give an
informal but convincing argument to justify the correctness of your automaton.
b. (5 marks)
Prove that there is no DFSA that accepts the language L0 = {x ∈ {0, 1}∗ : diff(x) ≤ 2}.
THAT’S IT WITH HOMEWORK, FOLKS!
2
Cover page for
CSCB36 Homework #5
Submitted by
(2) Family Name:
(1) Family Name:
Given Name:
Given Name:
Student Number:
Student Number:
Tutorial:
Tutorial:
By virtue of submitting this homework I/we acknowledge that I am/we are aware of the policy on
homework collaboration for this course.
3