Professional Documents
Culture Documents
Theory of Computing
Midterm # 2 Solutions
ID: ___________
Page 1 of 6
20 November 2013
NAME
Ima Sample
ASU ID
[10]
Question
2
Question
3
Question
4
Question
5
Total
[10]
[10]
[10]
[10]
[50]
Bonus
question
[1
mark]:
Give
an
example
of
a
language
over
the
alphabet
{0}
that
is
not
context-free.
For
example,
{0n
:
n
is
a
power
of
2},
{0n
:
n
is
a
perfect
square},
or
{0n
:
n
is
a
prime}.
CSE 355
Fall 2013 - Colbourn
Theory of Computing
Midterm # 2 Solutions
ID: ___________
Page 2 of 6
CSE 355
Fall 2013 - Colbourn
Theory of Computing
Midterm # 2 Solutions
ID: ___________
Page 3 of 6
(After
including
the
picture,
I
see
a
mistake
with
some
of
the
red
transitions
to
reject.
At
the
lower
left
it
should
not
say
c,a
;
instead
it
should
say
b,a
and
b,b
.
But
the
transitions
to
reject
can/should
be
omitted
anyway.)
Question
5
[10
marks
in
total]
In
each
part,
answer
yes
or
no,
and
explain.
The
grade
is
entirely
for
the
explanation
given,
not
the
yes/no
answer!
(a)
[2
marks]
If
L1
and
L2
are
linear
languages,
must
L1
L2
be
a
linear
language?
Yes.
When
L1
and
L2
have
linear
grammars
with
start
variables
S1
and
S2
and
no
variables
in
common,
take
all
rules
for
both
along
with
the
rule
S
S1
|
S2
to
get
a
linear
grammar
for
L1
L2.
(b)
[2
marks]
If
L1
and
L2
are
CFLs,
must
L1
L2
be
a
CFL?
No.
{aibiaj
:
i,j
0}
and
{aibjaj
:
i,j
0}
are
CFLs
but
their
intersection
is
not.
(c)
[2
marks]
If
L
is
a
CFL,
must
L*
be
a
CFL?
Yes.
If
L
has
CFG
with
start
variable
S,
form
a
new
CFG
by
adding
a
new
start
variable
N
and
the
rule
N
NS
|
.
This
is
a
CFG
for
L*.
(d)
[2
marks]
If
L
has
an
unambiguous
context-free
grammar,
must
every
CFG
for
L
be
unambiguous?
No.
(As
we
saw
in
class,)
CFGs
S
SS
|
(S)
|
and
S
(S)S
|
generate
the
same
language.
The
first
is
ambiguous;
the
second
is
not.
(e)
[2
marks]
If
L
is
a
regular
language,
must
{wwrev
:
w
L}
be
context-free?
Yes.
If
L
is
regular,
it
has
a
regular
grammar.
(All
rules
are
of
the
form
A
aB
or
A
.)
Replace
every
rule
of
the
form
A
aB
by
A
aBa,
and
leave
the
A
rules
alone
to
get
a
CFG
for
{wwrev
:
w
L}.
(You
cannot
just
show
that
LLrev
is
a
CFL,
because
LLrev
is
NOT
{wwrev
:
w
L}.)