meljun cortes automata lecture pushdown automata 1

Upload: meljun-cortes-mbampa

Post on 07-Aug-2018

236 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    1/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 1 of 16

    TOPIC TITLE: Pushdown Automata

    Specific Objectives:

     At the end of the topic session, the students are expected to:

    Cognit ive:

    1. Discuss the relationship between nondeterministic finiteautomata and pushdown automata.

    2. Explain the operation of a pushdown automaton.3. Give the formal definition of a pushdown automaton.4. Design a pushdown automaton for a given language.

    Affective:

    1. Listen to others with respect.2. Participate in class discussions actively.

    MATERIALS/EQUIPMENT:

    o  topic slideso  OHP

    TOPIC PREPARATION:

    o  Have the students review related topics that were discussed inprevious courses.

    o  Prepare the slides to be presented in class.o  It is imperative for the instructor to incorporate various kinds of

    teaching strategies while discussing the suggested topics. o  Prepare additional examples on the topic to be presented. 

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    2/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 2 of 16

    Pushdown AutomataPage 1 of 20

    Pushdown Automata

    Introduction

    It was seen in the previous lesson that a context-free grammar can generate orderive the strings of the context-free language it represents by using the differentrules of the grammar.

    In the same manner, a regular expression can be used to generate the strings ofthe regular language it represents.

    Therefore, regular expressions and context-free grammars are calledspeci f icat ion mechanisms   for regular languages and context-free languages,respectively.

     A finite automaton is a mathematical model that recognizes regular languages. It isused to determine whether a string belongs to a certain language or not. It istherefore a recognizing mechanism  for regular languages.

    This session will now focus on the machine that can recognize context-freelanguages. Such a machine is represented by a mathematical model called apushdown automaton  (PDA).

    Pushdown AutomataPage 2 of 20

     A PDA is similar to an NFA in the sense that it has the same components, whichare a set of states, an input alphabet, a transition function, a start state, and a setof final states. The only difference is the addition of a sixth component which is astack (also called a pushdown stack ).

    The figure below is a schematic representation of an NFA.

    NFA

    0 1 1 0

    Input String  

    So, the NFA needs only the input string to perform its calculations.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    3/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 3 of 16

    Pushdown AutomataPage 3 of 20

    The figure below is a schematic representation of a PDA.

    PDA

    a

    b

    a

    b

    Stack

    0 1 1 0

    Input String

     

    From the given figure, a PDA needs the input string and the data stored in thestack to perform its calculations.

    Take note that the stack here is the same as the stack discussed in DataStructures. It follows a last-in, first-out (LIFO) structure. It has a limitation that alldata are stored or removed to/from the stack only at one end (called the top of thestack ).

    Pushdown AutomataPage 4 of 20

     As in Data Structures, the operations that can be done on the stack are push ,which adds a symbol to the top of the stack, and pop , which removes a symbolfrom the top of the stack.

    State transitions on an NFA depend on the current state the NFA is in and theincoming input symbol. State transitions in a PDA depend on the current state thePDA is in, the incoming input symbol, and the symbol at the top of the stack.

    One of the limitations of an NFA is its limited memory. An NFA can only rememberthings that are represented by its states. And since it has a finite number of states,it can only remember so much. For example, consider the language L1 = {0

    n1

    n n ≥

    0}. This language is composed of all strings where the total number of consecutive0s is equal to the total number of consecutive 1s following it.

    If an NFA is to be constructed to recognize language L1, the NFA should be able tocount and remember the number of consecutive 0s it has received at any point intime. And then it should be able to count and remember the number ofconsecutive 1s it will be receiving after the 0s. Finally, it will have to determine ifthe number of consecutive 0s is equal to the number of consecutive 1s. But thatwould require an infinite number of states since the number of possible 0s and 1sare infinite. Therefore, no NFA that can recognize this language can be

    constructed. Language L1 is therefore not regular.

    The stack of the PDA can give it additional memory beyond what is available in anNFA (as represented by the states). There can potentially be an infinite number ofitems that can be stored inside the stack. This makes PDAs more powerful thanNFAs because they can recognize certain non-regular languages.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    4/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 4 of 16

    Pushdown AutomataPage 5 of 20

     As a case in point, consider again the non-regular language L1 = {0n1

    n n ≥ 0}.  As

    mentioned earlier, there is no NFA that can recognize this language. However, aPDA can be constructed to recognize it.

    Here is an informal description of how the PDA tries to determine if an input string

    belongs to language L1:

    1. As in an NFA, the PDA reads each symbol of the input string.

    2. For each input symbol 0 that it receives, the PDA pushes it onto thestack. So, if the PDA receives n consecutive 0s, there will be n 0s in thestack. The stack therefore keeps track of the number of consecutive 0sthat the PDA receives.

    3. Now, for each input symbol 1 that it receives, the PDA pops or removes a0 from the stack. If there is a 0 that can be popped from the stack forevery 1 the PDA receives, then each 1 has a 0 as its “partner.” So, if thenumber of consecutive 0s is equal to the number of consecutive 1sfollowing the 0s, the stack will be empty by the time the input string ends.

    4. If there is no more input symbol and the stack is empty, the input string isaccepted. The PDA will reject the input string if:

    a. There are still 0s left in the stack and there are no more inputsymbols arriving. This means that there are more 0s than 1s.

    b. The stack is already empty and there are still input symbolsarriving. This means that there are more 1s than 0s.

    c. If an input symbol 0 suddenly arrives while the PDA is receivingthe block of consecutive 1s (out of sequence).

    Pushdown Automata

    Page 6 of 20

    Formal Definition of Pushdown Automata

    The formal definition of a PDA is similar to that of an NFA. It simply lists down orenumerates the different components comprising it.

     As discussed earlier, an NFA has five components, which are the set of states, aninput alphabet, a transition function, a start state, and a set of final states. A PDAwill have all five components plus a 6

    th component which is the stack alphabet.

    So, the formal definition of a pushdown automaton is:

     A pushdown automaton is a 6-tuple (Q, , , , q0, F ), where Q, , , and F  are all finite sets, and

    1. Q is the set of states,

    2. is the input alphabet,

    3. is the stack alphabet,

    4. is the transition function,

    5. q0  Q and is the start state, and

    6. F   Q and is the set of final states.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    5/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 5 of 16

    Pushdown AutomataPage 7 of 20

    The stack alphabet is the set of symbols that can be pushed onto the stack. Itmay or may not be the same as the input string alphabet . In the discussionearlier on how a PDA can recognize the language   L1 = {0

    n1

    n  n ≥  0}, a 0 was

    pushed onto the stack every time an input symbol 0 arrives. Technically, thesymbol that is pushed onto the stack could be any symbol, such as  x , wherein  x  represents an input symbol 0. What is important in this example is not the actualsymbol that was pushed, but the total number of symbols that was pushed onto thestack (which represents the total number of consecutive 0s in the input string).

    Transitions in a PDA

     Another difference between an NFA and a PDA is when and how state transitionsare made. Recall that in an NFA, state transitions are represented by

    (qi , 0) = q j  

    This equation indicates that if the NFA is currently at state qi  and the input is 0, theNFA goes to state q j . State transitions are therefore determined by the current

    state and the incoming input symbol.

    Pushdown AutomataPage 8 of 20

    In a PDA, state transitions are represented by

    (qi , 0, a) = (q j , b)

    This equation indicates that if the current state is state qi  and the input symbol is 0,and the symbol at the top of the stack is a, the PDA goes to state q j  and pushesthe symbol b onto the stack.

    State transitions are thus determined by the current state, the input symbol, andthe symbol at the top of the stack. Moreover, moving from one state to anothermay be done together with an action that pushes a certain symbol onto the stack.

    Pushdown AutomataPage 9 of 20

    PDA State Diagrams

     As expected, PDA state diagrams are similar to NFA state diagrams. The onlydifference is the label of the transition edges. In NFAs, transition edges are labeledusing an input symbol, indicating what input symbol is needed to cause a transition

    from one state to another.

    For example:

    q  j x

    q  i 

     

    In the given state diagram, if the NFA is at state qi  and an input symbol  x  arrives,the NFA will go from state qi  to state q j .

    In PDAs, labels are of the form a, b → c . For example:

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    6/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 6 of 16

    The label a, b → c  means that if the input symbol is a and the symbol read from thetop of the stack is b, then the PDA goes to state q j  and it pushes the symbol c  ontothe stack. So the new top of the stack is the symbol c .

    Pushdown AutomataPage 10 of 20

    Take note that before the symbol at the top of the stack can be read by the PDA, ithas to perform a pop operation first. So the label a, b → c   implies that thesymbol b was popped off the stack when it is read. In other words, when a symbolat the top of the stack is read, it also means that it has been removed from thestack.

    Furthermore, any of the symbols a, b, and c   in the given label can also be theempty string . The different possibilities are then

    1. If a = , the PDA makes the transition without any input symbol arriving.

    2. If b = , the PDA makes the transition without reading any symbol from thestack.

    3. If c  = , the PDA does not push any symbol onto the stack whenperforming the state transition.

    Pushdown AutomataPage 11 of 20

    So far, there has been no mention of how a PDA can determine if a stack is empty.In order for the PDA to do so, a special symbol will be designated as the stackempty symbol. So, if the PDA sees this special symbol at the top of the stack, thenthe stack is considered empty.

    The symbol that will be used here as the empty stack symbol will be the dollar sign($ ). This symbol will be pushed onto the stack every time a computation is startedto ensure that it is the first symbol to enter the stack and will therefore always be atthe bottom of the stack.

    So, any time the PDA sees that the symbol at the top of the stack is $ , then thestack is empty. Technically, the stack is not really empty since it contains the $  symbol. However, as far as the computation is concerned, the stack is effectivelyempty.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    7/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 7 of 16

    Pushdown AutomataPage 12 of 20

    To help understand how a PDA operates, here are some possible state transitionsindicating the contents of the stack before and after the state transition is made.

    Sample 1

    In this example, assume that the PDA is currently at state qi  and the symbol at thetop of the stack is a. The transition label is 0, a → b. This means that the PDAgoes to state q j  if the input is 0 and the top of the stack symbol is a. And once itgoes to q j , it pushes the symbol b onto the stack.

     Assume now that a 0 arrives. The PDA will then pop (remove) the symbol at thetop of the stack to determine its value. Since the symbol popped is a, the PDA willnow go to state q j  and at the same time push b onto the stack. The new top of thestack symbol after the transition will now be b.

     As mentioned earlier, the $  symbol should always be the symbol at the bottom ofthe stack since it is the designated empty stack symbol.

    Sample 2

    In this example, assume that the PDA is currently at state qi  and the symbol at thetop of the stack is a. The transition label is 0, a → a. This means that the PDAgoes to state q j  if the input is 0 and the top of the stack symbol is a. And once it

    goes to q j , it pushes the symbol a onto the stack.

     Assume now that a 0 arrives. The PDA will then pop (remove) the symbol at top ofthe stack to determine its value. Since the symbol popped is a, the PDA will nowgo to state q j  and at the same time push another a onto the stack. So the top ofthe stack symbol will still be a.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    8/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 8 of 16

    Pushdown AutomataPage 13 of 20

    Sample 3

    In this example, assume that the PDA is currently at state qi  and the symbol at thetop of the stack is a. The transition label is 0, → b. This means that the PDAgoes to state q j  based on the input symbol only (which is 0). It does not read thetop of the stack symbol. And once it goes to q j , it pushes the symbol b onto thestack.

     Assume now that a 0 arrives. The PDA goes to state q j  without popping anythingfrom the stack. And at the same time, the PDA will push b onto the stack. Thenew top of the stack symbol after the transition will now be b, and the total numberof items in the stack increases by one item.

    Sample 4

    In this example, assume that the PDA is currently at state qi  and the symbol at thetop of the stack is a. The transition label is 0, a → . This means that the PDAgoes to state q j  if the input is 0 and the top of the stack symbol is a. But once itgoes to q j , it does not push anything onto the stack.

     Assume now that a 0 arrives. The PDA will then pop (remove) the symbol at top ofthe stack to determine its value. Since the symbol popped is a, the PDA will nowgo to state q j  but without pushing anything onto the stack. The new top of the stacksymbol after the transition will now be  x   (which is the symbol below a before the

    transition occurred). The total number of items in the stack decreases by one item.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    9/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 9 of 16

    Pushdown AutomataPage 14 of 20

    Sample 5

    In this example, assume that the PDA is currently at state qi  and the symbol at thetop of the stack is a. The transition label is 0, →  . This means that the PDAgoes to state q j  based on the input symbol only (which is 0). It does not read thetop of the stack symbol. And once it goes to q j , it does not push anything onto thestack.

     Assume now that a 0 arrives. The PDA goes to state q j  without popping anythingfrom the stack. It also does not push anything onto the stack. So, in this example,the stack contents do not change.

    It was mentioned earlier that a PDA can make a state transition without any inputsymbol (an -transition). This implies that PDAs are nondeterministic. This alsomeans that a PDA may go to several states for a single input symbol.

    Pushdown AutomataPage 15 of 20

    Going back to the case study presented earlier, the state diagram of the PDA P 1 that can recognize the non-regular language L1 = {0

    n1

    n n ≥ 0} is given below:

    The following describes how PDA P 1 operates:

    1. Before any computation begins, the PDA will be at the start state q0.

    2. There is a transition edge from state q0 to state q1 with the label , → $ .This means that even without any input symbol arriving and withoutlooking at the symbol at the top of the stack, the PDA may opt to go tostate q1 and at the same time pushing the $  symbol onto the stack. Thisaction simply pushes the $  symbol onto the stack since it should alwaysbe the symbol at the bottom of the stack (the first symbol to enter thestack).

    3. At state q1, there are two transition edges. One transition edge has thelabel 0, →  0 and goes back to state q1. This means that when a 0arrives at the input (no matter what the symbol is at the top of the stack),the PDA will stay at state q1  and at the same time push a 0 onto the

    stack. Recall that the PDA that recognizes language L1  should simply

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    10/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 10 of 16

    push a 0 onto the stack for every 0 it receives as input. This transitionedge accomplishes this task. While 0s keep on arriving at the input, thePDA will simply push 0s onto the stack (and stay at state q1).

    The other transition edge has a label 1, 0 →  which leads to state q2.

    This means that if an input symbol 1 arrives and the symbol at the top ofthe stack is 0, the PDA goes to q2  without pushing anything onto thestack. The reason for this is that when the PDA receives an input 1 afterreceiving consecutive 0s, the PDA is alerted that it is possible that theblock of consecutive 1s will start arriving. The PDA will then go tostate q2 where it will start partnering each 1 it will be receiving with the 0sit has received by popping a 0 off the stack for each 1 it receives. If thePDA receives a 1 and the symbol at top of the stack is not a 0, thismeans that the PDA received a 1 without receiving any 0s yet. The PDAthen cannot go anywhere and the computation dies (the string isrejected).

    4. At state q2, there are also two transition edges. One transition edge hasthe label 1, 0 →  and goes back to state q2. This is the point where the

    1s arrive. For every 1 that arrives, the PDA pops a 0 from the stack andgoes back to state q2. Take note that nothing is pushed onto the stack atthis point of the computation. If a 0 suddenly arrives at the input, it is anout-of-sequence 0 (a 0 arriving after a 1). The PDA then cannot goanywhere and the computation dies (the string is rejected). If a 1 arrivesand the symbol at the top of the stack is not 0, this means that the stackran out of 0s. The 1 that just arrived has no partner, meaning there aremore 1s than 0s. Once again, the PDA cannot go anywhere and thecomputation dies (the string is rejected).

    The other transition edge has the label , $ →  which leads to state q3 (afinal state). This means that if no input symbol arrives and the symbol atthe top of the stack is $ (the stack is empty), then this indicates that every0 that was in the stack was partnered with each 1 that arrived at the input.

    The PDA then goes to state q3  which is a final state and the string isaccepted. If a 1 arrives and the symbol at the top of the stack is $, thismeans that the input that arrived is an excess 1 (no 0 can be partneredwith it). The PDA cannot go anywhere and the computation dies (thestring is rejected). If a 0 arrives at this point of the computation, it is anout-of-sequence 0 (a 0 arriving after the 1s). The PDA cannot goanywhere and the computation dies (the string is rejected).

    5. At state q3, there are no transition edges. A 0 that arrives at this point isan out-of-sequence 0 while a 1 that arrives at this point is an excess 1.So any input that arrives causes the computation to die and the string isrejected.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    11/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 11 of 16

    Pushdown AutomataPage 16 of 20

    The formal definition of PDA P 1 is as follows:

    P 1 = (Q, , , , q0, F ) where:

    1. Q = {q0, q1, q2, q3}

    2. = {0, 1}

    3. = {0, $}

    4. q0 is the start state

    5. F  = {q0, q3}

    Pushdown AutomataPage 17 of 20

    6. The transition function is given by:

    From the transition table:

    (q0, , ) = (q1, $ )(q1, 0, ) = (q1, 0 )(q1, 1, 0) = (q2, )(q2, 1, 0) = (q2, )(q2, , $ ) = (q3, )

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    12/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 12 of 16

    Pushdown AutomataPage 18 of 20

    Example 2

    Consider the non-regular language L2 = {ww R  

    w   {0, 1}*}. Recall that the stringw 

    R  means the reverse (written backwards) of string w . This language is composed

    of strings whose second half is equal to the reverse of the first half. Examples of

    strings from this language are 110011, 1101001011, and 000110011000.

    The PDA that recognizes language L2 should perform the following:

    1. The PDA reads each symbol of the input string.

    2. For each input symbol that it receives, the PDA pushes it onto the stack.

    3. When the middle of the string is reached, the PDA starts popping off thestack for each input symbol read, trying to determine if what is read at theinput and what is popped off the stack is the same symbol. Remember,the stack follows the LIFO structure so popping the string inside the stackcauses the symbols to come out in the reverse order.

    4. If each symbol read from the input and popped out from the stack isalways the same and the stack empties at the same time as input isfinished, the string is accepted. Otherwise, it is rejected.

    But the problem is, how will the PDA know if it has reached the middle of the string.This is where the nondeterministic nature of the PDA will come into the picture.Each time an input symbol is received, the PDA can make a nondeterministicguess that it has reached the middle of the string. In other words, upon receivingan input symbol, another copy of the PDA will be created. The new copy willassume that the middle has been reached and will start comparing the inputsymbol with the symbol at the top of the stack. The original copy will assume thatthe middle has not been reached and will continue pushing the input symbols ontothe stack. Eventually, one copy of the PDA will reach the final state if the inputstring belongs to language L2.

    The state diagram of PDA P 2  that can recognize the non-regular language L2 = {ww 

    R  w   {0, 1}*} is given below:

    The following describes how PDA P 2 operates:

    1. Before any computation begins, the PDA will be at the start state q0.

    2. There is a transition edge from state q0 to state q1 with the label , → $ .This is when P 2  pushes the $  symbol onto the stack since it shouldalways be the symbol at the bottom of the stack (the first symbol to enterthe stack).

    3. At state q1, there are two transition edges. One transition edge has thelabels 0, → 0 and 1, → 1 and goes back to state q1. This is the part

    where P 2 continuously pushes the incoming input symbols onto the stack.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    13/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 13 of 16

    In other words, this is where P 2 assumes that it has not yet reached themiddle of the string.

    The other transition edge has the label , →  which leads to state q2.This transition edge gives P 2 the option of automatically going to state q2 

    without waiting for an input symbol, without checking the symbol at thetop of the stack, and without pushing anything onto the stack. This is thepart where the P 2 assumes that it has reached the middle of the string. Itthen goes to state q3 where it determines whether the second half of thestring is equal to the reverse of the first half.

     At this point, there will always be two copies of the PDA for each inputsymbol that arrives. One copy assumes that the middle of the string hasnot been reached and will continue pushing the incoming input symbolsonto the stack. The second copy assumes that the middle had beenreached and will go to state q2 where the actual checking will be done.

    4. At state q2, there are also two transition edges. One transition edge hasthe labels 0, 0 →  and 1, 1 →  and goes back to state q2. As

    mentioned earlier, this is the point where P 2 starts popping off the symbolat the top of the stack and comparing it with the incoming input symbol.This continues while there is always a match (P 2  keeps going back tostate q2). If the symbol at the top of the stack and the incoming symbolare not equal, the PDA cannot go anywhere and the computation dies(the string is rejected).

    The other transition edge has the label , $ →  which leads to state q3 (afinal state). This means that if no input symbol arrives and the symbol atthe top of the stack is $ (the stack is empty), then this indicates that thesecond half of the string matches the reverse of the first half. The PDAthen goes to state q3 which is a final state and the string is accepted.

    5. At state q3, there are no transition edges. This is where the second half

    of the string is equal to the reverse of the first half. A 0 or a 1 that arrivesat this point in time destroys the required pattern so the computationstops and the string is therefore rejected.

    Pushdown AutomataPage 19 of 20

    Example 3

    Consider the non-regular language L3 = {ai b

     j c 

    k i ,  j , k   0 and i  = j   or i  = k }. This

    language is composed of strings that starts with consecutive a’s followed byconsecutive b’s which are then followed by consecutive c ’s where the number ofa’s is equal to the number of b’s or the number of a’s is equal to the number of c ’s. 

    In processing an input string, the PDA for this language starts by pushing all the a’sit receives onto the stack. Once it has received all the a’s and these are all storedin the stack, the PDA may start matching them with either the incoming b’s or c ’s.

    Once it has been determined that the number of a’s is equal to the number of b’s orthe number of c’s, then the string is accepted. 

    The problem now is how will the PDA know whether to match the a’s with the b’s orwith the c ’s. In other words, there is no way to know  in advance if the a’s will beequal to the b’s or to the c ’s. 

    Like in the second example above, the nondeterministic nature of PDAs will play avital role in solving this problem.

     After receiving all the a’s and storing them in the stack, the PDA will make anondeterministic guess whether the a’s will be matched with the b’s or the c ’s. ThePDA will do this by creating another copy of itself. The first copy will continue theprocessing by partnering each input symbol b  it receives with the each a  in thestack. If it turns out that the number of a’s is equal to the number of b’s, the string

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    14/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 14 of 16

    is accepted.

    The other copy will simply ignore the incoming b’s. Once the c ’s start coming, thiscopy of the PDA will start partnering each input symbol c  it receives with the each a in the stack. If it turns out that the number of a’s is equal to the number of c ’s, the

    string is accepted.

    In other words, one copy will try to match the a’s with the b’s while the other copytries to match the a’s with the c ’s. If either copy ends in a final state, the string isaccepted.

    The state diagram of PDA P 2  that can recognize the non-regular language L3 = {a

    i b j c 

    k i , j , k   0 and i  = j  or i  = k } is given below:

    Pushdown AutomataPage 20 of 20

    PDA Design Exercises:

    Construct a PDA that can recognize the language  L4 = {w w   is composed of anequal number of 0s and 1s}.

    The language L4  is the set of all strings that have an equal number of 0s and 1s(not necessarily consecutive 0s and 1s as in language L1). The approach here isto keep track of whether there are more 0s than 1s or whether there are more 1sthan 0s. To do this, the PDA should push any excess symbols (whether 0s or 1s)onto the stack. Hence, if the stack is empty, then there are an equal number of 0sand 1s.

    The PDA should have states for the following situations:

    1. There are an equal number of 0s and 1s. Call this state q1 and this will bea final state.

    2. There are more 0s than 1s. Call this state q2.3. There are more 1s than 0s. Call this state q3.

     As usual, there should be a start state q0 with a transition edge to q1 with the label, → $ . This pushes the $  symbol onto the stack before any computation could

    begin.

    While the PDA is in state q1, a 0 that arrives causes the PDA to push the 0 onto thestack (it’s an excess 0) and the PDA goes to state q2. A 1 that arrives causes thePDA to push the 1 onto the stack (it’s an excess 1) and the PDA goes to state q3.

    While the PDA is in state q2, any 0 that will arrive will be pushed onto the stack.The number of 0s in the stack indicates the number of excess 0s. For any inputsymbol 1 that arrives, the PDA will pop a 0 from the stack signifying that there isnow one less excess 0. If the PDA sees that the stack is empty (the $  symbol waspopped out), then there are no more excess 0s. The PDA then goes to state q0.

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    15/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 15 of 16

    But because of the , → $  transition edge, the PDA goes to q1 and restores the$  symbol (since it was popped out earlier).

    While the PDA is in state q3, any 1 that will arrive will be pushed onto the stack.The number of 1s in the stack indicates the number of excess 1s. For any input

    symbol 0 that arrives, the PDA will pop a 1 from the stack signifying that there isnow one less excess 1. If the PDA sees that the stack is empty (the $  symbol waspopped out), then there are no more excess 1s. The PDA then goes to state q1 and pushes the $  symbol onto the stack to restore it.

    The state diagram for the PDA that can recognize the language  L4 = {w w   iscomposed of an equal number of 0s and 1s} is given below:

    Construct a PDA that can recognize the language L5 = {02n

    1n 

    n ≥ 1}. 

    This language is composed of all strings wherein the total number of consecutive0s is equal to the total number of consecutive 1s following it.

    The language L5 is composed of all strings wherein the total number of consecutive

    0s is two times the total number of consecutive 1s following it. The approach hereis similar to the PDA P 1 presented earlier.

    1. The PDA reads each symbol of the input string.

    2. For each input symbol 0 that it receives, the PDA pushes it onto thestack. The stack therefore keeps track of the number of consecutive 0sthat the PDA receives.

    3. Now for each input symbol 1 that it receives, the PDA pops or removestwo 0s from the stack. If there are two 0s that can be popped from thestack for every 1 the PDA receives, then each 1 has two 0s as its“partner.” Hence, if the number of consecutive 0s is two times thenumber of consecutive 1s following the 0s, the stack will be empty by thetime the input string ends.

    4. If there is no more input symbol and the stack is empty, the input string isaccepted.

    The state diagram for the PDA that can recognize the language  L5 = {02n

    1n 

    n ≥ 1}is given as follows:

  • 8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 1

    16/16

     

    Theory of Computation (With Automata Theory)

    Pushdown Automata *Property o f STIPage 16 of 16

    [Pushdown Automata, Pages 1 –20 of 20]