Homework Assignment #1: Solutions
Contents
In order to determine the cardinalities of the sets, you should use the rules
which relate the cardinalities of the various set operators to the
cardinalities of their operands. Note also that for disjoint sets A and B
of finite cardinality, | A È B | = |A| + |B| .
Note, on the other hand, that for any set A,
| A È A | = | A | since of course
A È A = A .
In order to characterize the cardinalities of sets in these broader terms, you need
to understand the "arithmetic" of infinite quantities.
Perhaps the easiest way to do this problem is to count the relevant strings
of a specific length, then add up all of these counts. When the length is
less than 3, the substring issue is irrelevant. For a length of 0, there is
1 string (the empty string); for a length of 1, there are 3 strings;
and for a length of 2, nine possible strings, since each "slot" in the string
can be filled in one of three ways.
Beginning with strings of length 3, we need to consider also those strings which
have "abc" as a substring and subtract them out of the count. Thus for a length
of 3, there would be 27 strings, but we must subtract 1 to account for "abc",
which is a substring of itself. For lengths of 4 and 5, notice that the substring
"abc" can occur in several different ways. For example, for strings of length
5 we have patterns such as "_ _ abc", "_ abc _" and "abc _ _", where the underscores
represent other letters. Each underscored slot can be filled in one of three ways,
so for a length of 5 we have 35 original candidates, minus 3 times
32 possibilities in which "abc" occurs as a substring, according to
one of the three patterns. This leaves 243 - 27 = 216 strings of length 5.
Similar calculations yield 81 - 6 = 75 strings of length 4.
Finally, when counting strings of length 6,
we must remember not to count the string "abcabc" twice when subtracting out for
strings with "abc" as a substring. In other words, this string fits both of the
patterns "_ _ _ abc" and "abc _ _ _", but should only be counted once. This yields
a total of 729 - (4 * 33 - 1) = 729 - 107 = 622 strings of length 6.
The sum total is then 1 + 3 + 9 + 26 + 75 + 216 + 622 =
952 strings
Note: the following exercises and problems are from the textbook
(on pages 83-90).
M1 =
( {q1,q2,q3},
{a,b}, d, q1, {q2} )
where d is given by the following table:
The machine given can be nicely drawn as a series of states with q3
in the middle and arranged as a "ladder". Then we can interpret "u" and "d"
as up and down, for example as in the following diagram:
The following diagram describes a machine which recognizes the given
language with substring "0101". Note that if we fail to recognize a
full substring "0101" in a left-to-right sweep, we must go back to the
state which represents the best prefix we have nevertheless seen so
far, if any. These considerations are handled by the back-looping
transitions which go above and below the "main line".
This next diagram describes a machine which recognizes the given
language with "0" occurring as the third symbol. The idea is that
upon the third transition, a "0" takes us to a final state which
we can loop back to on any symbol. Furthermore, a "1" transition
will take us into a "sink hole". Note that we must see at least
3 symbols to end up in the final state.
In order to convert the given NFA to a DFA form, we let the state set of
the new machine equal the set of subsets of the state set of the old machine
(i.e., Q = {{},{1},{2},{3},{1,2},{2,3},{3,1},{1,2,3}}). Then we set the
start state of the new machine equal to the set of states reachable by
zero or more e-transitions from the old start
state. Next we set the final states of the new machine to any state
containing a final state of the old machine. And finally, we create the
new transition function so as to take one state to another on a given
symbol just when there existed a transition on that symbol from any
state in the first set to any state in the second set in the old machine,
including possible e-transitions.
For the given NFA, we get a DFA represented by the following state diagram:
We can further consolidate this machine by eliminating those
states which are unreachable from the start state (since we
can never reach them, they cannot affect the set of strings
the machine will recognize).
A finite state transducer is a 5-tuple:
Now given a finite state transducer T as described above and a string
w = w1, ..., wn in S* and a string
v = v1, ..., vn in G*,
we say that T computes v from w just when there exists a sequence of states
r0, ..., rn in Q* such that both of the following hold:
We can design a simple machine to effect this transformation as follows:
it has two states, one for having read an even number of symbols and
one for having read an odd number of symbols. On any transition it goes
from one of these states to the other. Upon going from the even to the odd
state, it inverts the input by emitting the opposite symbol from the one
it has read. Upon going to the even state, it emits the same symbol that
it has read.
This state diagram illustrates the machine:
Read the textbook's definition of AR as "the reverse of language A".
Then we are asked to show that the reverse of any regular language is regular.
Assume that we are given some regular language A; by the definition of
regular language there must be some DFA M such that L(M) = A. We will
construct a new DFA M' such that L(M') = AR.
The basic idea is to reverse all of the arrows of the original machine, and
to interchange initial and final states. Note however that this basic plan
will not work directly, as it may introduce non-determinism (some
arrows in the new machine may lead to several states on a given input),
it may yield a partial transition function (there may be some states in
the converted machine which have no transition defined on a given input
symbol), and it may not yield a well-defined single initial state (since
the original machine may have had several final states). Therefore in fact
we will convert M into a NFA N, which we can then convert to the DFA M'
using the usual techniques (i.e., those of Theorem 1.19).
This said, let
We define the NFA N as follows:
where:
d'(q,a) = { r |
d(r,a) = q }
for all q in Q and a in S ;
d'(qi,e)
= F ;
d'(q,e)
= {} for all q in Q ;
d'(qi,a) = {}
for all a in S .
Without producing a rigorous proof by induction of the claim that N will
recognize AR, we can see informally that any sequence of states
that will cause M to accept a string w will allow N to accept wR.
N can go by an epsilon transition from its new initial state to the correct
final state of M and then by reversed transitions through the appropriate
states until it reaches the now-final state of N (corresponding to the initial
state of M). This plus the application of Theorem 1.19 completes the
construction of a DFA M' which will recognize AR and thus the proof.
For each n, we can directly construct a DFA Mn which will
recognize the language Bn. The idea is that the machine will
have n states, and transitions on input symbol "a" leading in a circular
fashion from the initial state, through each state in (ordinal) turn,
until it finally returns from the last state to the initial state again.
This last state will be the only final state in the machine.
Informally, if the machine reads a string of "a"s whose length is a
multiple of n (including possibly 0 for the empty string), it will
cycle through the n states exactly that multiple of times, thus ending
up in the final (also initial) state. On the other hand, if it reads
a string of "a"s whose length is not a multiple of n, then it
will end up in some state other than the final one, and thus not accept
the string.
More formally, we construct the machine M as follows:
where:
d(qi,a) = qi+1
for all i between 0 and n-1 (inclusive) ; and
d(qn-1,a) = q0 .
|