This preview shows pages 1–2. Sign up to view the full content.
CS 181 — Winter 2005
Formal Languages and Automata Theory
Problem Set #5 Solutions
Problem 5.1.
(10 points) Recall the shuﬄe operator from Homework 2. Prove or disprove:
1. Context free languages are closed under shuﬄe.
Solution
We will show that context free languages are not closed under shuﬄe! Consider the languages
L
1
=
{
0
n
2
n

n
≥
0
}
and
L
2
=
{
1
m
3
m

m
≥
0
}
. Then the shuﬄe of the two languages
(denoted
SHUFFLE
(
L
1
,L
2
)) will contain the words that have an equal number of 0’s and
2’s, and equal number of 1’s and 3’s and morover, no 2 occurs before a 0 and no 3 occurs
before a 1.
Assume that
(
L
1
2
) is contextfree. Then we know that context free languages
are closed under intersection with regular languages. Consider intersecting
(
L
1
2
)
with 0
*
1
*
2
*
3
*
. Then we get precisely the language
{
0
n
1
m
2
n
3
m

n,m
≥
0
}
.
However, notice that this language is not context free. Intuitively, this is because we will
need to recall
n
before
m
even though
m
is the last number we stored. This is not possible
using a stack! To formally show this language is not context free, we can use the pumping
lemma but we leave this as an exercise.
2. Let
L
be context free and
R
regular. Then the shuﬄe of
L
and
R
is context free.
Solution
We will show that in fact the shuﬄe of
L
and
R
is contextfree. We do this by building a
PDA for
(
L,R
) given a PDA for
L
and a DFA for
R
.
Let
P
= (
Q
L
,
Σ
,
Γ
,δ
L
,q
L
,F
L
) be a PDA accepting
L
and
M
= (
Q
R
,
Σ
R
R
R
) be a DFA
accepting
R
. Our construction of the PDA for shuﬄe will use ideas from the construction
showing the context free languages are closed under intersection with regular languages and
from our construction showing regular languages were closed under shuﬄe. In particular, we
deﬁne the PDA
N
= (
Q
L
×
Q
R
,
Σ
,
Γ
,δ,
(
q
L
R
)
L
×
F
R
)
.
The transition function nondeterministically decides whether or not to feed the next input
symbol to
P
or to
M
. In other words, ((
q
0
,p
0
)
,b
)
∈
δ
((
q,p
)
,w,a
) if and only if one of the
following hold
•
(
q
0
)
∈
δ
L
(
q,w,a
) and
p
0
=
p
. In this case, we update the PDA and let the DFA idle.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 griebach

Click to edit the document details