SlideShare uma empresa Scribd logo
1 de 115
Pushdown
Automata
PDAs
Pushdown Automaton --
PDA Input String
                 Stack


 States
Initial Stack Symbol


     Stack               Stack



      $                       z

               bottom
             special symbol
The States
   Input          Pop            Push
   symbol         symbol         symbol



                 a, b   c
            q1              q2
a, b   c
                      q1              q2


input
           a                                a   

   stack
        b       top                        c
        h                  Replace         h
        e                                  e
        $                                  $
a,      c
                      q1               q2


input
           a                                 a   

   stack                                    c
        b       top                         b
        h                   Push            h
        e                                   e
        $                                   $
a, b
                      q1           q2


input
           a                             a   

   stack
        b       top
        h                    Pop        h
        e                               e
        $                               $
a,
                      q1               q2


input
           a                                 a   

   stack
        b       top                         b
        h                  No Change        h
        e                                   e
        $                                   $
Non-Determinism

 a, b    c    q2

q1                             , b      c
                          q1                q2

 a, b    c                     transition
             q3

     These are allowed transitions in
     a Non-deterministic PDA (NPDA)
NPDA: Non-Deterministic
PDA
Example:




           a,       a     b, a


q0   ,          q1 b, a      q2   ,$   $ q
                                          3
Execution Example: Time 0
  Input
   a a a b b b
                                          $
                                      Stack


current       a,       a     b, a
state
          ,           b, a           ,$   $ q
  q0               q1           q2           3
Time 1
Input
 a a a b b b
                                       $
                                   Stack


         a,        a      b, a


q0   ,        q1   b, a      q2   ,$   $ q
                                          3
Time 2
Input
 a a a b b b                           a
                                       $
                                   Stack

         a,        a      b, a


q0   ,        q1   b, a      q2   ,$       $ q
                                              3
Time 3
Input                                  a
 a a a b b b                           a
                                       $
                                   Stack


         a,        a      b, a


q0   ,        q1   b, a      q2   ,$   $ q
                                          3
Time 4
                                       a
Input
                                       a
 a a a b b b                           a
                                       $
                                   Stack

         a,        a      b, a


q0   ,        q1   b, a      q2   ,$   $ q
                                          3
Time 5
                                     a
Input
                                     a
 a a a b b b                         a
                                     $
                                 Stack

         a,       a     b, a


q0   ,        q1 b, a      q2   ,$       $ q
                                            3
Time 6
Input                                a
 a a a b b b                         a
                                     $
                                 Stack

         a,       a     b, a


q0   ,        q1 b, a      q2   ,$   $ q
                                        3
Time 7
Input
 a a a b b b                          a
                                      $
                                     Stack


         a,       a     b, a


q0   ,        q1 b, a      q2   ,$     $ q
                                          3
Time 8
Input
 a a a b b b
                                      $
                                     Stack


         a,       a     b, a
                                       accept

q0   ,        q1 b, a      q2   ,$     $ q
                                          3
The Language of PDA
A string is accepted if there is
a computation such that:

     • All the input is consumed

     • The last state is a final state

At the end of the computation,
we do not care about the stack contents
Formal Definition Automaton
Non-Deterministic Pushdown
                 NPDA
         M   (Q, Σ, Γ, δ, q0 , z, F )   Final
States                                  states

Input                                   Stack
alphabet        Transition Initial      start
       Stack
                function   state        symbol
       alphabet
Instantaneous Description
            ( q, u , s )

  Current                  Current
             Remaining
  state                    stack
             input
                           contents
Acceptance by Final State


L(M)= set of all strings w such that starting
  from initial ID machine consumes w from
  input and enters an accepting state.
The contents of the stack at that time is
  irrelevant.
{w | (q0, w, Z) * (q, , )
For some final state q of F and any stack
  staring .
Acceptance by empty
stack
 N(M) = (w | (q0,w,Z)    * (q,   ,   )

 That is N(M) is the set of all strings w such
  that M can consume w and at the same
  time empties its stack.Here we do not
  care whether q is a final state or not.
The input string aaabbb
         is accepted by the NPDA:



             a,       a     b, a


q0   ,            q1 b, a      q2   ,$   $ q
                                            3
In general,
                      n n
              L {a b : n 0}

is the language accepted by the NPDA:



              a,       a     b, a


 q0   ,            q1 b, a      q2   ,$   $ q
                                             3
Another NPDA example
                   NPDA      M
                                 R
                  L( M ) {ww }

a,        a           a, a
b,        b           b, b


     q0       ,           q1         ,$   $   q2
Execution Example:   Time 0
  Input
       a b b a
                                         $
                                       Stack
  a,        a        a, a
  b,        b        b, b


       q0       ,       q1    ,$   $     q2
Time 1
Input
     a b b a
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 2
Input
                                      b
     a b b a
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 3
Input
                                           b
     a b b a
                  Guess the middle         a
                  of string                $
                                         Stack
a,        a         a, a
b,        b         b, b


     q0       ,        q1     ,$     $     q2
Time 4
Input
                                      b
     a b b a
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 5
Input
     a b b a
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,            ,$   $     q2
                     q1
Time 6
Input
     a b b a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b
                                    accept
     q0       ,      q1    ,$   $     q2
Rejection Example:   Time 0
  Input
       a b b b
                                         $
                                       Stack
  a,        a        a, a
  b,        b        b, b


       q0       ,       q1    ,$   $     q2
Time 1
Input
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 2
Input
                                      b
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 3
Input
                                           b
     a b b b
                  Guess the middle         a
                  of string                $
                                         Stack
a,        a         a, a
b,        b         b, b


     q0       ,        q1     ,$     $     q2
Time 4
Input
                                      b
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 5
Input             There is no possible transition.

     a b b b            Input is not          a
                        consumed
                                              $
                                            Stack
a,        a              a, a
b,        b              b, b


     q0       ,                   ,$    $     q2
                            q1
Another computation on same string:
  Input             Time 0
       a b b b
                                        $
                                      Stack
  a,        a       a, a
  b,        b       b, b


       q0       ,      q1    ,$   $     q2
Time 1
Input
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 2
Input
                                      b
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 3
Input                                 b
                                      b
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 4              b
Input                                 b
                                      b
     a b b b
                                      a
                                      $
                                    Stack
a,        a       a, a
b,        b       b, b


     q0       ,      q1    ,$   $     q2
Time 5                b
Input                                    b
                  No final state         b
     a b b b      is reached             a
                                         $
                                       Stack
a,        a        a, a
b,        b        b, b


     q0       ,       q1    ,$     $     q2
There is no computation
          that accepts string abbb

                  abbb L(M )


a,        a          a, a
b,        b          b, b


     q0       ,         q1     ,$   $   q2
Pushing Strings
    Input          Pop            Push
    symbol         symbol         string



                  a, b   w
             q1              q2
Example:
                           a, b    cdf
                      q1                 q2

input
   
           a    
                                        
                                                 a   
                                                      


                                              c       pushed
   stack                                      d
                top                                   string
        b                                     f
        h                   Push              h
        e                                     e
        $                                     $
Another NPDA example
                  NPDA   M
        L( M ) {w : na            nb }

 a, $   0$        b, $   1$
 a, 0   00        b, 1   11
 a, 1             b, 0


                         ,$   $      q2
             q1
Execution Example:            Time 0
  Input
   a b       b a a b

                                                $
     a, $    0$        b, $    1$
                                           Stack
     a, 0    00        b, 1    11
     a, 1              b, 0
   current
   state                       ,$      $
                  q1                       q2
Time 1
Input
 a b     b a a b
                                            0
                                            $
  a, $   0$        b, $    1$          Stack
  a, 0   00        b, 1    11
  a, 1             b, 0


                            ,$     $   q2
              q1
Time 3
Input
 a b     b b a a
                                            0
                                            $
  a, $   0$        b, $    1$          Stack
  a, 0   00        b, 1    11
  a, 1             b, 0


                           ,$      $   q2
              q1
Time 4
Input
 a b     b b a a
                                            1
                                            $
  a, $   0$        b, $    1$          Stack
  a, 0   00        b, 1    11
  a, 1             b, 0


                           ,$      $   q2
              q1
Time 5
Input
 a b     b b a a                            1
                                            1
                                            $
  a, $   0$        b, $    1$          Stack
  a, 0   00        b, 1    11
  a, 1             b, 0


                           ,$      $   q2
              q1
Time 6
Input
 a b     b b a a                            1
                                            1
                                            $
  a, $   0$        b, $    1$          Stack
  a, 0   00        b, 1    11
  a, 1             b, 0


                           ,$      $   q2
              q1
Time 7
Input
 a b     b b a a
                                            1
                                            $
  a, $   0$        b, $    1$          Stack
  a, 0   00        b, 1    11
  a, 1             b, 0


                           ,$      $   q2
              q1
Time 8
Input
 a b     b b a a

                                             $
  a, $   0$        b, $    1$
                                        Stack
  a, 0   00        b, 1    11
  a, 1             b, 0
                                       accept
                           ,$      $    q2
              q1
Formalities for
NPDAs
a, b   w
               q1              q2

Transition function:


              (q1, a, b) {(q2 , w)}
a, b    w   q2

              q1

               a, b    w   q3

Transition function:

        (q1, a, b) {(q2 , w), (q3 , w)}
Formal Definition Automaton
Non-Deterministic Pushdown
                 NPDA
         M   (Q, Σ, Γ, δ, q0 , z, F )   Final
States                                  states

Input                                   Stack
alphabet        Transition Initial      start
       Stack
                function   state        symbol
       alphabet
Instantaneous Description
            ( q, u , s )

  Current                  Current
             Remaining
  state                    stack
             input
                           contents
Example:      Instantaneous Description
                    (q1, bbb, aaa$)
                                              a
Time 4:       Input                           a
                   a a a b b b                a
                                              $
                                            Stack
              a,        a      b, a


  q0      ,        q1   b, a      q2   ,$   $ q
                                               3
Example:      Instantaneous Description
                        (q2 , bb, aa$)
                                                a
Time 5:       Input                             a
                   a a a b b b                  a
                                                $
                                              Stack
              a,        a       b, a


  q0      ,        q1    b, a      q2    ,$   $ q
                                                 3
We write:



    (q1, bbb, aaa$)  (q2 , bb, aa$)
      Time 4              Time 5
A computation:

(q0 , aaabbb,$)  (q1, aaabbb,$) 
(q1, aabbb, a$)  (q1, abbb, aa$)  (q1, bbb, aaa$) 
(q2 , bb, aa$)  (q2 , b, a$)  (q2 , ,$)  (q3 , ,$)


                a,        a      b, a


   q0    ,           q1   b, a      q2    ,$     $ q
                                                    3
(q0 , aaabbb,$)  (q1, aaabbb,$) 
(q1, aabbb, a$)  (q1, abbb, aa$)  (q1, bbb, aaa$) 
(q2 , bb, aa$)  (q2 , b, a$)  (q2 , ,$)  (q3 , ,$)


    For convenience we write:


           (q0 , aaabbb ,$)  (q3 , ,$)
Formal Definition
Language of NPDA M :


   L( M ) {w : (q0 , w, s )  (q f , , s ' )}


     Initial state                Final state
Example:
            (q0 , aaabbb,$)  (q3 , ,$)


                      aaabbb L(M )

 NPDA M :

            a,        a      b, a


  q0   ,         q1   b, a      q2   ,$   $ q
                                             3
n n
           (q0 , a b ,$)  (q3 , ,$)

                          n n
                         a b       L(M )

NPDA M :

           a,        a          b, a


 q0   ,         q1   b, a          q2   ,$   $ q
                                                3
Therefore:                  n n
                L( M ) {a b : n 0}




NPDA M :

           a,        a      b, a


 q0   ,         q1   b, a      q2   ,$   $ q
                                            3
NPDAs Accept
Context-Free
Languages
Theorem:

  Context-Free    Languages
    Languages    Accepted by
   (Grammars)      NPDAs
Proof - Step 1:

  Context-Free            Languages
    Languages            Accepted by
   (Grammars)              NPDAs


 Convert any context-free grammar G
 to a NPDA M with: L (G ) L( M )
Proof - Step 2:

  Context-Free           Languages
    Languages           Accepted by
   (Grammars)             NPDAs


 Convert any NPDA M to a context-free
 grammar G with: L (G ) L( M )
Converting
Context-Free
Grammars
to
NPDAs
An example grammar:   S   aSTb
                      S   b
                      T   Ta
                      T

What is the equivalent NPDA?
Grammar:
S   aSTb
S   b                NPDA:
T   Ta
               ,S   aSTb
T
               ,S   b
               ,T   Ta   a, a
               ,T        b, b


    q0     ,    S            ,$   $
                      q1              q2
The NPDA simulates
leftmost derivations of the grammar




       L(Grammar) = L(NPDA)
Grammar: S     aSTb
          S    b
          T    Ta
          T


A leftmost derivation:

    S   aSTb       abTb   abTab   abab
NPDA execution: Time 0

Input   a b a b

              ,S   aSTb               $
              ,S   b                Stack
              ,T   Ta   a, a
current       ,T        b, b
state
          ,    S           ,$   $
   q0                q1               q2
Time 1

Input   a b a b
                                      S
             ,S    aSTb               $
             ,S    b                Stack
             ,T    Ta   a, a
             ,T         b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 2             a
                                     S
Input   a b a b
                                     T
                                     b
             ,S   aSTb               $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 3             a
                                     S
Input   a b a b
                                     T
                                     b
             ,S   aSTb               $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 4
                                     b
Input   a b a b
                                     T
                                     b
             ,S   aSTb               $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 5
                                     b
Input   a b a b
                                     T
                                     b
             ,S   aSTb               $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 6
                                     T
Input   a b a b                      a
                                     b
             ,S   aSTb               $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 7
                                     T
Input   a b a b                      a
                                     b
             ,S   aSTb               $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 8

Input   a b a b                       a
                                      b
             ,S   aSTb                $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 9

Input   a b a b
                                      b
             ,S   aSTb                $
             ,S   b                 Stack
             ,T   Ta   a, a
             ,T        b, b


   q0    ,    S            ,$   $
                     q1               q2
Time 10

Input   a b a b

             ,S   aSTb                 $
             ,S   b                  Stack
             ,T   Ta   a, a
             ,T        b, b
                                     accept

   q0    ,    S             ,$   $
                     q1                q2
In general:

    Given any grammar    G

    We can construct a NPDA    M

     With     L(G )   L( M )
Constructing NPDA         M from grammar G :

 For any production                   For any terminal
         A       w                             a


                     ,A   w        a, a


    q0       ,        S               ,$   $
                              q1                   q2
Grammar     G generates string w

if and only if

NPDA      M accepts w



     L(G)    L( M )
Therefore:


     For any context-free language
     there is an NPDA
     that accepts the same language
Converting
NPDAs
to
Context-Free
Grammars
For any NPDA    M

we will construct

a context-free grammar    G with

             L( M )   L(G )
Intuition: The grammar simulates the machine


A derivation in Grammar   G:

   S        abc ABC                 abc



    Current configuration in NPDA   M
A derivation in Grammar    G:
           terminals      variables
    S         abc ABC                 abc


    Input processed          Stack contents

                 in NPDA     M
Some Necessary
Modifications
First, we modify the NPDA:
    • It has a single final state q f
    • It empties the stack
      when it accepts the input


   Original NPDA              Empty Stack

                                        qf
Second, we modify the NPDA transitions:

     all transitions will have form

                        a, B       qj
                   qi

                           or

                   qi   a, B    CD q
                                     j


B, C , D : stack symbols
Example of a NPDA in correct form:

           L( M ) {w : na         nb }

    $ : initial stack symbol

    a, $    0$        b, $   1$
    a, 0    00        b, 1   11
    a, 1              b, 0


                             ,$          qf
                 q0
The Grammar
 Construction
In grammar G :
                   Stack symbol

          Variables:   (qi Bq j )

                        states



          Terminals:
          Input symbols of NPDA
For each transition
                            a, B       qj
                       qi




We add production     (qi Bq j )   a
For each transition   qi   a, B      CD q
                                          j




We add production (qi Bqk )       a(q j Cql )(ql Dqk )

                      For all states qk , ql
Stack bottom symbol


Start Variable:     (qo $q f )


      Start state                final state
Example:
    a, $   0$        b, $   1$
    a, 0   00        b, 1   11
    a, 1             b, 0


                            ,$         qf
                q0



Grammar production:         (q01q0 )   a
Example:
     a, $    0$        b, $   1$
     a, 0    00        b, 1   11
     a, 1              b, 0


                              ,$          qf
                  q0
Grammar productions:
(q0 $q0 )    b(q01q0 )(q0 $q0 ) | b(q01q f )(q f $q0 )
(q0 $q f )   b(q01q0 )(q0 $q f ) | b(q01q f )(q f $q f )
Example:
     a, $   0$        b, $   1$
     a, 0   00        b, 1   11
     a, 1             b, 0


                             ,$   qf
                 q0


Grammar production: (q0 $q f )
Resulting Grammar:          (q0 $q f ) : start variable


(q0 $q0 )    b(q01q0 )(q0 $q0 ) | b(q01q f )(q f $q0 )
(q0 $q f )   b(q01q0 )(q0 $q f ) | b(q01q f )(q f $q f )

(q01q0 )     b(q01q0 )(q01q0 ) | b(q01q f )(q f 1q0 )
(q01q f )    b(q01q0 )(q01q f ) | b(q01q f )(q f 1q f )

(q0 $q0 )    a (q0 0q0 )(q0 $q0 ) | a (q0 0q f )(q f $q0 )
(q0 $q f )    a (q0 0q0 )(q0 $q f ) | a (q0 0q f )(q f $q f )
(q0 0q0 )    a (q0 0q0 )(q0 0q0 ) | a (q0 0q f )(q f 0q0 )
(q0 0q f )   a (q0 0q0 )(q0 0q f ) | a (q0 0q f )(q f 0q f )

       (q01q0 )     a
       (q0 0q0 )    b

       (q0 $q f )
Derivation of string         abba

(q0 $q f )    a(q0 0q0 )(q0 $q f )

                      ab(q0 $q f )

             abb(q01q0 )(q0 $q f )

                   abba(q0 $q f )       abba
In general, in Grammar:

            (q0 $q f )    w

              if and only if


      w is accepted by the NPDA
Explanation:

   By construction of Grammar:

               (qi Aq j )   w

               if and only if

    in the NPDA going from qi to q j
    the stack doesn’t change below A
    and A is removed from stack

Mais conteúdo relacionado

Mais procurados

Push down automata
Push down automataPush down automata
Push down automata
Somya Bagai
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
lavishka_anuj
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
chidabdu
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Non regular languages
Non regular languagesNon regular languages
Non regular languages
lavishka_anuj
 

Mais procurados (20)

Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Push down automata
Push down automataPush down automata
Push down automata
 
Push down automata
Push down automataPush down automata
Push down automata
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
3.4 deterministic pda
3.4 deterministic pda3.4 deterministic pda
3.4 deterministic pda
 
Turing machine
Turing machineTuring machine
Turing machine
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
PUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINEPUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINE
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Restoring & Non-Restoring Division Algorithm By Sania Nisar
Restoring & Non-Restoring Division Algorithm By Sania NisarRestoring & Non-Restoring Division Algorithm By Sania Nisar
Restoring & Non-Restoring Division Algorithm By Sania Nisar
 
Undecidability.pptx
Undecidability.pptxUndecidability.pptx
Undecidability.pptx
 
push down automata
push down automatapush down automata
push down automata
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
 
Pda
PdaPda
Pda
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
RABIN KARP ALGORITHM STRING MATCHING
RABIN KARP ALGORITHM STRING MATCHINGRABIN KARP ALGORITHM STRING MATCHING
RABIN KARP ALGORITHM STRING MATCHING
 
Non regular languages
Non regular languagesNon regular languages
Non regular languages
 
Automata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAutomata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfa
 

Mais de lavishka_anuj

Mais de lavishka_anuj (7)

Properties of cfg
Properties of cfgProperties of cfg
Properties of cfg
 
One ques
One quesOne ques
One ques
 
Moore and mealy machines
Moore and mealy machinesMoore and mealy machines
Moore and mealy machines
 
Grammar
GrammarGrammar
Grammar
 
Flat
FlatFlat
Flat
 
Finite automata intro
Finite automata introFinite automata intro
Finite automata intro
 
Finite automata
Finite automataFinite automata
Finite automata
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Pushdown automata

  • 2. Pushdown Automaton -- PDA Input String Stack States
  • 3. Initial Stack Symbol Stack Stack $ z bottom special symbol
  • 4. The States Input Pop Push symbol symbol symbol a, b c q1 q2
  • 5. a, b c q1 q2 input  a   a  stack b top c h Replace h e e $ $
  • 6. a, c q1 q2 input  a   a  stack c b top b h Push h e e $ $
  • 7. a, b q1 q2 input  a   a  stack b top h Pop h e e $ $
  • 8. a, q1 q2 input  a   a  stack b top b h No Change h e e $ $
  • 9. Non-Determinism a, b c q2 q1 , b c q1 q2 a, b c transition q3 These are allowed transitions in a Non-deterministic PDA (NPDA)
  • 10. NPDA: Non-Deterministic PDA Example: a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 11. Execution Example: Time 0 Input a a a b b b $ Stack current a, a b, a state , b, a ,$ $ q q0 q1 q2 3
  • 12. Time 1 Input a a a b b b $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 13. Time 2 Input a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 14. Time 3 Input a a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 15. Time 4 a Input a a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 16. Time 5 a Input a a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 17. Time 6 Input a a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 18. Time 7 Input a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 19. Time 8 Input a a a b b b $ Stack a, a b, a accept q0 , q1 b, a q2 ,$ $ q 3
  • 20. The Language of PDA A string is accepted if there is a computation such that: • All the input is consumed • The last state is a final state At the end of the computation, we do not care about the stack contents
  • 21. Formal Definition Automaton Non-Deterministic Pushdown NPDA M (Q, Σ, Γ, δ, q0 , z, F ) Final States states Input Stack alphabet Transition Initial start Stack function state symbol alphabet
  • 22. Instantaneous Description ( q, u , s ) Current Current Remaining state stack input contents
  • 23. Acceptance by Final State L(M)= set of all strings w such that starting from initial ID machine consumes w from input and enters an accepting state. The contents of the stack at that time is irrelevant. {w | (q0, w, Z) * (q, , ) For some final state q of F and any stack staring .
  • 24. Acceptance by empty stack N(M) = (w | (q0,w,Z) * (q, , ) That is N(M) is the set of all strings w such that M can consume w and at the same time empties its stack.Here we do not care whether q is a final state or not.
  • 25. The input string aaabbb is accepted by the NPDA: a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 26. In general, n n L {a b : n 0} is the language accepted by the NPDA: a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 27. Another NPDA example NPDA M R L( M ) {ww } a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 28. Execution Example: Time 0 Input a b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 29. Time 1 Input a b b a a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 30. Time 2 Input b a b b a a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 31. Time 3 Input b a b b a Guess the middle a of string $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 32. Time 4 Input b a b b a a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 33. Time 5 Input a b b a a $ Stack a, a a, a b, b b, b q0 , ,$ $ q2 q1
  • 34. Time 6 Input a b b a $ Stack a, a a, a b, b b, b accept q0 , q1 ,$ $ q2
  • 35. Rejection Example: Time 0 Input a b b b $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 36. Time 1 Input a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 37. Time 2 Input b a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 38. Time 3 Input b a b b b Guess the middle a of string $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 39. Time 4 Input b a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 40. Time 5 Input There is no possible transition. a b b b Input is not a consumed $ Stack a, a a, a b, b b, b q0 , ,$ $ q2 q1
  • 41. Another computation on same string: Input Time 0 a b b b $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 42. Time 1 Input a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 43. Time 2 Input b a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 44. Time 3 Input b b a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 45. Time 4 b Input b b a b b b a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 46. Time 5 b Input b No final state b a b b b is reached a $ Stack a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 47. There is no computation that accepts string abbb abbb L(M ) a, a a, a b, b b, b q0 , q1 ,$ $ q2
  • 48. Pushing Strings Input Pop Push symbol symbol string a, b w q1 q2
  • 49. Example: a, b cdf q1 q2 input   a     a   c pushed stack d top string b f h Push h e e $ $
  • 50. Another NPDA example NPDA M L( M ) {w : na nb } a, $ 0$ b, $ 1$ a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 51. Execution Example: Time 0 Input a b b a a b $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 current state ,$ $ q1 q2
  • 52. Time 1 Input a b b a a b 0 $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 53. Time 3 Input a b b b a a 0 $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 54. Time 4 Input a b b b a a 1 $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 55. Time 5 Input a b b b a a 1 1 $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 56. Time 6 Input a b b b a a 1 1 $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 57. Time 7 Input a b b b a a 1 $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 ,$ $ q2 q1
  • 58. Time 8 Input a b b b a a $ a, $ 0$ b, $ 1$ Stack a, 0 00 b, 1 11 a, 1 b, 0 accept ,$ $ q2 q1
  • 60. a, b w q1 q2 Transition function: (q1, a, b) {(q2 , w)}
  • 61. a, b w q2 q1 a, b w q3 Transition function: (q1, a, b) {(q2 , w), (q3 , w)}
  • 62. Formal Definition Automaton Non-Deterministic Pushdown NPDA M (Q, Σ, Γ, δ, q0 , z, F ) Final States states Input Stack alphabet Transition Initial start Stack function state symbol alphabet
  • 63. Instantaneous Description ( q, u , s ) Current Current Remaining state stack input contents
  • 64. Example: Instantaneous Description (q1, bbb, aaa$) a Time 4: Input a a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 65. Example: Instantaneous Description (q2 , bb, aa$) a Time 5: Input a a a a b b b a $ Stack a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 66. We write: (q1, bbb, aaa$)  (q2 , bb, aa$) Time 4 Time 5
  • 67. A computation: (q0 , aaabbb,$)  (q1, aaabbb,$)  (q1, aabbb, a$)  (q1, abbb, aa$)  (q1, bbb, aaa$)  (q2 , bb, aa$)  (q2 , b, a$)  (q2 , ,$)  (q3 , ,$) a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 68. (q0 , aaabbb,$)  (q1, aaabbb,$)  (q1, aabbb, a$)  (q1, abbb, aa$)  (q1, bbb, aaa$)  (q2 , bb, aa$)  (q2 , b, a$)  (q2 , ,$)  (q3 , ,$) For convenience we write: (q0 , aaabbb ,$)  (q3 , ,$)
  • 69. Formal Definition Language of NPDA M : L( M ) {w : (q0 , w, s )  (q f , , s ' )} Initial state Final state
  • 70. Example: (q0 , aaabbb,$)  (q3 , ,$) aaabbb L(M ) NPDA M : a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 71. n n (q0 , a b ,$)  (q3 , ,$) n n a b L(M ) NPDA M : a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 72. Therefore: n n L( M ) {a b : n 0} NPDA M : a, a b, a q0 , q1 b, a q2 ,$ $ q 3
  • 74. Theorem: Context-Free Languages Languages Accepted by (Grammars) NPDAs
  • 75. Proof - Step 1: Context-Free Languages Languages Accepted by (Grammars) NPDAs Convert any context-free grammar G to a NPDA M with: L (G ) L( M )
  • 76. Proof - Step 2: Context-Free Languages Languages Accepted by (Grammars) NPDAs Convert any NPDA M to a context-free grammar G with: L (G ) L( M )
  • 78. An example grammar: S aSTb S b T Ta T What is the equivalent NPDA?
  • 79. Grammar: S aSTb S b NPDA: T Ta ,S aSTb T ,S b ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 80. The NPDA simulates leftmost derivations of the grammar L(Grammar) = L(NPDA)
  • 81. Grammar: S aSTb S b T Ta T A leftmost derivation: S aSTb abTb abTab abab
  • 82. NPDA execution: Time 0 Input a b a b ,S aSTb $ ,S b Stack ,T Ta a, a current ,T b, b state , S ,$ $ q0 q1 q2
  • 83. Time 1 Input a b a b S ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 84. Time 2 a S Input a b a b T b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 85. Time 3 a S Input a b a b T b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 86. Time 4 b Input a b a b T b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 87. Time 5 b Input a b a b T b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 88. Time 6 T Input a b a b a b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 89. Time 7 T Input a b a b a b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 90. Time 8 Input a b a b a b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 91. Time 9 Input a b a b b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b q0 , S ,$ $ q1 q2
  • 92. Time 10 Input a b a b ,S aSTb $ ,S b Stack ,T Ta a, a ,T b, b accept q0 , S ,$ $ q1 q2
  • 93. In general: Given any grammar G We can construct a NPDA M With L(G ) L( M )
  • 94. Constructing NPDA M from grammar G : For any production For any terminal A w a ,A w a, a q0 , S ,$ $ q1 q2
  • 95. Grammar G generates string w if and only if NPDA M accepts w L(G) L( M )
  • 96. Therefore: For any context-free language there is an NPDA that accepts the same language
  • 98. For any NPDA M we will construct a context-free grammar G with L( M ) L(G )
  • 99. Intuition: The grammar simulates the machine A derivation in Grammar G: S  abc ABC   abc Current configuration in NPDA M
  • 100. A derivation in Grammar G: terminals variables S  abc ABC   abc Input processed Stack contents in NPDA M
  • 101. Some Necessary Modifications First, we modify the NPDA: • It has a single final state q f • It empties the stack when it accepts the input Original NPDA Empty Stack qf
  • 102. Second, we modify the NPDA transitions: all transitions will have form a, B qj qi or qi a, B CD q j B, C , D : stack symbols
  • 103. Example of a NPDA in correct form: L( M ) {w : na nb } $ : initial stack symbol a, $ 0$ b, $ 1$ a, 0 00 b, 1 11 a, 1 b, 0 ,$ qf q0
  • 104. The Grammar Construction In grammar G : Stack symbol Variables: (qi Bq j ) states Terminals: Input symbols of NPDA
  • 105. For each transition a, B qj qi We add production (qi Bq j ) a
  • 106. For each transition qi a, B CD q j We add production (qi Bqk ) a(q j Cql )(ql Dqk ) For all states qk , ql
  • 107. Stack bottom symbol Start Variable: (qo $q f ) Start state final state
  • 108. Example: a, $ 0$ b, $ 1$ a, 0 00 b, 1 11 a, 1 b, 0 ,$ qf q0 Grammar production: (q01q0 ) a
  • 109. Example: a, $ 0$ b, $ 1$ a, 0 00 b, 1 11 a, 1 b, 0 ,$ qf q0 Grammar productions: (q0 $q0 ) b(q01q0 )(q0 $q0 ) | b(q01q f )(q f $q0 ) (q0 $q f ) b(q01q0 )(q0 $q f ) | b(q01q f )(q f $q f )
  • 110. Example: a, $ 0$ b, $ 1$ a, 0 00 b, 1 11 a, 1 b, 0 ,$ qf q0 Grammar production: (q0 $q f )
  • 111. Resulting Grammar: (q0 $q f ) : start variable (q0 $q0 ) b(q01q0 )(q0 $q0 ) | b(q01q f )(q f $q0 ) (q0 $q f ) b(q01q0 )(q0 $q f ) | b(q01q f )(q f $q f ) (q01q0 ) b(q01q0 )(q01q0 ) | b(q01q f )(q f 1q0 ) (q01q f ) b(q01q0 )(q01q f ) | b(q01q f )(q f 1q f ) (q0 $q0 ) a (q0 0q0 )(q0 $q0 ) | a (q0 0q f )(q f $q0 ) (q0 $q f ) a (q0 0q0 )(q0 $q f ) | a (q0 0q f )(q f $q f )
  • 112. (q0 0q0 ) a (q0 0q0 )(q0 0q0 ) | a (q0 0q f )(q f 0q0 ) (q0 0q f ) a (q0 0q0 )(q0 0q f ) | a (q0 0q f )(q f 0q f ) (q01q0 ) a (q0 0q0 ) b (q0 $q f )
  • 113. Derivation of string abba (q0 $q f ) a(q0 0q0 )(q0 $q f ) ab(q0 $q f ) abb(q01q0 )(q0 $q f ) abba(q0 $q f ) abba
  • 114. In general, in Grammar: (q0 $q f ) w if and only if w is accepted by the NPDA
  • 115. Explanation: By construction of Grammar: (qi Aq j ) w if and only if in the NPDA going from qi to q j the stack doesn’t change below A and A is removed from stack