Theory of Computing
Midterm # 2
NAME
ASU
ID
ID: ___________
Page 1 of 5
19
October
2015
Ima
Sample
You
have
50
minutes
to
complete
the
exam.
Do
not
open
the
exam
until
instructed
to
do
so.
No
text
and
no
other
notes
permitted.
Computers,
calculators,
and
communication
devices
are
not
permitted.
Write
all
answers
on
the
examination
paper
itself.
BUDGET
YOUR
TIME
WELL!
SHOW
ALL
WORK!
Question
1
[10]
Question
2
[10]
Question
3
[10]
Question
4
[10]
Total
[40]
If
you
need
a
clarification
about
one
of
the
responses,
ask
during
office
hours
or
recitations.
If
you
think
there
is
an
addition
error,
see
the
instructor.
If
you
want
to
question
a
grade,
first
read
these
solutions
carefully
to
understand
why
you
may
not
have
earned
the
grade
you
expected.
If
this
does
not
resolve
your
question,
then
provide
a
clear
explanation
of
your
reasons
together
with
the
original
of
your
test
paper
prior
to
10/30/15
start
of
class.
Then
the
entire
paper
will
be
regraded,
and
the
grade
on
the
test
may
increase,
decrease,
or
stay
the
same.
Bonus
question
[1
mark]:
Give
an
example
of
a
language
over
the
alphabet
{0}
that
is
not
regular.
One
example
is
{0n
:
n
is
a
perfect
square}.
CSE 355
Fall 2015  Colbourn
Theory of Computing
Midterm # 2
ID: ___________
Page 2 of 5
B
aBb

Bb

ab

b
S
XAZ

XZ

AZ

c

XBY

BY

XY

b

A
XAZ

XZ

AZ

c

XBY

BY

XY

b
B
XBY

BY

XY

b
X
a;
Y
b;
Z
c
S
XT

XZ

AZ

c

XU

BY

XY

b

A
XT

XZ

AZ

c

XU

BY

XY

b
B
XU

BY

XY

b
X
a;
Y
b;
Z
c;
T
AZ;
U
BY
(c)
[3
marks]
Is
the
language
in
the
(b)
part
regular?
Explain.
No!
The
language
is
{aibjck
:
i
j+k}.
Suppose
to
the
contrary
that
it
is
regular.
Intersect
it
with
a*b*
to
get
{aibj
:
i
j};
by
closure
under
intersection
this
must
be
regular.
Let
p
be
the
pumping
length
and
consider
w
=
apbp
=
xyz.
Then
y
contains
only
as,
and
xy2z
contains
more
as
than
bs
and
so
is
not
in
the
language.
Hence
it
is
not
regular.
Question
2.
[10
marks]
Let
L1
and
L2
be
contextfree
languages.
You
cannot
simply
say
that
CFLs
are
closed
under
union,
concatenation,
star,
and
reversal
that
is
what
you
are
asked
to
show.
Also
the
question
cannot
be
answered
by
giving
examples;
the
question
asks
how
to
show
these
in
general.
Consider
CFGs
for
L1
and
L2
with
no
variables
in
common,
start
variables
S1
and
S2.
(a) [2
marks]
Show
that
L1
L2
is
contextfree.
Add
a
new
start
variable
S
and
rules
S
S1

S2.
As
mentioned
in
class,
one
could
combine
the
two
PDAs.
(b) [2
marks]
Show
that
L1L2
is
contextfree.
Add
a
new
start
variable
S
and
rules
S
S1S2.
As
mentioned
in
class,
combining
the
two
PDAs
may
not
work
because
the
stack
contents
may
mess
things
up.
(c) [2
marks]
Show
that
L1*
is
contextfree.
Add
a
new
start
variable
S
and
rules
S
S1S

.
As
mentioned
in
class,
restarting
the
PDA
may
not
work
because
the
stack
contents
may
mess
things
up.
(d)
[4
marks]
Show
that
reverse(L1)
is
contextfree.
Reverse
the
symbols
on
the
RHS
of
every
rule
in
the
CFG
for
L1
to
get
a
CFG
for
reverse(L1).
Reversing
the
transitions
in
a
PDA
may
not
work;
think
about
the
case
that
in
the
original
PDA
the
last
transition
pushes
but
does
not
pop
then
reversing
means
that
the
first
transition
pops
an
empty
stack!
Question
3
[10
marks
in
total]
Consider
the
language
L
=
{aibjck:
ij
or
jk}.
Describe
precisely
a
PDA
that
recognizes
L.
Describe
precisely
a
PDA
that
CSE 355
Fall 2015  Colbourn
Theory of Computing
Midterm # 2
ID: ___________
Page 3 of 5
recognizes
L.
One
such
PDA
has
start
state
q0,
final
states
{accept,accept1}
and
the
following
transition
function.
(q0,,)
(q1,a,)
(q1,,)
(q2,b,)
(q2,,)
(q3,,x)
(q3,c,x)
(q3,c,$)
(accept,c,$)
{(q1,$),(q4,$)}
{(q1,)}
{(q2,)}
{(q2,x)}
{(q3,)}
{(accept,
x)}
{(q3,
)}
{(accept,
$)}
{(accept,
$)}
(q4,a,)
(q4,,)
(q5,b,x)
(q5,b,$)
(q5,,x)
(q6,b,$)
(q6,,)
(accept1,c,)
{(q4,x)}
{(q5,)}
{(q5,)}
{(q6,$)}
{(accept1,x)}
{(q6,$)}
{(accept1,)}
{(accept1,)}
{(q1,$)}
{(r,)}
{(r,A),(r,B)}
{(q3,A)}
{(q6,B)}
And
I
am
done.
(q1,,)
(r,b,b)
(r,,A)
(q3,,)
(q6,,)
{(r,S)}
{(r,)}
{(q2,c),(q4,c),(r,B),
(r,)}
{(r,a)}
{(r,a)}
(r,,$)
(r,c,c)
(r,,B)
(q4,,)
(q7,,)
{(accept,)}
{(r,)}
{(q5,b),(q7,b),
(r,)}
{(r,A)}
{(r,B)}