0% found this document useful (0 votes)
6 views

cs381 02 01

abawa

Uploaded by

eugordissimo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

cs381 02 01

abawa

Uploaded by

eugordissimo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Exercise 2.2.

1b:
Note, for Exercise 2.2.1a: Please see http://www-db.stanford.edu/˜ullman/ialcsols/sol2.html

First we realize that what determines whether a string of As and Bs is accepted is ONLY the
last marble dropped. If the last marble is dropped from the proper x1x2x3 lever configuration,
then we will accept. Since all we care about is the lever configuration, let’s draw the 8 state
machine depicting the possible lever configurations.

Next we make two distinctions, namely whether the last marble enters through A or B.
Suppose the last marble enters through A. From our understanding of the problem, we know
that the string will be accepted if x1 x2 x3 = 110 or 111.
Let’s treat each of these cases separately. How do we get to state 110? Well, if we only had
As, then we would need
#As = 3 mod 4
(follow the A transitions in the diagram, starting from 000). Now B transitions are a bit
more tricky. First, B transitions move us alternately between the top and bottom of the
diagram. Since we’re aiming for 110, we want to be on top. Thus we need an even number
of Bs. Therefore,
#B = 0 mod 2
How do the Bs take us across the machine? Well, each B transition from bottom to top
transports us 2 positions, or the equivalent of reading two As. Thus, half the B transitions

CS 381 Homework 1 1/7


move us two spaces forward horizontally. So if we only saw Bs and wanted to land at 110,
we’d want
(#B/2) ∗ 2 = 3 mod 4
So before we consider the final A, combining the two equations we get #B mod 2 = 0 and
#A + #B = 3 mod 4. We have one more A to consider, and we want #A to always denote
the total number of As in our string. Thus, our final equation is

#B mod 2 = 0 and #A + #B − 1 = 3 mod 4

or
#B mod 2 = 0 and #A + #B = 0 mod 4

A similar line of argument gets us the equation for state 111. Here is equation:

#B mod 2 = 1 and #A + #B = 3 mod 4

Now what if our string ends in B? Well we trivially know that an even number of Bs total will
make us accept since x3 osciallates between 1 and 0 each B drop. The other way we could
accept is if x1 x2 x3 = 010 or 110. Since both these states are on the top level in the diagram
we can find this solution quickly. Again, As alone yields #A = 2 or 3 mod 4. For Bs, we
can assume there are an odd number (even automatically accept). The total number of Bs
(including the last one) give us #B-1 total horizontal moves (reason this out like above).
Thus #B − 1 = 2 or 3 mod 4. Putting this together we get

#A + #B = 0 or 3 mod 4

So to sum up:
Ends in A:
#B = 0 mod 2 and #A + #B = 0 mod 4
OR
#B = 1 mod 2 and #A + #B = 3 mod 4
Ends in B:
#B = 0 mod 2
OR
#A + #B = 0 or 3 mod 4.
Further simplifications could be made if you were so inclined.

Common mistakes:
1. Some people didn’t give a language. Recall that a language for this machine is a string
of As and Bs, not a configuration of levers.
2. Many people gave the standard definition of L(M): L(M) is the set of strings such
that delta-hat(s,w) is in F. This is not what we were asking for: we wanted a pattern
describing strings in the language.

CS 381 Homework 1 2/7


3. Many people noticed that only the last drop really determined acceptance or rejection
and there were certain lever configurations that led to success, but went no further.
Finding the pattern was just one more step!

4. Finally, many people gave some of the patterns (ie an even # of Bs, ending with B)
but did not take this to its final end.

Exercise 2.2.1c:
The full transition table is below. Note that the first three bits represent the three levers,
respectively, and 0 indicates original position, while 1 represents flipped position.
A B
000r 110a 011a
001r 111a 010a
001a 111a 010a
010r 100r 011a
010a 100r 011a
011r 101r 000r
011a 101r 000r
100r 000r 101a
101r 001r 110a
101a 001r 110a
110a 010r 111a
111a 011r 100r
Accept states are the states ending in ’a’.
The difference between this automaton and the one from part a can be stated as follows: If
we flip all the bits in the table above (ignoring r and a), we will get the machine from part
a. As an example, 000r 110a 011a from the first line maps to 111r 001a 100a, which is a
transition from part a. To complete the mapping, the unreachable states must be added to
the table above (i.e. 000a, 100a, 110r, 111r).
The language for this machine is also different from the language of part a. Using the same
approach to part b, we can determine the language for this machine. Namely, we have:
Let # A be the number of A’s in the string, and # B be the number of B’s in the string.
If the string ends in A, it will be accepted if

b#B/2c ∗ 2 + #A − 1 = 0 mod 4
If the string ends in B, it will be accepted if

#B = 1 mod 2

OR
b(#B + 1)/2c ∗ 2 + #A) = 3 mod 4

Comments on part c:

CS 381 Homework 1 3/7


Many people got the transition table but most did not explain how it was different from the
table in part a. Only a few people recognized the bit-flipping. Similarly, only a few people
attempted to get the language for this machine. For people who gave a substantial effort
on the language, and gave an explanation of the new machine, we generally gave full credit
for part c. Some people made mistakes on part a, and this meant that part c would also be
incorrect. We attempted to avoid taking off double points for this.

Exercise 2.2.2:
We defined δb by breaking the input string into any string followed by a single symbols
(in the inductive part, Equation 2.1). However, we informally think of δb as describing what
happens along a path with a certain string of labels, and if so, then it should not matter how
b Show that in fact, δ(q,
we break the input string in the definition of δ. b xy) = δ( b δ(q,
b x), y) for
any state q and strings x and y.

Solution: Proof by induction on |y|

Base Case: |y| = 0


b we know δ(q,
We know that y = , since its length is 0. From the definition of δ, b ) = q.
Therefore:
b x) = δ(q,
δ(q, b x)
b δ(q,
δ( b x), ) = δ(q,
b x)

Inductive step: Assume the statement holds true for |y| = `, i.e.

b xy) = δ(
δ(q, b δ(q,
b x), y) (1)

We must show the statement holds for |y| = ` + 1. Consider w = ya. We must show
b xw) = δ(
δ(q, b δ(q,
b x), w). We know that

b δ(q,
δ( b x), w) = δ(
b δ(q,
b x), ya)

b we know
>From the definition of δ,
b δ(q,
δ( b x), ya) = δ(δ(
b δ(q,
b x), y), a)

CS 381 Homework 1 4/7


>From our inductive assumption (1), we have

b δ(q,
δ(δ( b x), y), a) = δ(δ(q,
b xy), a)

b we have
>From the definition of δ,
b xy), a) = δ(q,
δ(δ(q, b xya)
b xya) = δ(q,
δ(q, b xw)

Hence we can conclude that


b xw) = δ(
δ(q, b δ(q,
b x), w) (2)

which is what we needed to prove. 2

Common mistakes:

• Not stating the inductive assumption

• Using the base case |y| = 1 instead of |y| = 0

CS 381 Homework 1 5/7


Excercise 2.2.4

Excercise 2.2.5a
The question is to find an automaton which accepts strings with the property that every
substring of length 5 contains at least two 0. It is not clear what should be done with strings
of length less than five. Here we have decided to accept them.
Below is one automaton which accepts the described language. The idea is to keep two
counters which indicate the position of the last two 0s we have seen. For example state (1,3)
indicates the last 0 we have seen is in position 1, the previous one is in position 3, possible
strings could be 01011 . . . , 01001 . . ., 01000 . . .

CS 381 Homework 1 6/7


0

1,2 1 2,3 1 3,4 1 4,5


0

1 1
0 1,3 2,4 3,5
0 0
0 0
1,4 1 2,5 0
0

1,5

There are 10 states, all of which are final (accepting). The initial state is (1,2). When a
transition doesn’t exist, it means the string is not accepted.

One another of doing it is the consider the last relevant part of the string, and change
accordingly (this yields the same automata as previous, only the name of the states differ,
the name of the states is the relevant part of the string, i.e. what’s at the right of the second
last 0 from the left (starting 0 being omitted).

CS 381 Homework 1 7/7


0
1 1 1
0 1 11 111
0
1 1
0 10 101 1011
0 0
0 0
110 1 1101 0
0

1110

It would be nice if there was a one sentence explanation of the main idea behind the con-
struction of the automaton. I don’t want a page, a sentance such as: I keep track of the
last two 0s – I consider the relevant part of the end of the string. – I list all 32 states, then
move between them. is enough. It can seem to be pretty obvious to you when you draw your
automaton, and most of the time it is when it is correct. When it is not, you’ll get more
partial credit with explanations than without (not to say that I cannot always distinguish
between something which was almost right, and just a random set of states and arrows).
A few common mistakes, referenced on your papers by:
&1 Could be done using less states
&2 You shouldn’t be accepting after failling. Typically it means you should have had
a trap state when you failled, instead if looping back (discarding the fact the block
didn’t contain two 0) and be in the position of later reaching an accepting state. A
typical example is when the automaton contains all 32 strings of length five, and
you go from 11011 (fail) to 10110 (transition 0) (accepting). I took 2 points of for
that.
&3 You interpreted the text as being disjoints block of 5 (1-5, 6-10, etc.) and not 1-5,
2-6, 3-7, etc. Not point were taking off, but this is unlikely to staty the same in the
future
&4 You didn’t indicate the start state of your automaton. Most of the time it was
obvious, but not always.

CS 381 Homework 1 8/7

You might also like