 So, far we have discussed NFAs at an informal level. Let us define NFAs formally. An NFA when we use the formal root is a pipe tuple q sigma delta q 0 f as d f s r, where q is the finite set of states of the machine m. In other words, an NFA also has number of states and that number is finite. Sigma is the alphabet and which is a finite set of symbols. Delta is the transition function and it is here an NFA and a dFA would differ in general. q 0 is the initial state of the machine m and f is the set of final or setting states. We have two terminologies for the same thing. Either we can say final states or accepting states. Clearly this is a subset of q and now let me describe the transition function for NFAs. So, delta is a mapping from q cross sigma to power set of q. You recall what power set is. Power set of q is the set of all subsets of q. Example would be simple example. Let us see you have power set of the set 1 and 2. This is going to be this is a set. Remember power set is a set and its elements are the subsets of the set here. So, the empty set is a subset of this set 1, 2, the singleton 1, the singleton 2 and the entire set itself. So, in general if q had n elements, q had n states then power set of q will have 2 to the power n elements each of which is a subset of the set q. So, now this is saying the delta is a map which is which has two arguments that is the domain is the cross product of q cross q and sigma and its range is this power set. So, for example, delta of let us see q and a symbol a. So, the first argument of delta comes from the set capital q. The second argument comes from the set sigma. So, this is a state of NFA. This is a symbol of sigma and this will be some r which is a subset of q. So, let us see how it captures our informal understanding of NFAs. Let us take this very simple example and let me name these states as this is p, this is q, this is r and you can see what this NFA accepts the language the NFA accepts. It accepts the set of all strings in which the string 0 1 occurs as a substrate. We have seen similar examples before, but in this picture the transition diagram formally would write like this delta p of 0. Now, which are the states the machine can go to in this diagram you can see it can either go to p or it can go to q on 0. So, therefore, this is. So, the understanding of this is that if we have delta q and a is r which is a subset of q the machine from state q on symbol a can go to any one of these states of m which are in r. So, like here the machine r machine this particular machine from p to on 0 it can go to you see it can go to p on 0 it can also go to q on 0. So, the set of all states to which the machine can go to that is the value for this case. So, similarly what is delta p of 1 delta p of 1 you can see it from p on 1 it comes back to p, but we write like since they have to be a subset even for a singleton case this is the set of states it can go to it may be singleton. In fact, this set can also be empty as you can see from the next state q delta what is q of 0. See there is no transition defined from q on the symbol 0. So, which are the set of states the machine can go to from q on 0 none of the states. So, therefore, it is the empty set, but empty set remember is always a member of the power set. So, that is all right our definition of delta allows a empty set here r can be empty as in this case. And similarly you can write delta q of 1 delta q of 1 is only the set consisting of the symbol r. And to complete the r description for this case delta r of 0 as well as delta r of 1 both of this once the machine is in state r it does not matter whatever is the symbol it remains in the state r. So, this is right so just to emphasize once more in case of an NFA when we say the delta q a from state q on a is equal to r which is a subset of q what we mean is our understanding is that if r is the set of all states the machine can go to from the state q on symbol a right. We have defined formally what NFA is, but the next important thing we need to define is what the language accepted by an NFA is how do we define that formally. In case of NFA what did we do we extended this delta which was from q cross sigma to q cross sigma star exactly that is what we are also going to do, but keeping this definition in mind for delta in case of NFA. Now we would define l m the language accepted by an NFA m informally what did we see the language was informally we said l m was the set of all strings in sigma star such that x can take m from q 0 to 1 of its final states. Remember I emphasize that because it is a nondeterministic machine a string can give rise to many different computational paths and depending on the nondeterministic choices made by the machine in a particular computation it will be either in this state or in that state. However, this thing is well defined we look at all possible states the machine can go to after reading the string x and then if one of its states it can go to happens to be one or more happens to be a final state then we say the string x is accepted. So, this is of course we have stated it informally how do we formalize it as I said we will do it in terms of delta hat. So, let us remember what delta hat was delta hat is a function which again takes two arguments, but the second argument first argument is a state second argument is a string is a finite string over the alphabet sigma and its range is as before the power set of q. So, intent is intent is this we would like to define delta hat in this manner that suppose delta hat of p and x now x is a string remember which is in sigma star if this happens to be r which is of course a subset of q then we would like our definition should ensure definition of delta hat will ensure that this capital R is the set of all states thus r is the set of all states m can go to m can go to I will again emphasize the fact it is matter of possibility it can go here it can go there and which are all the states it can go to that is what is the subset of q r on string x from state starting from state p right this is what we would like to ensure and how do we do that well we will do it in this manner inductively we will define delta hat using the definition of delta and remember the style is same as the way we did it for DFA this is what so informally what we would like delta hat to satisfy. So, what is delta hat remember delta hat takes two arguments p and some string x now I need to define this function delta hat for all possible second argument argument here, but then that is an infinite set we cannot just write down as we could do it for delta. So, inductively we define inductively this in the induction is on x. So, what is the base case the base case is when the string is empty the null string. So, p and it is presented with the null string epsilon what happens what do you want to ensure that the set of all states the machine can go to from p on this string, but then there are no symbols it has seen. So, it will not make any transition it cannot make any transition it will remain in the state p. So, clearly this is going to be this. So, this is the base case and for the induction part what do I have to do we need to define delta hat p x a using the value for delta hat p x this is how all inductive definition goes that you supposing you have you already know how to do it for the string x then a new symbol comes a which is added to its right then for the string x a what will be the value of delta hat. So, let delta hat of p of x be r which is of course the subset of q remember that means this is the set of all states the machine can go to from inductively we assume that this assertion will hold here from the state p on the string x right. So, just before I write down formally what is happening. So, let us say this is part is x and this part is a right and after reading x the machine is in some states let us say it can be in one of these states. Now, what are the states the machine can be after reading a at this point. So, it on x it could have reached the state p 1 and now it care it is reading the symbol a. So, had it reached p 1 then it would have gone to one of these states p 1 a this is defined because delta we already know when you gave me the machine m delta p p 1 of a tells me which all states the machine can be on reading a from the state p 1. So, this is going to be a collection of states. So, these are the states the machine can be after reading a similarly from p 2 on x it could have gone to p 2 and now a came again there will be a bunch of states defined the machine which the machine can go to any one of which the machine can go to on symbol a and so on. So, therefore, it is not difficult to see the set of states the machine can be after reading this symbol a is the union of all these states. So, therefore, we would write like this way we will the delta hat of p of x a is the union of you are supposing r is a state r is an element which is of course, the state in capital R remember what was R capital R is the state of states the machine can be starting from the state p on reading x and now the next symbol we need to take care. So, delta r of a this is going to give me a subset of states. So, had the machine reached R then when it read a the machine would have gone to could have gone to any one of these states and the same is true for every other element of R. So, we take the union. So, you see this completely defines delta hat and in terms of delta hat we can now formally define the language accepted by the machine n. This was the informal definition and formally now that we have all this machinery we do not need to write English sentences or any natural language sentences to explain what the language accepted is l m is the set of all strings in sigma star such that delta hat of q 0 x what is this? This is the set of all states the machine can be starting from q 0 on this x on reading the string x and we what we want would say that this string x is in the language l m if any one of these states happens to be one of the final states. So, that is easy to write formally is this what we are saying is look at the collection of states the machine can be on reading x starting from the initial state intersect that set with the set of final states if that overall thing that you get is non-empty that means it can go to one of the final states then of course x is in the language and these are precisely the strings which are in the language because we are stating this is equal. So, that we this is the way to define the language accepted by the non-deterministic machine m. Now, this one very important question that we need to address and that is we had defined DFA's and we had then talked of the languages accepted the class of languages accepted by DFA's and now we have defined NFA's and now again we can talk of the class of languages defined by NFA's. So, I have two classes of languages one defined through DFA's the other defined through NFA's what is the relationship between these two classes. In particular it is easy to see that if language if a language is accepted by a DFA then it is also a language accepted by NFA. So, let me let me write it down let me state it if L is accepted by a DFA that means there is a DFA to accept L then L is accepted also by NFA now the reason for this is actually a trivial reason why because every DFA is also an NFA does it make sense this statement it does because what is an NFA NFA just states that from a state on a symbol there can be 0 1 or more transitions right whereas DFA's on from a state on a particular symbol there exactly one transition. So, therefore, the DFA case is a sub case DFA situation is subsumed by the situation of NFA. So, you can think of every DFA without any problem that it is an NFA it is that NFA is choosing to behave deterministically that is all. So, in terms of class of languages therefore, it is clear that the class of languages accepted by NFA's can be something bigger it cannot be less right. So, the question therefore, the which comes to our mind is that is there a language which can be accepted by an NFA, but not by any DFA and that the answer is no. So, in other words the these two classes the classes of the class of languages accepted by DFA on one hand the class of languages accepted by NFA's on the other hand these two classes are actually same. And therefore, since the class of languages accepted by DFA's we termed it as the regular languages class of regular languages NFA's also precisely accept regular language. So, this requires of course, proof to what we are claiming is that if you give me an NFA M for an NFA M the language accepted by M I will put it this way is regular. When I say L M is regular then what I mean is of course, by definition there is a DFA to accept this language L M the language accepted by the NFA M. And we prove this by actually constructing even any NFA M we will see how to construct it DFA from that M the definition of that M which accepts the same language. So, let me now give a proof sketch. So, the idea is to construct a DFA let me call it M dash such that the language accepted by this DFA is same as the language accepted by the NFA that you had given me. So, before we proceed further let us see what can be the strategy of the DFA M dash. So, we have seen several examples of the for the design of DFA's. And remember this is a string and our M dash has to decide by the time it reaches here the end of the string what the whether or not X would have been accepted by the NFA. So, as it is going on what all information it can keep through its finite head that will help in doing this task. So, in particular what should be the states of the DFA such that as the DFA moves from symbol to symbol when it reaches the end of the string it will know whether or not the string is in the language of NFA. Now let me tell you is an idea which you want for which is this it can we do this that of course we know that on a string X there are many possible computation paths. So, one would be that let the DFA keep track of all these paths but that idea would not work why because the total amount of information if you would like the total number of states that would be required will be infinite. Because as we have longer and longer strings will have it is like it you remember that computation tree is like a tree and it is it keeps growing it keeps growing and we cannot keep the entire tree for any for every input string in a state. In other words we just because a DFA can work only with finite number of states then you would say it is not really necessary to keep track of all these computation paths why not keep track of the this sequence that is if it had taken this path then it would have been in this state on X had it taken this path. So, this will be a sequence of states can we keep track of that in the finite states of DFA again the answer is no because this sequence also keeps growing arbitrarily large with larger and larger input all this is over came we do not really need the DFA does not really need to keep all the information which are which is there either in the entire computation tree or even in the frontier of the tree what it needs to keep track of. So, let me write it down the states of m dash on reading some string X will remember in its states the set of states NFA m could be could have been reading the same string X. Now, why should this idea work? So, you know this is the invariant the DFA will keep fixed that it will remember in one of its states precisely the set of states the NFA could have been on reading the string X. Now, you see this actually the total amount of information is finite why because NFA has the states the set of states of NFA is Q and Q is a finite set and whatever be the string that you give me the NFA will be on reading some string X it will be I know in one of the subsets of Q. So, how many different subsets can be there of a finite set like Q clearly that will also be finite. So, this information that the DFA needs to keep track of therefore, is a finite amount of information and that does the work. So, let me now give the a little more detail on this idea from the NFA m we would like to get to a DFA m dash which is equivalent in the sense m dash the DFA accepts the same language as that of the NFA. So, if our NFA was this Q sigma delta Q 0 f m dash let me write it as Q dash etcetera and now our strategy for this DFA m dash we said is going to be that m dash is going to keep track through its you know states the set of states m could be after reading part of the input some initial part of the input. So, then the simplest thing would be to define Q dash which is remember the set of states of DFA to be the power set of Q. So, for example, if the DFA is in this state where each P Q and R is a state of the NFA after reading. So, after reading x DFA m dash is in now this is a state of the DFA what we would like to ensure is if and only if m after reading x can be either in P or in Q or in R this is what we would like to ensure. So, for that we are saying the DFA set of states is the set of all subset of state space of the NFA alright this is not too difficult to see to implement that idea the only thing is now what we do about how do we define the transition function for the DFA. So, now delta dash is going to be now this is now is R and A what is R? R is a subset of Q which is and the Q is the NFA set of states, but this is now a state of the way we have defined it it is now a state of the DFA R and a symbol has come. So, according to this idea this should be equal to R dash and what is R dash where R dash is the union of I mean we have discussed this idea before, but it is essentially what we are saying is that suppose the NFA is one of these states R on reading something some part of some string and now A came right. So, from this from this small R it can go to these are the states the NFA can go to. So, I collect these states collect these all these states take their union now I get a subset of states of M and let me say that to be the let me define that to be the value for delta dash R A and if you see this actually implements this idea that we have stated here one more thing to notice that this is there is nothing non-deterministic about it. This is a state of the DFA this is another state of the DFA is not it because R dash is also a subset of Q. So, there is one state a symbol and we are giving a definite state of DFA that DFA can go. Now, I will not prove it formally, but if you see that this idea being implemented through this definition of delta dash then it is not going to be difficult to see that this M dash is going to accept the same language, but of course I need to tell you what these other two components of the DFA would be. So, that is easy. So, Q 0 dash the initial state of the DFA it is clearly should be the set of states the NFA could be initially and that is of course Q 0. Q 0 is the initial state of the NFA and this is this is the set of states the NFA could be initially and therefore, the corresponding subset is our state of the DFA and what should be F dash when should when will the DFA know the string would have been accepted by the NFA. If it finds that the NFA can be in one of the states on reading this string x and one of such one of these states is a final state of NFA then the string would have been accepted. So, it is clearly F dash we can define it this way that the set of all R now this is a state of the DFA this is of course the set of states of the NFA such that R intersection F F is the set of final states of the NFA is. So, we have completely described what M dash is we have described what Q dash is sigma of course, same as that of NFA sigma and then delta dash we have defined and F dash we have defined. So, the DFA is totally defined now let me give you an example of going from given an NFA to a DFA which accepts the same language. As an example consider this NFA and can see of course, what does this NFA do it accepts the set of all strings which each of which has as a substring somewhere in the string 0 1 and we would like to using this idea that we have developed. So, far going from NFA to DFA we would like to get a equivalent DFA. Now, it described of course, in detail what the set of states etcetera will be but given such a problem it is instead of trying to first see this NFA has three states and if you follow blindly that whatever you said we will start out with eight states 2 to the power 3 is 8, but you see some of these states could be inaccessible from the initial state that is there is no way you can reach one of these subsets. So, there is no point keeping those. So, we will start with the initial state of the DFA and see which all such states it can reach on 0 and on 1 basically the symbols of the alphabet. So, the initial state of the DFA is of course, the initial this set consisting of just the initial state of the NFA. So, which is P and here is a state and there the symbol can be either 0 or 1. So, from P on 0 you can let us see this probably once from P on 0 it can go to P as well as it can go to Q. So, therefore, we write this and you can see from P on 1 there it has no other choice it has to remain in P. So, now we have found another state which is reachable from initial state. So, let P take care of the state. So, the DFA is in this state P Q and let us say 0. So, what is the state the DFA would be? So, we see individually in fact that is what we liberated there from P on 0 it can go to the NFA can go to either P or Q and from Q on 0 which is the set states it can go to from Q on 0 no transition is defined. So, from Q on 0 the NFA goes to the empty state. So, take the union of all the states and that is P Q. So, and now let us consider from state P Q on 1 which all states it can go to from P on 1 it can go to of course P from Q on 1 this the NFA has no choice, but it will go to R. So, on 1 it goes to R. So, from P Q on 1 it goes to P R. So, you have found discovered one more state which is reachable from the initial state we need to take care of it. So, P R we will do the same thing. So, now it is P and R and 0 came on 0 from P you can be either in P or in Q from R when a 0 comes you will remain in R. So, the state DFA will be P Q R and what about 1. So, from P the NFA on 1 can go to on go to only P and on from R on 1 you will see can only go to R. So, it is P R P R is already taken care of, but again we have discovered a new state P Q R. So, P Q R from P on 0 it can go of course to either P or to Q Q on 0 it goes to empty R on 0 it goes to R. So, P Q R is on 0 it goes to P Q R and now consider the one case the symbol 1 from P on 1 it has no choice, but to come to P the NFA Q on 1 it can go to R R on 1 it can go to R take the union. So, it is P R. So, these are the now you see all the states these are the states which the machine can go to starting from I mean these are the reachable states P P Q etcetera and. So, therefore, we have completed the description of the DFA by the way this is called a transition diagram a transition table because here we are this side we are listing out the all the set of states of the DFA and here we have number of columns 1 column per symbol and basically such a thing tells that if the machine is in this state and a 0 came which is the state it can go to. Let us draw the corresponding transition diagram. So, that for the DFA M dash and you can see it has 4 states the initial state is this P and on 0 it goes to a state for this state and 1 it remains in the same state initial state from P Q on 0 it remains in the same state and on 1 it goes to a state P R from P R on 0 it goes to a state P Q R and on 1 what are the final states all those which have a final state as one of the members all those subsets. So, you can see the final state here is only R. So, R occurs here R occurs here. So, these are the two things oh by the way we should have taken care of for P R transitions I mean this state transition P Q R on 0 it remains here and P Q R from this state on 1 you come to. So, this is the DFA according to our idea now two points first of all if you I mentioned it once if you had done mechanically you would have written 8 states and then you would have found some of the states are not reachable. So, we just those states we do not have to really show. So, this is the DFA now does it make sense can we informally see that m and m dash accept the same language m of course, I know it is the it will accept the set of all strings with which has 0 1 somewhere and you see what this DFA does this DFA waits on 1 here and if a 0 comes it is here it means it has seen a 0. If it sees another 0 at this point it says I have seen a 0 which could be the first part of the interesting string 0 1 and once it finds a 1 then of course, it is either in this state or in this state I should have put down what that the transition diagram symbol was p r on 1 it remains here. So, you see once it has seen 0 and 1 the then in consecutive first once it escapes it remains here then it sees a 0 then oh by the way what happens on a 1 here. So, it has seen a 0 if a 1 then you have seen the interesting thing. So, now whatever happens whatever be the symbols which would come later on we should accept the string and therefore, it is either of these two states this is not the best DFA that you could design, but of course, this DFA accepts precisely the same language namely the set of all strings in which 0 1 occurs as a substitute. So, today in this lecture what we did was formally we defined what an NFA is and then we showed a very important result which is that given any NFA I can construct a DFA such that there is DFA accepts the same language as the NFA. So, therefore, the class of NFAs do not does not have any language which is not accepted by a DFA. In other words NFAs also accept precisely the class of regular language.