Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

1-solutions

VIEWS: 4 PAGES: 4

									CS 360 Introduction to the Theory of Computing                                            Spring 2008


                                      Assignment 1 Solutions

Let us fix the alphabet Σ = {0, 1} for all of this assignment.


1. [3 points] Give a DFA that recognizes the language

                                    L1 = {x ∈ Σ∗ : 1110 is not a prefix of x}.

    Solution:

    To maintain information about the prefix of a word, states q1 , q11 , q111 , and q1110 are intro-
    duced. All states but q1110 are accepting. This way DFA accepts an empty string, strings with
    ≤ 3 symbols, and any string that doesn’t start with 1110.



                       q1       1       q11      1    q111        0     q1110

                                          0      0
                      1                                       1
                                                                         0, 1
                       qi                0                q           0, 1




2. [3 points] Give a DFA that recognizes the language

        L2 = {x ∈ Σ∗ : x contains the substring 010, but does not contain the substring 0101}.

    Solution:

    States q0 , q01 , and qacc,010 correspond to symbol 0, two symbols 01, and three symbols 010
    having been last read, respectively. States qacc,0 and qacc,01 play the same role but they also
    carry the information that a string contains a substring 010 (that has already been read), and
    therefore, are accepting. States qi and qacc,i correspond to either no symbol having been read,
    or the last symbol being 1 (but the last two symbols not being 01), where qacc,i also carries the
    information that a string contains a substring 010 that has already been read. qerror state can
    only be reached from a state qacc,010 on an input symbol 1. This is a self-loop error state which
    means that a substring 0101 was met in the input string.




                                                      1
                             1              0



                             qi      0     q0          1    q01     0   qacc,010

                                            1               0
                                                                            1
                                                       0

                          qacc,0     1   qacc,01       1   qacc,i       qerror


                                            0
                             0                               1            0, 1

3. [6 points] Argue that for every string w ∈ Σ∗ , the following two languages are regular:
                                   L3 = {x ∈ Σ∗ : x is a prefix of w}
                                   L4 = {x ∈ Σ∗ : w is a prefix of x}.
  (Note that the languages L3 and L4 depend on the choice of w, meaning that if you change w,
  you change the languages.)

  Solution:

  There are several approaches to show that a language is regular.

  Let w be of length n. Then, each string in L3 is of length ≤ n. However, there are only finitely
  many strings of length ≤ n. Therefore, L3 is finite, and regular.

  Let Lw = {w} be a language that contains only one string. It is clear that Lw is regular, since it
  is finite. Let L = Σ∗ be a language over Σ. It is also regular since it can be expressed with a reg-
  ular expression (or recognized by a single self-loop accepting state DFA). Clearly, L4 = Lw L.
  Since regular languages are closed under concatenation, L4 is also regular.

  Express L4 with a regular expression s1 s2 . . . sn Σ∗ , rewriting a string w as a sequence of sym-
  bols s1 . . . sn (for n = 0 we define it to be ǫ). Therefore, L4 is regular.

  Rewrite w as a sequence of symbols s1 . . . sn . Then it is simple to construct NFAs that accept
  L3 ,


              s1                   s2                       ...                       sn
     q0                 q1                  q2                               qn−1               qn

  and L4 :                                                                                     0, 1


              s1                   s2                       ...                       sn
     q0                 q1                  q2                               qn−1               qn



                                                   2
4. [5 points] Consider the following NFA N :


                                                    1
                                  q1                                q2          0
                                                 0, 1


 (a) [2 points] Give the state transition diagram of a DFA that recognizes the language L(N ).

     Solution:

     This DFA is constructed as described in the course handout (NFA to DFA). Since there is
     no transition from q1 on symbol 0 in N , an error state ∅ is added.



                       0, 1            ∅                    0, 1   {q1 , q2 }


                                   0                                 0
                                                        1
                                    q1                                q2

                                                        1


 (b) [3 points] Give an NFA with two states that recognizes L(N ).

     Solution:

     It is easy to construct a DFA that recognizes L(N ) using the solution to part (a). It is suffi-
     cient to just interchange the roles of accepting and non-accepting states. Then it is not hard
     to see that L(N ) can be expressed with a regular expression 1(11)∗ ∪ (11)∗ 0Σ∗ . Here is an
     NFA that accepts this language (you can double check it by quickly converting this NFA to
     DFA and comparing it to a complement of a DFA that you got in part (a)).


                                                    0, 1
                                    q1                                q2

                                                        1

                                       0




                                                3
5. [3 points] Give a regular expression for the language

                    L5 = {x ∈ Σ∗ : x contains at least two 0’s and at most one 1}.

  Solution:
                                        (010 ∪ 100 ∪ 00 ∪ 000∗ 1)0∗



6. [5 points] Suppose that A is a regular language over Σ. Define

                     L6 = {x ∈ Σ∗ : x is a substring of at least one string in A}.

  Argue that L6 is also regular.

  Solution:

  Since A is regular, there exists a DFA M that accepts it. Construct an ε-NFA N that recog-
  nizes L6 as follows.

     1. Create a new initial state qi
     2. Add ε transitions from qi to every state that is reachable from an old start state in M
     3. If one of the accepting states in M can be reached from a state q in M , mark q as an
        accepting state in N

  This NFA will accept substrings of all strings in A, as required.




                                                   4

								
To top