 So, far what are the concept that you have learned related to finite automata, you understood the limitations of finite automata that they cannot accept a context free languages, because particularly we have observed that a context free language you know a power n b power n the context free language that we have discussed that finite automata cannot accept that. Now, we will introduce a notion called pushdown automaton is this concept we will use to accept context free languages. So, for that purpose we will introduce this. So, in pushdown automaton because if you remember that we have finite control the point or pointing to states say some and a reading and writing head and a tape cells. So, we are giving the input on this say for example, a b a b b etcetera for example, now the transition the whatever the transition function defined for this finite control this takes care of the takes care of this input. So, corresponding to a whatever is there the next state it will the pointer will move to that and so on. So, this reading and writing that reading head will move towards right after a niche transition one by the end of the tape that means by the end of the input depending on the state if it is final state or non final state we say the string is accepted that is how we have considered finite automata. Now, with this mechanism we have limitation that we cannot accept the language of the form a power and b power and r some other context free languages which are not regular. We have observed that this kind of mechanism can accept regular languages further we have talked about some finite automata two way finite automata also we have talked about there the reading the reading head can move left and right and so the two way finite automata when we have discussed even by giving that we are unable to you know improve the improve the power of finite automata it accepts precisely regular languages only. Now, what do we do we give some more facility to the system this automata and define push down automata and there we consider context free languages. So, further purpose what do we give we give another tape let me write like this why do I write like this I will mention. So, divided into cells like this and here a reading and writing head sort of here we give and here the mechanism is the symbols that you write in this say naturally you may write symbols let me just distinguish here say capital A capital A capital B like that you keep writing in this and you will be have access to the top most symbol only. So, you will read the top most symbol or next to that next to that and so on. So, that means say for example, if you have written this A B B A I will be able to read A then B then A like that. So, that means this is essentially stack principle. So, this tape we will consider it as stack and the rest of the mechanism is similar that means you know in the read this is a reading head on the first tape this is the input tape you may call input tape and this I call push down stack this is a finite control a finite control. Now, the reading head reads one after another the symbol and according to the stack and the input and what are the transition defined here the next stage it goes to the next state and keep on reading the input and write something to the stack or read something to the from the stack and so on. So, the mechanism is essentially with respect to the with respect to this phenomena and accordingly we will be defining the corresponding the transition transitions in push down automaton. So, once again I reemphasize on this point here in addition to the finite automaton what we have learnt here we are giving one auxiliary memory called stack I call it a push down stack. So, in which you will be that will be used sort of rough work that means what are the symbols that you are reading that correspond to that you can put something in the memory and accordingly you can read and match the things and read the input. For example, if you take say a power 2 n b power n such that n greater than equal to 1 if this this kind of language you know this is clearly contest free, but not regular you can you can observe that this is not regular in which case what is the expectation in the tape for example, if you have say a a a a and 2 b's what do I do I keep reading the symbols and corresponding to say if I read 2 s then correspond to that I may put say for example, some capital B and I keep on moving to write and next 2 s I will put another b now what do I do when I encounter b I remove this I pop this b from this stack. So, in the beginning for correspond to this 2 s I put 1 I push 1 b and another 2 s I push another b in the stack and when I get b when I read b here I will pop this b I read another b I will pop this b and when the stack is empty by the time you finish input by the time this reading and writing that reading had reaches on the input tape here and if the point is pointing to some final state some final state then I say the string is accepted now you understand this stack concept how I will be using. So, similarly say for example, a power n b power n if you consider. So, number of s correspond to number of s you put some symbols inside that and you can match with that in the rest of the half similarly for palindromes or you know context free languages that you are familiar with for you will find this is a very convenient automaton a convenient device in to understand the context free languages I will give you better examples. Now, this is this mechanism let me define formally the notion called push down automaton a push down automaton I introduce that as a 6 triple push down automaton is a 6 triple I write it as q sigma gamma delta q naught f where q as earlier finite set of states set of states sigma is a finite alphabet input alphabet. Now, this new symbol gamma that is a finite set again finite set called the set of stack symbols. So, the whatever that I wanted to put in the stack I will choose from this set and of course, as earlier q naught the initial state f is a set of final states the set of final states. Now, what is delta this delta I give you little more general than what are the example I have discussed this is the transition relation I do not give it as a function non determinism I introduce here is the transition relation defined by defined by a finite subset finite subset of given a state an input string and a stack string given these three what is the next state and what is that you want to put in the stack. So, that is an element of q cross gamma star we take this is a finite subset of this particular set that means given a state input string and a stack string we give what the corresponding next state and this and I am giving you this as a relation is a transition relation. So, that means I am no considering non determinism. So, that means given a state and a input string and a stack string correspond to that I may assign finitely many possibilities as next state and stack strings that I would like to put inside the stack. So, let me just elaborate what I mean here if say p x alpha q beta if this is an element in delta that means if this is a transition defined in a pushdown automaton in a pushdown automaton then the meaning of this is on the tape let me assume somewhere here you have x before that say some x 1 and after this string say for example, x 2 you have and in the finite control this is pointing to the state p and the reading head is about to read x I am just marking it like this and in the stack something is there, but I am able to access alpha on the top of the stack something else may be there inside say for example, gamma if this is the situation the top of the stack is alpha that means alpha may be a combination of symbols a string essentially. If this is the transition corresponding to that the next picture is it will read x that means it will move to the end of this x that means you are about to read x to the rest of the string and you are removing alpha from the stack and you are putting in this place beta in the stack that means in the stack now you have this gamma beta that is a stack string and in the remaining input you have x 2 now the state changes to the state q. So, this is what is the meaning once again if a state p x alpha p x alpha corresponding to that if I are given q beta in the transition we complete x in the input from the current position and change to the state q corresponding to that you are accessing the top of the stack with as alpha is a string and you are removing that alpha is removed this need to be you know you pop this alpha and push this beta into the stack this is what is the meaning of that particular transition. Now, if you consider a transition in a transition relation say for example, p x alpha is going to q beta say for example, if alpha is epsilon that means what you are going to do when you are reading x in the input in the state p without removing anything from the stack you are pushing beta inside the stack that means this can be considered as this is pushing transition a pushing transition in case if beta is equal to epsilon if beta is equal to epsilon you are not if alpha is epsilon then you are pushing beta inside the stack if beta is equal to epsilon you are reading alpha from the stack and you are not pushing anything inside. So, this is a popping transition. So, now you notice that you notice that in a transition a transition can be a pushing transition a transition can be a popping transition or in a transition in a stack you can push you can pop something and push something inside the stack. So, you can have this kind of a mechanism now to talk about computation in a push down automaton suppose push down automaton it is given like this a snapshot or a configuration as earlier we have we need to define. So, what essentially the information that you require on the tape what is the information in a push down automaton whatever the string that you are going to read in the tape that you require and what is there in the stack that is what you would require. So, this information you would require and what you are going to read that is required and the current state. So, if you know these things depending on the transition that you are applying you may here in the tape this reading head is not going back and forth it is not going left and right only it goes to right if you read something after that you know what are the remaining information it is going to read and the stack information you would require and the current state that means merely you would require this information and therefore, this kind of picture can be seen as an element of q cross sigma star cross gamma star. So, that means a configuration is an element of a configuration is an element of this set that means you have to give me the current state and what is the string that I am going that it is left over on the input tape and what is the string inside the stack. If you know this this is a configuration correspond to given this snapshot or configuration we call. Now, for computation we would require to the computation relation that we define as earlier in case of finite automaton also. So, the binary relation on the set of configurations. So, that means we are defining on q cross sigma star cross gamma star is defined by this is a binary relation is defined by if you consider transitions transition between two configurations say for example, if say p x alpha goes to say q y beta there are two configurations if and only if there exist a transition that is in the state p for example, some z gamma is q gamma dash delta such that such that this x is equal to z y and what happens this the in the stack when you have alpha you are making that beta by removing gamma from the stack that means this is of the form say gamma some alpha dash and then beta will be this gamma dash gamma dash alpha dash. So, that means what you are doing here this configuration p x alpha gives the configuration q y beta that means you should have a transition transition in the transition relation say p z gamma goes to q gamma dash such that the x you are finishing the input z because z is shown here and in the stack you have alpha of the form say gamma alpha dash. So, that you remove gamma from the stack and you push gamma dash inside the stack that means the resultant string beta should be this gamma dash alpha dash because alpha dash is already there in the stack. So, that will be there in place of gamma you are pushing gamma dash. So, beta should be equal to gamma dash alpha dash if this happens we say this configuration is related to you. So, given two configurations there should exist a transition satisfying this condition then we say these two configurations are related as earlier now for computation consider the for computation in a push down automaton for computation in a push down automaton consider the reflexive transitive closure of this relation one step relation that is through this relation the reflexive transitive closure of that one step relation we talk about the computation. So, a computation in a computation in a push down automaton either form a finite sequence of configurations related by one step relation C naught, C 1, C 2 and so on C n for n greater than or equal to 0 this can be considered as a computation in a push down automaton. So, with respect to this binary relation what we have defined we talk about this computation. Now, what is initial configuration and when do you say a string is accepted by a push down automaton that notion I am going to define now. Because you have observed the mechanism in a very first place when I have explained a power n a power 2 n b power n this particular example when I have talked about this particular example you realize that by the time you finish the input you know stack we are making it empty and we are expecting final state has to be there. So, that means you should not have anything to read on the input tape and you are starting with the empty stack and you are making the stack also empty and when you are starting from the initial state with this input by the time you finish the input stack we are expecting it to be expecting it to be empty by and you should reach to final state. So, this is the expectation that I have I have made here this is the expectation we have in this example. So, let me consider let me consider initial configuration is of the form is the initial state q naught and whatever is the input that you are taking x epsilon for x belongs to sigma star this is given as this is the entire string on the input tape for x belongs to sigma star is the input on the tape and final configuration is of the form. I mean when you are accepting some final state you would require says for example, p and you should finish the tape input tape use there should not be anything and the stack should also reach to empty for some state p in F. So, for this is an accepting configuration in fact accepting configuration accepting configuration is of this form. Now, you can quickly define for x belongs to sigma star given an input string x is said to be accepted by a push down automaton push down automaton as I was writing earlier m q sigma gamma delta q naught F if the following happens. That means, in the initial state you give this as its input after finitely many steps you should reach to a final state by completing this input and a stack should remain I mean I should come back to empty stack for some p in F. Now, as usual as earlier the language accepted by push down automaton m is set of all x in sigma star x is accepted by m that means you should have this relation after finitely many steps you will get this for p in F for some p in F. So, the language accepted by a push down automaton as earlier the set of all those strings accepted by a push down automaton m. Now, let me consider some examples the natural candidate that as we have discussed if you consider l 1 equal to a power n b power n such that n greater than equal to 1 as I gave the hint earlier what do you do you push s inside correspond to that some symbols you put you remember those the number of s through certain symbols and then when you are getting b's you match with them and accept the string. So, let me write the transitions instead of giving the quadruple that sex tuple first I will just give you the transitions let me say q naught is the initial state anyway n greater than equal to 1 I had put. So, at least 1 a has to come. So, when a is coming I do not do anything with the stack and in the state say some capital A remembering a I will put inside the stack. So, this is one transition I define and this continues because I am the same state whenever I get a without taking anything out of the stack I simply put a inside the stack and when I get first b in the state q naught I expect a in the stack I expect a in the stack in which case I will match with them and change the state because at least 1 a and 1 b has to be there a a b has to be at least in the input. So, then I will change the state say for example to q 1 and a pop that a. So, this is one transition I define in another transition what do I do I continue this in q 1 when I get a and 1 more when I get b if I have capital A in the stack then I simply remove that also I keep doing this. So, I consider delta to be in a set of these 3 transitions and now I set m to b I have 2 states here q naught q 1 the sigma is a b and I have considered gamma I have only 1 symbol used capital A q sigma gamma delta as defined above and q naught the initial state and the singleton q 1 is the final state suppose if a. So, set m to be this and note that observe that the language accepted by m is l 1 let me just do some computation in this p d a in this pushdown automaton. So, this pushdown automaton for example, if you give a a b b in the initial state q naught this stack m t as we have defined in q naught if you read a without touching anything in the stack I am simply putting a inside the stack. So, that means what happens here q naught a b b capital A and in the next step I continue this same. So, I have b b a a I have put the second a here and then when I have q b in the input I expect a on the top of the stack in the state q naught to change to the state q 1. So, I have the remaining here is this look here if I have b in the input and a on the top of the stack I remove that capital A from the stack and read b and change to the state q 1. So, second transition I am using here ok. So, by this you get and in q 1 I continue to with this. So, q 1 I remove a a from the stack. So, clearly as we have mentioned q 1 is the final state and thus this string a a b b is in language accepted by m. Now, for example, if I consider a a a b b suppose if I consider you understand first I will put 3 a's inside the stack by the time I get this. So, this kind of configuration you get after 3 steps. Now, in q naught if I read b I can have this situation this will be in another step and after that you can of course pop this also you will get epsilon you have epsilon in the input and you have this much left over. So, q 1 epsilon. So, you do not have anything to read here and you have something left over in the stack. So, the stack you have put 3 a's in the stack and you have read you have removed corresponding to those 2 b's this and something is left over in the stack or for example, if you have less number of a's and more number of b's the input will be left over and when the input is left over I do not have any transition defined corresponding to b and if you have any mixer of a's and b's. Now, what will happen if you have any mixer of a's and b's corresponding to a you have removed b's and for example, if you get a then what will happen let us see that that part. See for example, now if you have a a b b after that say for example, a in q naught I can put these 2 a's in the stack. So, it will be a a b b corresponding to this and when a is left over I am in the state q 1 and the stack empty because as you have observed here a a b b now if I give a a b b after that this or may be after 1 b if I give a in the state q naught in the state q 1 if I have a then what is happening after getting as long as you are getting a's you are putting them inside them once you get b you are popping them and if there is a mismatch suppose assume you have match for a a b b and after that say for example, if you have a then what will happen q 1 a epsilon. Now, you see in q 1 we have not defined. So, the delta as a flexibility we have fixed with the push down automaton I abbreviated as PDA push down automaton if you know some symbol is here for which I have not defined I have this flexibility because we have considered transition relation is a non determinism that we have introduced. So, through this non determinism you know I I have the flexibility for not defining for certain symbols in the in a particular state. So, I have not defined. So, this so you will reach to this configuration and the computation you know ends or there and you can see that this final configuration this is the final configuration corresponding to the initial configuration with a with input a a b b a. So, this so with this it will stop you are you are in the final state, but some input is left over although the stack is empty the some input is left over. So, this is not an accepting configuration. So, if you get an accepting configuration then only we say string is accepted. So, thus with this simple explanation about the computation in this particular PDA I can I can say that the language accepted by this particular push down automaton is a power and b power n. Now, you can try other what I have mentioned earlier say for example, a power 2 n b power n that n greater than equal to 1. So, you can try and let me give this a power n b power n such that n greater than equal to 0 why I am putting 0 here I have worked with greater than equal to 1. So, I know that there has to be at least 1 b and accordingly I have defined the transition here. So, q 1 b a I have defined this now you have to carefully think that since it is 0 epsilon can be accepted and now when you have to change the state that you have to be careful with this. So, construct push down automaton for l 2 and l 3 push down automaton. So, this take this as an exercise I will discuss one more example for instance if you consider set of all x in a b star such that let me consider this say l 4 number of a sin x is same as number of b sin x you know this is a context free language you have constructed a context free grammar for this. So, now you first think about the logic when you are constructing a push down automaton. So, what is the pattern that you are expecting and how you what are the things that you have to remember you have to memorize or you have to put it in the memory. So, that first you decide then based on that you can construct the respective you know you can define the transitions in the respective p d a. So, one logic can be now when I get a I put say for example, a in the stack and I get now b I will match with this when I get b 1 more b I will put to b inside this. Now, the question is now the question is how do I know that you know here things are things got over for example, if this is the situation a b b suppose this is situation corresponding to a I had put inside a and I have match when I have got b I have removed this when I get b the first place I know I am putting a inside when I get b now how do I know that the stack became empty now I have to put say for example, some b inside this. So, that is that will be a question say for example, if you are getting in a pattern a power and b power and sort of pattern the earlier version will work. Now, it can be a mixer you can have first b if the first symbol as far as the first symbol concerned may be from the initial state you can go ahead with that and you know you can put that particular symbol. But in between when certain some after some match when the stack becomes empty how do I how do you know that a new symbol another type of symbol has come and I have to put inside the stack. So, for that purpose you can now introduce you know some special symbol in the beginning itself you put inside the stack and then whenever you are touching that symbol you know the stack became empty that means the symbols correspond to that you have already a match. Now, the new another symbol has come so now corresponding to that you want to put inside this. So, that is how you can define push down automaton in the for this particular purpose. So, let me use the technique and say in the beginning without reading any input and of course, stack is anyway empty in the beginning I simply put some special symbol let me call it as say z naught and push it in the stack. So, that means in the beginning in the stack I put this. Now, in q 1 if I get a and top of the stack is z naught then what do I do z naught I do not remove, but corresponding to that I put a inside and z naught is remain that remains there. So, this is the transition that I define. Now, if it is z naught is the top of the stack now I have already one a if I get one more a that means this is the situation I have then this a I do not remove. So, in same q 1 I will continue and I put one more a corresponding to this a I hope you have got the point. So, in the beginning we have put some special symbol and if I get first a s and the top of the stack is z naught then I push a s one after another and if I am getting so many s and I will keep pushing those s inside that. Now, in q 1 corresponding to this a if I get b now and if I access a on the top of the stack what do I do I will pop that. So, I am this is matching configuration corresponding to b this is a matching transition. So, I keep now the same thing will match as many b's as long as you are getting b's it will match now in q 1 for example, if you have got z naught that means s have got exhausted. So, now you put b inside that means without removing z naught. So, the similar to what we have done earlier for s. So, if I get some more b's that means this is the situation you keep putting b's inside that. So, this you consider and now corresponding to b's if you get a's in the input then you remove. So, match now you can you can understand if you have say for example, 3 s you have put inside the stack if you get 3 b's that you are matching. Now corresponding to if you have lesser number of b's and after that suppose if you get some more s you are in the same state q 1. So, say for example, if you have say 3 s 2 b's then a then what will happen this 3 s are put in the form a a a of course, z naught in the bottom and now when I get b I am removing this another b I am removing this. Now I am accessing on the top a in the top of the stack. So, when I get a now I will put. So, these 2 a's are removed now I put corresponding to this a another a in the stack after that whatever that you are getting accordingly that you will be managing. Now if there is a match that means number of a's is equal to number of b's throughout whatever the order that you put and match them finally, by the time you complete the input what is the expectation. So, input is empty and if there is a proper match then on the top of the stack you would have only the special symbol z naught whatever that we have we had put in the beginning. If you access that in q 1 you simply change the state and remove it. So, because non determinism is helpful in this regard. So, I will change to the state say q 2 without reading anything in the input. If I access z naught I simply remove it sorry in q 1 I will change to state q 2 and simply remove that z naught. So, this transition I put in this. Now with this transitions if you set the machine m. So, how many states I have 3 q naught q 1 q 2 and what is sigma here I have a's and b's only. So, little a little b and in case of gamma I have capital A capital B and z naught these 3 are there delta as defined and q naught is the initial state and the final state is singleton q 2. So, if you consider this x triple you can observe that as per the logic we have discussed you can observe that the language acceptable with this machine is the required one. That means number of a's is equal to x in a b star such that number of a's is equal to number of a's. Now, you see the push down automaton through this logic you can understand systematically how the pattern of the symbols are coming and accordingly how we are actually you know matching them. This for the same language I am sure that you would have felt little bit difficult when you are constructing contested grammar, but you know depending on the pattern that you are expecting in the input and appropriate string that you have to store if you can think of then you can easily construct a push down automaton and in that regard non determinism is specially useful and you will be I am sure that you will be able to construct a push down automaton for contested languages that you have learnt. Let me give some more examples that you can try as exercises I am sure that you have you would have constructed contested grammar for all these things, but let me just give you. So, let me consider this as alpha here in this lecture. So, W c W power r such that this W I am confining myself to two element alphabet nevertheless you can construct for arbitrary alphabet. Now, in this case you can quickly see that what are the symbols that you are getting you put inside the stack when you are getting c because that is not in a in a s and b is when you get this symbol c then you know there you have to change the state and match with the reversal it is reversal essentially. Now, if I ask you W W power r now you do not have any check here when you have to change for matching. So, that means here again non determinism is useful. So, think carefully and construct for this and in general because these are even palindromes if I can if I ask you set of all x in a b star such that x is equal to x power r that means all palindromes over the alphabet a b try for this languages and not only this any contested language that you have considered you have constructed contested grammar you try constructing p d a. So, consider any c f l that you would have constructed c f g for these languages and construct p d a pushdown automata. Now, here I give you a mechanism particularly to obtain the equivalence between this pushdown automata and contested grammars suppose if I obtain the equivalence that means you give me a contested grammar I construct a pushdown automata accepting the same language that is generated by given contested grammar and vice versa. If I can do that you can understand you can understand the equivalence between pushdown automata and contested grammars once again here I emphasize that the pushdown automata that I have introduced the version it is a non deterministic version. So, the statement here is the pushdown automata are equivalent to contested grammars what do I do since you know contested grammars earlier given a contested grammar contested grammar g given a contested grammar there exists a p d a let me write say m such that the language generated by g is equal to the language accepted by this m. So, this is one part this is particularly this direction similarly you give me a p d a I have to construct a contested grammar and I have to construct a contested grammar equivalent to that. So, in this lecture I simply construct I consider this direction that means you give me a c f j I construct a p d a and I conclude this lecture in the next lecture I consider the converse part. So, let it is very simple that is I can explain in this lecture let g n t p s be a c f d now set m to b only two states I consider see how simple is that sigma here of course, the in the terminal set there and now gamma I consider all the symbols that usually we write v gamma and I define delta and p the initial state and singleton q I take them as final states where v is all the symbols of all the symbols of that grammar n union t and delta is defined by delta consists of the following types of rules what are they first I do this in p without reading anything I push I change the state to q and push the start symbol into the stack. So, this is one type without reading anything in the input I do this simply I push s in the stack now what do I do in the state q if I have a non-terminal symbol on the top of the stack. So, this I push the respective so for all a goes to alpha in p I hope you understand this transition you take any production rule in the grammar a goes to alpha form if you are having a on the top of the stack without reading anything in the input you simply remove a and put the corresponding right hand side alpha what are the rule that you put inside the stack. So, correspond to each production rule you introduce one such and then what do I do for all terminal symbols when I am getting on the top of the stack terminal symbol I will I will define this you match them then I remove them for all a the terminal symbols. Suppose if you introduce these three type of rules then what are the push down automaton you construct you can understand that the language accepted the push down automaton is same as the language generated by the given grammar I just consider a small example a very simple example that if I if you consider the rules a goes to say a s b epsilon you know the language generated by this grammar that is a power n b power n such that n greater than equal to 0 you know this is the language generated by these two rules. So, what we have asked p epsilon q s this rule is anyway there one is there in place of two you have two rules that is q epsilon s is q a s b this you have to put inside this is one transition and q epsilon s this is non determinism you can see that q epsilon correspond to the rule s goes to epsilon this is the transition that I have to put inside that three correspond to three you have q a a is q epsilon this is one transition and another transition is q b b is q epsilon to remove that. Now, you see if you are having a a b b in the input in the state p of course the stack what do I do this p a a b b we do not we do not we simply put change to the state q simply put the start symbol s in that. Now, the way that you generate this particular string I generate in the stack and then match. So, I have the production rule a a b b so what do I do a s b this is the production rule that I use. So, you put corresponding to the transition to in type 2 then you match this q a b b s b now you are accessing s you have to match another a. So, generate that particular string so q a b b again here you insert a s b in the stack s is removed and a s b is inserted. So, this is the situation now in q now you match with this. So, b b s b b now you use this transition q epsilon s is q epsilon the second correspond to second production rule so s now will be popped. So, what do you get this q b b now b b now you match them q s now match this also q epsilon epsilon. So, whatever the string that you have in the input if it can be generated by the grammar then you generate them in the stack and match them. Of course, here I require a special type of derivation that I am observing of course, in this particular example you do not realize we will discuss this and see how this construction will work to show that correspond to a given context of grammar there exist this type of push down automaton. So, that means this indeed this construction indeed works that is what we have to observe that we will discuss in the next lecture.