Sunday, 2 December 2012

DFSA? NFSA? Regular Expression! (Part II)

So as we went over the basic on the previous post. I'll have something that's more challenging that'll take more effort to tackle it.

Give a DFA for each language below.

    (a) L_1 = { s (- {0,1}* : s contains at least 2 characters and s's
            second character is a 1 }

        We only need to keep track of which character we are processing for
        the first 2 characters, to ensure the second one is a 1.  Using the
        ASCII conventions from lecture (parentheses around accepting
        states, self-loops indicated by labels next to states, dead states
        not shown), we get the following DFA:

                           0,1        1
            --> q_0 ----> q_1 ----> (q_2) 0,1

        (Note: this has implicit dead state q_3.)

    (b) L_2 = { s (- {0,1}* : s contains fewer than 2 characters }

        Note that L_2 = { \epsilon, 0, 1 }.

                            0,1
            --> (q_0) ----> (q_1)

        (Note: this has implicit dead state q_2.)

    (c) L_4 = { s (- {a,b}* : every a in s is _eventually_ followed by b }
        For example, aaab (- L_4 because there is a 'b' that follows every
        'a'-- even though it is not immediately after the first two 'a's.

        Note that L_4 = { every string that does *not* end with an 'a' }.

                                 a
                        b      --->     a
            -->  (q_0)            ( q_1)
                               <---
                                  b

No comments:

Post a Comment