Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Problem Set 2

Fall 09
Due: Thursday Oct 1 at 11:00 AM in class (i.e., Room 103 Talbot Lab)
Please follow the homework format guidelines posted on the class web page:
http://www.cs.uiuc.edu/class/fa09/cs373/

1. Pumping Lemma. [Points: 10]


Prove that these languages are not regular:
3
A ={0n | n ≥ 0}
B ={0n 1m 0k | 0 ≤ n ≤ m ≤ k}

m
er as
Solution:

co
For A: we use contradiction, assume A is regular and p is its pumping length. Consider wp = 0p ∈ A.
3

eH w
Assume wp = xyz = 0p and |xy| ≤ p, |y| = 6 0. Now we have p3 < |xy 2 z| ≤ p3 + p < (p + 1)3 which implies
3

o.
2
xy z ∈/ A, which contradicts the pumping lemma.
rs e
For B : we use contradiction, assume B is regular and p is its pumping length. Consider wp = 0p 1p 0p ∈ B .
ou urc
Assume wp = xyz = 0p 1p 0p and |xy| ≤ p, |y| = 6 0. Now xy is a substring of the p zeros to the left of
wp , so xy 2 z will start with at least p + 1 zeros followed by exactly p ones, which means xy 2 z ∈
/ B . This
o

contradicts the pumping lemma.


aC s
vi y re

2. Pumping Lemma. [Points: 10]


Is the following language regular? Prove or disprove.
ed d

A = {0blg nc
100
ar stu

| n ≥ 1}

where bxc is the largest integer not greater than x; and lg x is logarithm of x to the base 2.
sh is

Solution:
Th

√ √
First we see that limy→∞ 2 y+1 − 2 100 y = +∞ (there is more than one way to see this, you may want
100

to use your calculus knowledge to see it fast, our your general knowledge about how exponential function
grows).

This means

that there is a xed Y such that for all y ≥ Y , we can ndan integer x such that
2 y ≤ x < 2 y+1 , which implies y ≤ lg100 x < y + 1, which implies lg100 x = y . In other words
100 100

for all y ≥ Y , we have 0y ∈ A. Let A1 be the set of all strings in A of length less than Y . We have
A = A1 ∪ {0y | y ≥ Y }. Both of these two sets is regular and the union of two regular sets remains regular,
therefore A is a regular language.

1
https://www.coursehero.com/file/5864306/hw-02-sol/
3. Regular Expression. [Points: 10]
Write regular expressions generating the following languages:

A ={w ∈ {0, 1}∗ | w has no substring 011}


B ={w ∈ {0, 1}∗ | |w| is a multiple of 3}
C ={w ∈ {0, 1}∗ | w has at least two 0 or at most one 1}

Solution:


A =L 1∗ (0∗ + 0∗ 01)

B =L ((0 + 1)(0 + 1)(0 + 1))∗

m
er as

C =L 1∗ 01∗ 0(0 + 1)∗ + 0∗ 10∗ + 0 + 

co
eH w
o.
4. Regular Expression. rs e
[Points: 10]
ou urc
Prove or disprove: For languages A and B of the same alphabet Σ, if AB and B are regular, then A
must be regular.
o
aC s

Solution:
vi y re

This is wrong. Consider A = {0n1m | m ≤ n}, B = L(1∗ ) and observe that AB = L(0∗ 1∗ ).

5. -closure [Points: 10]


ed d

Compute the -closure for the following NFAs


ar stu

(a) Σ = {a, b, c}:


sh is

a,b
" q1
Th

b
q0 "
c
b,c a
"
q2 q3
c
"

2
https://www.coursehero.com/file/5864306/hw-02-sol/
Solution:
We give the transition function for the new NFA with the same states. Note that the δ function is highly
symmetric.

δ a b c
q0 {q0 , q1 , q3 } {q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 }
q1 {q0 , q1 , q3 } {q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 }
q2 {q0 , q1 , q3 } {q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 }
q3 {q0 , q1 , q3 } {q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 }

(b) Σ = {0, 1}:

m
er as
0

co
eH w
q1 "
1

o.
1
rs e q3
ou urc
q0
" 1
0 "
o

"
aC s

q2 q4
vi y re

0,1
"
ed d
ar stu

Solution:
We give the transition function for the new NFA with the same states.
sh is

δ 0 1
Th

q0 {q0 , q2 , q3 , q4 } {q0 , q1 , q2 , q3 , q4 }
q1 {q0 , q1 , q2 , q3 , q4 } {q0 , q1 , q2 , q3 , q4 }
q2 {q0 , q2 , q3 , q4 } {q0 , q1 , q2 , q3 , q4 }
q3 {} {q0 , q1 , q2 , q3 , q4 }
q4 {q0 , q2 , q3 , q4 } {q0 , q1 , q2 , q3 , q4 }

3
https://www.coursehero.com/file/5864306/hw-02-sol/
6. DFA minimization [Points: 10]

(a) Determine the minimal-size DFA M such that L(M) = L(M1 ), M1 = (Σ, δ, Q, q0 , F ):
Σ = {0, 1},
Q = {q0 , q1 , q2 , q3 , q4 , q5 , q6 , q7 },
qstart = q0 ,
F = {q3 },
and δ , the transition function

0 1
q0 q1 q0
q1 q0 q2

m
er as
q2 q3 q1
q3 q3 q0

co
eH w
q4 q3 q5
q5 q6 q4

o.
rs e q6 q5 q6
ou urc
q7 q6 q3
o

Solution:
aC s

The new machine is basically the old one with q4 , q5 , q6 , q7 removed.


vi y re

M10 = (Σ, δ, Q, q0 , F ):
Σ = {0, 1},
Q = {q0 , q1 , q2 , q3 },
ed d

qstart = q0 ,
ar stu

F = {q3 },
and δ , the transition function
sh is

0 1
Th

q0 q1 q0
q1 q0 q2
q2 q3 q1
q3 q3 q0

4
https://www.coursehero.com/file/5864306/hw-02-sol/
(b) Determine the minimal-size DFA M such that L(M) = L(M2 ), M2 = (Σ, δ, Q, q0 , F ):
Σ = {0, 1},
Q = {q0 , q1 , q2 , q3 , q4 , q5 , q6 , q7 },
qstart = q0 ,
F = {q5 , q6 },
and δ , the transition function

0 1
q0 q7 q1
q1 q7 q0
q2 q4 q5
q3 q4 q5
q4 q5 q6

m
q5 q5 q5

er as
q6 q6 q5

co
q7 q2 q2

eH w
o.
rs e
ou urc
Solution:
q0 /q1 , q2 /q3 , q5 /q6 are equivalent. Take these as new combined states. We have
M20 = (Σ, δ, Q, q0 /q1 , F ):
o

Σ = {0, 1},
aC s

Q = {q0 /q1 , q2 /q3 , q4 , q5 /q6 , q7 },


vi y re

qstart = q0 ,
F = {q5 , q6 },
and δ , the transition function
ed d
ar stu

0 1
q0 /q1 q7 q0 /q1
q2 /q3 q4 q5 /q6
sh is

q4 q5 /q6 q5 /q6
q5 /q6 q5 /q6 q5 /q6
Th

q7 q2 /q3 q2 /q3

5
https://www.coursehero.com/file/5864306/hw-02-sol/
7. NFA to DFA [Points: 10]
For each of the following NFAs: describe the language that it accepts, convert it to DFA and remove
unreachable states.
(a) M1 = (Σ, Q, δ, qstart , F ), Σ = {0, 1}, Q = {q1 , q2 , q3 , q4 }, qstart = q1 , F = {q4 }

δ 0 1 
q1 {q1 } {q1 , q2 } {}
q2 {q3 } {q3 } {}
q3 {q4 } {q4 } {}
q4 {} {} {}

m
er as
Solution:

co
M10 = (Σ, Q, δ, qstart , F ) :

eH w
Σ = {0, 1},

o.
Q = {{q1 }, {q1 , q2 }, {q1 , q3 }, {q1 , q4 }, {q1 , q2 , q3 }, {q1 , q2 , q4 }, {q1 , q3 , q4 }, {q1 , q2 , q3 , q4 }},
qstart = {q1 }, rs e
ou urc
F = {{q1 , q4 }, {q1 , q2 , q4 }, {q1 , q3 , q4 }, {q1 , q2 , q3 , q4 }}
o

δ 0 1
aC s

{q1 } {q1 } {q1 , q2 }


vi y re

{q1 , q2 } {q1 , q3 } {q1 , q2 , q3 }


{q1 , q3 } {q1 , q4 } {q1 , q2 , q4 }
{q1 , q4 } {q1 } {q1 , q2 }
ed d

{q1 , q2 , q3 } {q1 , q3 , q4 } {q1 , q2 , q3 , q4 }


ar stu

{q1 , q2 , q4 } {q1 , q3 } {q1 , q2 , q3 }


{q1 , q3 , q4 } {q1 , q4 } {q1 , q2 , q4 }
{q1 , q2 , q3 , q4 } {q1 , q3 , q4 } {q1 , q2 , q3 , q4 }
sh is
Th

(b) M2 = (Σ, Q, δ, qstart , F ), Σ = {a, b, c}, Q = {q1 , q2 , q3 , q4 , q5 }, qstart = q1 , F = {q4 }

δ a b c 
q1 {q1 , q2 } {q1 , q3 } {q1 } {}
q2 {} {q3 } {q4 } {}
q3 {} {} {q5 } {}
q4 {} {} {} {q1 }
q5 {} {} {} {q4 }

6
https://www.coursehero.com/file/5864306/hw-02-sol/
Solution:
M20 = (Σ, Q, δ, qstart , F ) :
Σ = {a, b, c},
Q = {{q1 }, {q1 , q2 }, {q1 , q3 }, {q1 , q4 }, {q1 , q4 , q5 }},
qstart = {q1 },
F = {{q1 , q4 }, {q1 , q4 , q5 }}

δ a b c
{q1 } {q1 , q2 } {q1 , q3 } {q1 }
{q1 , q2 } {q1 , q2 } {q1 , q3 } {q1 , q4 }
{q1 , q3 } {q1 , q2 } {q1 , q3 } {q1 , q4 , q5 }
{q1 , q4 } {q1 , q2 } {q1 , q3 } {q1 }

m
er as
{q1 , q4 , q5 } {q1 , q2 } {q1 , q3 } {q1 }

co
eH w
Note: States {q1 , q4 } and {q1 , q4 , q5 } are equivalent and can be merged together.

o.
rs e
ou urc
8. DFA to regular expression [Points: 10]
Give a regular expression for each of the following DFAs:
o
aC s

(a) M1 = (Σ, Q, δ, qstart , F ), Σ = {0, 1}, Q = {q1 , q2 , q3 , q4 , q5 }, qstart = q1 , F = {q4 }


vi y re

δ 0 1
ed d

q1 q3 q2
ar stu

q2 q4 q3
q3 q3 q4
q4 q5 q5
q5 q5 q5
sh is
Th

Solution:

10 ∪ (0 ∪ 11)0∗1

7
https://www.coursehero.com/file/5864306/hw-02-sol/
(b) M2 = (Σ, Q, δ, qstart , F ), Σ = {0, 1}, Q = {q1 , q2 , q3 , q4 , q5 }, qstart = q1 , F = {q4 , q5 }

δ 0 1
q1 q1 q2
q2 q1 q3
q3 q5 q4
q4 q1 q4
q5 q1 q2

Solution:

m
0∗ 1(( ∪ 10 ∪ 11)0∗ 1)∗ (11 + 10) or, equivalently, (0 ∪ 1)∗ (111 ∪ 110)

er as
co
eH w
Note: use algorithm described in the class

o.
9. Irregularity [Points: 10] rs e
ou urc
Let h be a homomorphism h : Σ → Γ∗ , we dene inverse homomorphism as the following function:
For any w ∈ Γ∗ , let h−1 (w) = {s ∈ Σ∗ | h(s) = w} and h−1 (B) = {s ∈ Σ∗ | h(s) ∈ B} for any
B ⊆ Γ∗ .
o
aC s

Theorem1: The class of regular languages is closed under inverse homomorphism. That is, if B is
vi y re

regular then so is h−1 (B).


Prove that the following languages are not regular using closure theorems, which were shown in the
class:
ed d
ar stu

(a) B = {0n1m 0k | 0 ≤ n ≤ m ≤ k}

Solution:
Proof by contradiction. Let's assume that B is a regular language. If B is regular, then A = {1m 0k | 0 ≤
sh is

m ≤ k} = B∩1∗ 0∗ has to be regular by the closure theorem (since 1∗ 0∗ is a regular expression that describes
Th

a regular language). Let's dene a homomorphism h to be h : {0, 1} → {0, 1}∗ with h(0) = 1, h(1) = 0,
then h(A) = {0m 1k | 0 ≤ m ≤ k} has to be regular. We also know that by the closure theorem AR =
{0k 1m | 0 ≤ m ≤ k} has to be regular. AR ∩ h(A) is a intersection of two regular languages and hence also
a regular language (by another closure theorem). But AR ∩ h(A) = {0k 1m | 0 ≤ m ≤ k} ∩ {0m 1k | 0 ≤
m ≤ k} = {0n 1n | 0 ≤ n} which is known to be not a regular language, contradiction. Hence, B is not a
regular language.

8
https://www.coursehero.com/file/5864306/hw-02-sol/
(b) C = {an ban | n ≥ 0}

Solution:
Proof by contradiction. Let's assume that C is a regular language. Let's dene a homomorphism h to
be h : {0, 1, b} → {a, b}∗ with h(0) = a, h(1) = a, h(b) = b then h−1 (C) = {(0 ∪ 1)n b(0 ∪ 1)n | n ≥ 0},
which has to be regular by the Theorem1. 0∗ b1∗ is a regular language (since 0∗ b1∗ is a regular expression),
hence, by the closure theorem, h−1 (C) ∩ 0∗ b1∗ = {0nb1n | n ≥ 0} also has to be regular. Now let's
dene h0 to be h0 : {0, 1, b} → {0, 1}∗ with h(0) = 0, h(1) = 1, h(b) = . Since h0 is a homomorphism,
h0 (h−1 (C) ∩ 0∗ b1∗ ) = h0 ({0n b1n | n ≥ 0}) = {0n 1n | n ≥ 0} has to be regular. But we know that
{0n 1n | n ≥ 0} is not a regular language. We got a contradition, hence C is not a regular language.

Note: You may use the fact that {0n 1n | n ≥ 0}, Σ = {0, 1} is not regular without proving it. For
part (b), you may nd inverse homomorphism useful.

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th

9
https://www.coursehero.com/file/5864306/hw-02-sol/

Powered by TCPDF (www.tcpdf.org)

You might also like