 We will continue with our discussion on non-deterministic finite automata. There is one particular way of thinking of NFAs, non-deterministic finite automata, which is very useful. And that is this, that you may consider that NFAs have the ability of guessing and then checking. The work of an NFA, the way or what it is doing, that is the language it is accepting, it is useful to think in terms of this guess and check methodology. Let me first take a very simple problem and then through that problem I will try to explain this guess and check paradigm. Consider this language L, this is the set of all strings over 0, 1 such that x has 0, 1, 0 as substrate. You have seen this or similar problem before and you know how to do it in DFA. But let us see and convince ourselves that how this view of guess and check gives us a very simple NFA for this language. Now when you are thinking in terms of this guess and check, first of all we consider only the strings in the language. We are not bothered with the strings which are not in the language. So what is the property of all strings which are in the language? So such a string may be anything but there will be some somewhere this substring will occur and then there may be another part, non-empty part following this 0, 1, 0. So imagine an automaton which is looking at the input bit by bit then it guesses when the 0, this 0 of the interesting substring 0, 1, 0 comes in the input. So input let us take a particular example. Let us say we had 1, 1, 0, 1, then we had 0, 0, then we had 0, 1, 0 and 1, 0, 1, 1. This is the string. To make it a little more interesting this same problem, let me make the occurrence of 0, 1, 0 as the first occurrence of 0, 1, 0 here. So as you can see in this string 0, 1, 0 is occurring. So therefore this particular string is in the language. Now imagine an automaton m and this is the input which is given to this automaton. It sees this first 1, then it sees second 1, then it sees 0. Now as I said it has the ability to guess of these 0s which is the 0, which is of interest and that you can see it is in this 0. So in a way what this automaton does it will wait, it will keep on skipping these symbols one after another guess which is the 0 of the substring 0, 1, 0 in the language in the string. So that is this 0. Then it needs to verify that starting from here there is indeed a substring 0, 1, 0 starts. So that is the checking part. So how does an automaton check that 0, 1, 0 this just this substring 0, 1, 0. So it requires these states. This is in the state in it is in some state and then it sees this 0 it comes to this sees this 1, sees this 0. So the point I am trying to make is this that it is like the DFA. We said in this state it remembers that I have seen the first 0, here it remembers I have seen I have seen 0, 1 and then here it says 0, 1, 0. But the entire string is of course more than this. Now imagine or automaton looks like something like this that there is this transition which in because of which the machine can remain in this state either on input 0 or input 1. And non-determinism is coming here first of all that you see on 0 from this state either you can come to this state or one can goes to this state. This guess and check paradigm of understanding non-determinism is that the machine guesses which is the 0, where which is the first or which is the 0 at which the substring 0, 1, 0 in the string is starting. So let us say it makes this case here and now the automaton has the requirement of verifying that it is indeed the 0 of 0, 1, 0. So then it 0, then 1, then 0 it is in this state. And now after that once it has verified that 0, 1, 0 is there then of course in this part of the string comes or you know in this particular concrete example 1, 0, 1, 1 come this substring comes. So here it should remain irrespective of whatever is the input bit and if the machine can come by here then we should see the string is accepted. Now in particular notice the verification means that after 0 if another 0 came then the verification fails and in case of NFA what does it mean? This is here and now is 0 came what would happen? Then of course the no transition is defined. So that particular computation path is aborted. So but before proceeding let me again see in this very simple automaton example of an NFA how that guess and check paradigm how the guess and check methodology is being brought into play. Whatever be the input the machine is trying to guess in the initial state where is the first 0 of 0, 1, 0. Now it guesses and this is what you have to always assume that the machine will guess correctly. What happens if it does not guess correctly? I will come to that a little later. But let us say it guesses correctly but that is not enough it should now verify that it is indeed the first 0 of 0, 1, 0. So that it does by doing making this transitions and at this point machine has verified it had guessed and that it has that this is the right 0 and then when it comes here it has checked that its guess is correct and once it is convinced that it is that is the machine's guess check is correct the machine is convinced that his guess was correct then it has no hesitation in accepting the screen. So this is it this is L this is the language accepted by this machine which accepts this particular language L. Now sometimes this question ask what happens if the machine guesses wrongly. Now suppose the machine guessed that this is the 0 of 0, 1, 0. Then what would happen? Of course it will so on one it remains here on the second one it remains here now it guesses that this is the 0 and now it will try to verify the next 3 bits are 0, 1, 0. It sees 0 fine so it comes here it sees 1 it will come here. Now instead of a 0 which it is expecting it sees a 1 this 1 then computation about. So a wrong guess on the part of the NFA will mean a computation path either which is about it or which leads to non-accepted correct guess and if the string is in the language would mean that the input will be accepted and the machine will be in the accepting state or final state. So in the same way we can think of the other language in fact now you see it is so simple to say that is the example we had given earlier similar example that the language x has 0, 1, 0 as a as substring or 1, 1 as a substring. So I can just say or 1, 1 as a substring. Then there are two things the machine guesses given a string in the language. Firstly is the string in the language because 0, 1, 0 there or is it because the substring 1, 1 is there in the language. So if it so you remember that in that case the NFA would look like this. So now you see on both 0 and 1 from this state it has two transitions defined on both either 0 or 1. Now so let us say I have again this string this is of course in the language for both because 0, 1, 0 is there, 1, 1 is there. But let us say the machine guesses that first that I will accept the string because 1, 1 is there and then it skips the 1 it remains here it 1 it remains here it 0. Now it you know it has already guessed and now it verifies that 1, 1 is here. So on the first one of 1, 1 it will come here, second one it comes here. So therefore on these two ones convinces the machine that the substring 1, 1 indeed occurs in the language and therefore whatever comes later it will remain in this state. So this is the same thing so it is so easy you see that in thinking in terms of guess and check this method to repeat myself again that NFA as if to accept a string it is guessing where the property which that makes the string in the language where in the that property is to be found in the string and then it is verifying it is checking that indeed that property is being obeyed by the string and after that it remains it is in the final state. The other example of NFA that we had seen so let us say something similar we had seen something another language like this let me call it l 1 is x in 0, 1 star. Now let me see the why not let us say the 10th bit from the right end is 1 and then suppose an input is comes something like this will make the 10th bit 1 here. So I will first write the 10th bit 1, 0, 1, 1, 0, 1, 1 right and this suppose this is the end and then I have something supposing this is the input and this should be there in the language l 1 clearly because 1, 2, 3, 4, 5, 6, 7, 8, 9, 10th bit from the right end is 1. So suppose I want to design an NFA to accept this language you have already seen what NFA should be but I am thinking in now in terms of this guess and check. So what should be the guess? The guess should be that this is the 10th bit and verification should be consisting of two things that this 10th bit is 1 and after that there are exactly 9 bits no more no less. So what let us see the machine is initially in a state and on 0 and 1 it remains here and then when the 10th bit comes which is from the right end the 10th bit 10th bit from the right end that time now it should verify that this is indeed the 10th bit. So 1, 2, 3, 4, 5, 6, 7, 8 bit will lead me here 9th bit here 10th bit. So you see let me complete this do you care what is the 9th bit from the right end is you do not. So for verification should mean that 10th bit from the right end is 1 and after that there are exactly 9 more bits. So this either on 0 or 1 it will be here either on 0 or 1 0 or 1 0 or 1 0 or 1. So 1, 2, 3, 4, 5, 6, 7, 8 or 1 0 or 1 and 10th bit comes here takes me here and now how do I verify this is indeed the there are no more bits after this by having no transition. So if the by this you started from here and then let us see whatever there are 9 exactly 9 other bits one comes here and then if there more bits then what happens then the NFA computation is not defined therefore the next state is not defined the that string or the guess where the 10th bit is not 1 but let us say 12th bit from the right end is 1 then there will be 2 extra bits. So at you are here and you will find one more input bit has come and then the NFAs computation from here by defining no transition out of this state I am ensuring that if this is not the 10th bit from the right end the string is not going to lead me lead the NFA to the accepting state this final state. So point I am trying to make is there are 2 aspects guess and check you see there are many ones coming before this but the 10th bit from the right end was this right 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 the one came the machine guess correctly let us say this is not the one which is the 10th bit from the right end this is this one is also not this one is also not when this one so all up to this point the machine remained in this initial state and when the 10th bit I mean 10th bit from the right end came it guess correctly that is how you should imagine that it guess correctly and then now it is verifying it is indeed the 10th bit from this. So these are 2 examples that we had seen and I have tried to explain by means of this guess and check methodology and this is actually how you if you think that way think the design of an NFA becomes quite simple in many cases. Let us take a new example and that example will be as following our next example for NFA where I would like to begin explain exemplify this guess and check methodology is this suppose L is regular and now I am defining another language using this L as follows. We are saying that L 1 and without loss of generality let me say and L is a subset of 0 1 star to that means L consists of binary string and L 1 is all y in 0 1 star so again of course binary strings such that there is an x in L you see that is how I am using this L to define this new language L 1 there is an x in L from which or let us say which is flip or 1 bit of which is a binary string. Which is flip there is an x in L 1 bit of which is flip to obtain this y let us see clearly. We are saying L 1 is that language where this is these language consists of binary string and if you take a string in L 1 you will find an x in L and such that if you flip 1 particular bit of this x that bit may be anywhere in x and exactly 1 bit so let me let me emphasize this 1 by saying that this is exactly 1 bit of which is flip to obtain this particular string y so let me let me make this clear supposing my language was like this 0 1 1 0 1 so what is L 1 now is it take this string 0 1 you flip this bit you will get the string 1 1 now this 1 1 should be in L 1 because I have obtained 1 1 by flipping this bit of 0 so similarly I could have flipped this bit also so I then I would have get gotten this string 0 0 right so from 0 1 by flipping 1 bit I would get this 2 string 1 0 1 if I flip the first bit I will get 0 0 1 if I get flip the second bit I will get 1 1 1 if I flip the last bit I will get 1 0 0 so therefore my language L 1 is 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 and 1 now if I ask you to tell me why this bit is in this language L 1 you will see if you flip I have asked you why this particular string is language L 1 you will see that is because you flip this bit the second bit you will get 1 0 1 and that is in the language L right it is clear what the language L 1 is and the problem is to show show that L 1 is regular now before we try to design the language L 1 you will see so and see basically what we are trying to do will be that will design an NFA for L 1 but I have not yet shown you that this will make L 1 to be regular but let me just say show that L 1 is accepted by an NFA at this point this should be the more appropriate question and later on we will see the set of languages accepted by NFAs precisely the set of languages accepted by DFA so once we know that then I could have invoked that to say to claim once I show that L 1 is accepted by an NFA that L 1 is also regular but at this point it is restrict ourselves to only prove that there is an NFA to accept L 1. So let me now remove this and once when you are confronted with this problem of course one thing you know one thing is that since L is regular there is a DFA M so I can write like this as L is regular there is a DFA M to accept L 1. Of course that comes by definition of regularity and now I want to decide an NFA so by NFA let us say so let me first of all say this M as the states Q and then of course its alphabet is 0 1 binary alphabet we are using and transition to L 1. Function is defined by delta Q 0 and F this is some N now I would like to define to define M 1 and NFA such that language accepted by M 1 is precisely the language L 1 which we have defined here. So let us think in terms of this guess and check business remember for designing that NFA all I am interested in is that if you give me any string of the language my NFA will be able to accept it and will think of the work of the NFA in terms of the guess and check. So you have given me a Y and this Y happens to be in L 1 this is a bit string now what should the NFA do guess and check so NFA has to guess which bit is the bit which was flipped from a string of L in order to get this particular string Y. So let us say it is just think conceptually first that this is the bit that was flipped the bit that is somewhere that is here. But that is not enough it is not enough saying that I have guessed therefore this but you need to verify that this fact what is that you need to verify there is an X in L who one bit flip exactly one bit flip gives me the string that you have given me as input suppose you just think in this way that suppose there was a 0 here and by flipping I will get a 1 here. So everything else remains same what can you say about this string new string. So this bit was 0 here you have flipped this one rest of the bits are exactly identical and now if this string is in the language L 1 then clearly this string should be in the this is the X which is in L how do you verify that this string is in language L the DFA obviously should accept it. So now we are getting a glimmer of what is to be done. So imagine a machine NFA which on successive bits behaves as if it is the DFA M on one exactly one particular input bit it flips the bit. So it was 0 here and it assumes as if the bit is 1 and then sees what the DFA would have done on this particular bit that is the state now the machine goes to machine in the sense the DFA goes to this M goes to our NFA is keeping track of that and then rest of the bits it behaves exactly like the machine M the DFA. So let me repeat to verify that Y is in L 1 what our NFA will do in the beginning it will keep track of the states the machine the DFA is in on successive bits then on one particular bit if it is 0 it will make the transition as if or it will it will it will see which is the state the DFA would go to had this bit been instead of 0 1 and then from that state onwards it just keeps track of what the DFA would do. Till the rest of the input and then at this point the NFA check will be over if the DFA is found to be in an accepting state. Let me describe this pictorial imagine this is the DFA this is the DFA M and this is the initial state and there may be a number of final states let us just see for the sake of this example illustration rather that there are two final states imagine we are thinking of a machine NFA which is consisting of two copies of this. So this is the two copies of course look like that excuse me and then imagine this is one of the states there are many other states but let me focus on one particular state and for the sake of illustration let us say on this is a DFA remember 1 0 it goes here and 1 on 1 it comes here of course in the copy also say let me even give names for this P Q R. So as I saying that this is one particular state and on 0 this DFA M would go to Q on 1 it goes to R on the copy also of course the similar same thing will happen identical thing this state P this state Q this state R right 0 and then 1 and now imagine my NFA is making use of these two copies to initially remember up to this point it is behaving exactly like the DFA. So it imagine at that time this is making use of this copy and suppose it sees now a 0 and the machine has given guessed the NFA has guessed that this is the 0 which was flipped right to up from a string which was in L. So actually DFA would have seen 1 so suppose so therefore the NFA on 0 also it can of course go here it also on 0 it can of course on 0 can go to this state R the state R. Now just look at this what I am trying to say is this that normally when the DFA is working of course on from the state P on 0 you go to Q on P if you on 0 if you go to R that means what another way of looking at it is that as if the bit 0 was flipped and because of that when we flip 0 you would see 1 and the DFA therefore should go to the state R. So similarly from this state P on 1 the normally on 1 it would go to R but if that particular bit 1 is the bit which was flipped then it on 1 it should go to as if it had seen a 0 the DFA would have seen a 0 and it would have gone to this Q instead. Then after that the machine remains here. So now of course this is let me complete at least the picture wise pictorially what the NFA will be this is the initial state initial state is the initial state of the first copy from every state of the first copy these kinds of these new transitions are defined. So either on 0 it can make a transition to its copy that will be the normal DFA working or what can be done is to imagine that 0 is flipped and then what happens then it would go to the copy here which the DFA would have gone from here on seeing a 1. So that is why you are coming here and then these are no longer these are which were the final states here are not final states of the NFA but these two the final states of the DFA in the second copy are the final states of the NFA. Now through this picture let me explain that guess and check the way it is happening the NFA starts its operation on this copy of DFA by the way why it is NFA because you see on every state on every symbol in this copy in this part of the state space of NFA by the way the NFA states will be the this set of these states plus the set of these states. So either on 0 it can come here or on 0 it can come here and so then they have full it is an NFA because and not a DFA because on 0 it has two transitions from here and similarly from 1 two transitions from here and that is the case for every state I have just shown you the case with one particular state but that is precisely what you will do for a write it more formally here later on. Let us understand the guess and check idea from here the machine NFA is working on the string it sees successive inputs it remains in this copy till it finds the bit which it guesses had it been flipped then the along with the flip bit the string would have been accepted by DFA. So it considers the effect of that flip comes to this copy and then again behaves like the DFA. So it is doing two things that you see to go from here to one of the final states on an input what is going to happen you may be here somewhere and then at some point you have to come to this part because the fine accepting states final states of the entire machine is so this m 1 is this entire thing right the initial state is this and the final states accepting states of these two. So you can see we are verifying that exactly one flip of the input if it is whether or not it would take the DFA from the initial state to one of the final it is one of its final states how am I making sure that exactly one flip you see you can the NFA has the ability to consider flipping any bit but after flipping the effect of flipping though the work happens in this copy and then no more flip can be entertain so exactly one one and exactly one flip is required to go from here to here alright. So let me let me more formally define this NFA m 1. So as I said that this is the m is this so what should be the states of m 1 so let me say m 1 is q 1, 0 1, delta 1, q 0 1 and f 1 right. So I would think of the way I have done it in this picture that q 1 is there are two things whether I what we need to remember is whether I mean this copy of DFA or in this copy of DFA and so therefore let me see. So q 1 you can see it has exactly twice the number of states of q because for every state q you can see the number of I have two states q 0 and q 1 and I would like to imagine q 0 are these states the first copy and q 1 are this. So how do I describe delta 1 so delta 1 now first let me describe suppose remember a transition function takes two things an input symbol and the state of the machine here suppose the state is q 0 and I have a 0. Now the machine can remain in this copy so that would mean essentially saying that it can remain in state delta of q and then this 0 has come remember this q is the state of the DFA 0 is the input symbol which is come so from q the DFA would go to delta q 0 and it is still in the first copy so that to indicate that I mean it is 0 and this is one state but it can go to another state also and which is that it considers this 0 as 1 and that would mean delta of q 1 and now it should be in this copy that I indicate by 1. So once more states of machine m 1 which is an NFA they keep track of two things what is the state of DFA and whether it is using the first copy of DFA or the second copy of DFA. So here it is that is why states are q 0 means it is in the top copy q 1 means it is the q of the second copy this is the set of states for q for m 1 the NFA and so let me state very clearly and this is NFA and of course the transition function tells me that it is an NFA because from this state on this symbol there are two ways of going. Similarly what is delta 1 of q 1 sorry q 0 on 1 right it is now you can see if it if the NFA chooses to remain in the first copy then it is just this that this is delta from on q it has seen a 1 so it is 1 please do not get confused between this delta 1 and this delta now you are talking of the DFA q on 1 q on 1 this is the state and it has it is going to this state that means it is assuming that it is still in the first copy. So therefore it is 0 but it can also take this 1 to be the flip bit right in that case the state would be delta of q 1 has come flip it which is 0 q 0 right but now it is in the second copy so right clearly and this is q 1 right now the role of the picture is over since we are thinking in terms of doing it explicitly writing out explicitly so what can you say about delta 1 of q 1 0 now it is q 1 means we are talking of the second copy so it should be delta of q 0. And it will remain in the second copy right it is an NFA we will write like this as a subset of states remember that this whole thing is a state of the NFA and similarly delta 1 of q 1 1 is delta of from q it has seen 1 to q 1 0. And since it is in the second copy it will remain in the second copy and other two things so for the NFA I have said q 1 what is 0 1 what is delta 1 q 0 will be what now you can see q 0 is going to be the state it is the q 0 of the DFA and the first copy so this state is to be taken as this way that it is q 0 0 this is the state and f 1 which are the states all those states which are ending with second component is 1 and the state component of the DFA is the final state right. But the main point of this example was that guess and check method. This NFA has the ability I mean it is using its ability of guessing which is the bit which is flipped see every time it will it can guess oh this is in that picture if you went back to the picture which I had just rubbed out that for every input bit it is seeing it has the choice of guessing whether it is the bit which it should consider flip and then see what the DFA will do. And then it is verifying also that one bit is flipped exactly one bit is flipped and on this flip one bit new string will take the machine the DFA from an initial state to one of from the initial state to one of its final state. So, this is a slightly more involved use of our understanding for our understanding of guess and check methodology of describing NFS and their work and this is one way at a very useful way whenever non-determinism is there will encounter non-determinism in other kinds of automata be Turing machine or be pushed or automata wherever non-determinism is there it is often in fact most often it is very useful to think in terms of this guess and check method.