Languages and Finite Automata - Download as PowerPoint by 3RSlbgu

VIEWS: 7 PAGES: 57

									Finite Automata




    Costas Busch - RPI   1
 Finite Automaton

   Input
  String

                           Output
Finite                     String
Automaton



      Costas Busch - RPI            2
  Finite Accepter

  Input
  String
                            Output
                           “Accept”
Finite
                              or
Automaton
                           “Reject”



      Costas Busch - RPI              3
           Transition Graph
Abba -Finite Accepter                   a,b

                                         q5
             a                                a,b
    b             a    b
   q0 a     q1 b q2 b q3 a                    q4

 initial                                   final
 state                                     state
                     transition
           state                          “accept”

                   Costas Busch - RPI                4
      Initial Configuration
           Input String
a b b a

                                   a,b

                                    q5
           a                             a,b
   b            a    b
  q0 a    q1 b q2 b q3 a                 q4


              Costas Busch - RPI               5
          Reading the Input

a b b a

                                    a,b

                                     q5
           a                              a,b
   b            a    b
  q0 a    q1 b q2 b q3 a                  q4


               Costas Busch - RPI               6
a b b a

                                   a,b

                                    q5
           a                             a,b
   b            a    b
  q0 a    q1 b q2 b q3 a                 q4


              Costas Busch - RPI               7
a b b a

                                   a,b

                                    q5
           a                             a,b
   b            a    b
  q0 a    q1 b q2 b q3 a                 q4


              Costas Busch - RPI               8
a b b a

                                   a,b

                                    q5
           a                             a,b
   b            a    b
  q0 a    q1 b q2 b q3 a                 q4


              Costas Busch - RPI               9
   Input finished

a b b a

                                   a,b

                                    q5
           a                             a,b
   b            a    b
  q0 a    q1 b q2 b q3 a                 q4

                             Output: “accept”
              Costas Busch - RPI                10
           Rejection

a b a

                                  a,b

                                   q5
          a                             a,b
   b           a    b
  q0 a   q1 b q2 b q3 a                 q4


             Costas Busch - RPI               11
a b a

                                  a,b

                                   q5
          a                             a,b
   b           a    b
  q0 a   q1 b q2 b q3 a                 q4


             Costas Busch - RPI               12
a b a

                                  a,b

                                   q5
          a                             a,b
   b           a    b
  q0 a   q1 b q2 b q3 a                 q4


             Costas Busch - RPI               13
a b a

                                  a,b

                                   q5
          a                             a,b
   b           a    b
  q0 a   q1 b q2 b q3 a                 q4


             Costas Busch - RPI               14
 Input finished

a b a

                                   a,b
                                       Output:
                                    q5 “reject”
          a                            a,b
   b           a    b
  q0 a   q1 b q2 b q3 a                  q4


              Costas Busch - RPI                  15
       Another Rejection

                  

                                 a,b

                                  q5
         a                             a,b
 b            a    b
q0 a    q1 b q2 b q3 a                 q4


            Costas Busch - RPI               16
                     

                                    a,b

                                     q5
            a                             a,b
   b             a    b
  q0 a     q1 b q2 b q3 a                 q4

Output:
“reject”       Costas Busch - RPI               17
        Another Example

a a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               18
a a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               19
a a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               20
a a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               21
  Input finished

a a b


  a                                      a,b
            Output: “accept”

  q0    b                          a,b
                       q1                q2



              Costas Busch - RPI               22
            Rejection

b a b


  a                                     a,b


  q0    b                         a,b
                      q1                q2



             Costas Busch - RPI               23
b a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               24
b a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               25
b a b


  a                                    a,b


  q0    b                        a,b
                     q1                q2



            Costas Busch - RPI               26
 Input finished

b a b


  a                                        a,b


  q0    b                          a,b
                       q1                  q2

                                   Output: “reject”

              Costas Busch - RPI                  27
                  Formalities
Deterministic Finite Accepter (DFA)

              M  Q, , , q0 , F 
  Q : set of states
   : input alphabet
      : transition function
  q0   : initial state

  F    : set of final states
                     Costas Busch - RPI   28
       Input Alphabet 

  a, b

                                  a,b

                                   q5
 b      a                               a,b
             a    b
q0 a   q1 b q2 b q3 a                   q4

             Costas Busch - RPI               29
               Set of States Q
Q  q0 , q1, q2 , q3 , q4 , q5


                                         a,b

                                          q5
               a                               a,b
      b             a    b
     q0 a     q1 b q2 b q3 a                   q4

                    Costas Busch - RPI               30
        Initial State q0



                                a,b

                                 q5
        a                             a,b
 b           a    b
q0 a   q1 b q2 b q3 a                 q4


           Costas Busch - RPI               31
         Set of Final States F

F  q4 

                                     a,b

                                      q5
             a                             a,b
   b              a    b
  q0 a      q1 b q2 b q3 a                 q4


                Costas Busch - RPI               32
  Transition Function 

        :Q  Q

                              a,b

                               q5
 b      a                           a,b
             a    b
q0 a   q1 b q2 b q3 a               q4

         Costas Busch - RPI               33
        q0 , a   q1

                                a,b

                                 q5
 b       a                            a,b
              a    b
q0 a    q1 b q2 b q3 a                q4

           Costas Busch - RPI               34
        q0 , b   q5

                                a,b

                                 q5
 b       a                            a,b
              a    b
q0 a    q1 b q2 b q3 a                q4

           Costas Busch - RPI               35
        q2 , b   q3

                                a,b

                                 q5
 b       a                            a,b
              a    b
q0 a    q1 b q2 b q3 a                q4

           Costas Busch - RPI               36
          Transition Function 
     a    b
q0   q1   q5
q1   q5   q2
q2   q5   q3
q3   q4   q5                           a,b
q4   q5   q5
q5   q5   q5                            q5
                b        a                   a,b
                              a    b
               q0 a     q1 b q2 b q3 a       q4
                  Costas Busch - RPI              37
Extended Transition Function  *

          * : Q  *  Q

                                  a,b

                                   q5
   b       a                            a,b
                a    b
  q0 a    q1 b q2 b q3 a                q4

             Costas Busch - RPI               38
        * q0 , ab  q2

                                  a,b

                                   q5
 b        a                             a,b
               a    b
q0 a     q1 b q2 b q3 a                 q4

             Costas Busch - RPI               39
        * q0 , abba  q4

                                 a,b

                                  q5
 b        a                            a,b
               a    b
q0 a     q1 b q2 b q3 a                q4

            Costas Busch - RPI               40
   * q0 , abbbaa  q5

                              a,b

                               q5
 b      a                           a,b
             a    b
q0 a   q1 b q2 b q3 a               q4

         Costas Busch - RPI               41
Observation: There is a walk from               q to q
             with label w

                  * q, w  q

        q                    w                  q



                 w  1 2  k
            1   2                        k
        q                                       q

                      Costas Busch - RPI                  42
Example: There is a walk from q0 to q5
            with label abbbaa

          * q0 , abbbaa  q5
                                       a,b

                                        q5
         b      a                            a,b
                     a    b
        q0 a   q1 b q2 b q3 a                q4

                  Costas Busch - RPI               43
                           Recursive Definition
                             * q ,    q
                             * q, w    ( * (q, w), )


                       q              w                    q1         q

 *  q , w    q
                             * q, w    (q1, )
 (q1, )  q
                                                            * q, w    ( * (q, w), )
                             * q, w  q1


                                      Costas Busch - RPI                              44
 * q0 , ab  
  * (q0 , a ), b  
   * q0 ,  , a , b  
  q0 , a , b  
 q1 , b  
q2                                            a,b

                                               q5
           b          a                             a,b
                           a    b
          q0 a       q1 b q2 b q3 a                 q4
                         Costas Busch - RPI               45
      Languages Accepted by DFAs
Take DFA   M

Definition:
  The language LM  contains
  all input strings accepted by M


 LM  = { strings that drive M         to a final state}



                   Costas Busch - RPI                       46
             Example
LM   abba                                   M

                                      a,b

                                       q5
      b      a                              a,b
                  a    b
     q0 a   q1 b q2 b q3 a                  q4
                                        accept

                 Costas Busch - RPI                  47
              Another Example
LM    , ab, abba                             M

                                       a,b

                                        q5
         b       a            a              a,b
                           b
        q0 a    q1 b q2 b q3 a               q4
     accept           accept             accept

                  Costas Busch - RPI                   48
                  Formally
For a DFA   M  Q, , , q0 , F 

Language accepted by      M :
     LM   w  * :  * q0 , w  F 


     q0             w                   q   q  F


                   Costas Busch - RPI                 49
                  Observation
Language rejected by M :

        LM   w  * :  * q0 , w  F 


   q0               w                      q   q  F




                      Costas Busch - RPI                 50
       More Examples


     LM   {a b : n  0}
                     n


a                                       a,b


q0   b                          a,b
                    q1                   q2

               accept                 trap state

           Costas Busch - RPI                  51
LM = { all strings with prefix ab }
                                           a,b



   q0      a              q1         b      q2

            b               a              accept

                         q3          a,b

                Costas Busch - RPI                  52
L M  = { all strings without
           substring 001 }


   1                               0        0,1
        1

                      0                1
              0                    00       001

        0
                  Costas Busch - RPI              53
            Regular Languages

A language L is regular if there is
a DFA M such that L  LM 




All regular languages form a language family


                   Costas Busch - RPI          54
Examples of regular languages:

  abba      , ab, abba                {a b : n  0}
                                               n

 { all strings with prefix              ab }
  { all strings with prefix             ab }
  { all strings without substring 001 }


 There exist automata that accept these
 Languages (see previous slides).
                   Costas Busch - RPI                      55
               Another Example
The language    L  awa : w  a, b*
is regular:
                                               a
                                      b
 L  LM                                  b
                q0        a           q2       q3

                  b                        a
                q4

                      a,b
                      Costas Busch - RPI            56
There exist languages which are not Regular:


   Example:     L {a b : n  0}
                      n n



There is no DFA that accepts such a language


   (we will prove this later in the class)




                     Costas Busch - RPI        57

								
To top