 We have already seen that regular expressions represent the class of regular languages and the regular grammars as language genetic devices are intended to generate regular languages. Now we will see an important concept or tool, final automata. Final automata are important tools to understand the regular languages better. We will introduce the notion of final automata and so that they model the class of regular languages. In fact, we observed that final automata, regular grammars and regular expressions all are equivalent and final automata can be used to model many different physical systems. For example, digital systems can be modeled or any software engineering problem can be modeled using final automata. Just consider the regular language, the set of all strings over a, b having odd numbers of ways. Already we have seen that the grammar for this language is e goes to b, e small b e or e goes to a o, o goes to small b o and or o goes to small a e or o goes to epsilon. This grammar we have seen that can generate the given regular language. We have also already given a diagram of representation of the same grammar which contains three nodes e labeled as e o and dollar and there are some transitions defined according to the rule of the grammar. Now consider this diagram representation of the grammar and let us traverse the diagram via a sequence of a's and b's starting at the node e. If we do that, we see that at the given point of time, if we are at the node e then so far we have encountered even number of a's. Similarly, if we are at the node o then so far we have traversed through odd numbers of a's via generation from e to o level a. Of course, if we are at the node dollar it has a same effect as that of node o that means regarding the numbers of a's and counter so far rather once we reach to dollar then we will have we will not have any further move that means we have to stay there only. Now in the diagram that models in this diagram that models a system which understands a language nodes holds some information about the traversal as its node is holding some information it can be considered as a state of the system and hence a state can be considered as a memory creating unit. As we are interested in the languages having finite representation we restrict ourselves to those systems with finite numbers of states only that means the idea or concept that we have used in the diagram to represent a grammar. We are now going to introduce the concept of finite automata the notion of finite automata will be explained with the help of the concept that we have already introduced in using the diagram model. So, in such system we have transitions between the states on symbols of the alphabet thus we may call them as a finite state transition system because we have finite numbers of states and there will be some transitions on symbols of the alphabet from one state to another. As the transitions are predefined in a finite state in a finite state transition system it automatically changes states based on the symbols given as input thus a finite state transition system can also be called a finite state automaton or simply a finite automaton that means it is a device that works automatically and the plural form of automaton is automata. We have a look at a special kind of finite automata which is deterministic finite automata or simply a DFA. DFA is a type of finite automaton in which the transitions are deterministic in the sense that there will be exactly one transition from a state out of an input symbol. Formally we define a DFA as a quintuple containing five components q sigma delta q naught and f where q is a finite state called the state of states sigma is a finite state called the input alphabet q naught which belongs to the state of states is called the initial state or start state of the system and capital F is of state of the state of states is called the state of final state or the state of accept states and delta is a transition function which is defined from q cross sigma to q and is called the transition function or the next state function. Now note that for every state and input symbol the transition function delta assigns a unique next state. So, in that sense this automaton is deterministic just consider an example say the state of states q is contains the elements p q r the input alphabet contains only two elements symbols say a b the state of states is simply contains one state the state of final states contains only one state from q that is the state r and delta the transition function is defined or expressed by the following transition table. So, delta on p when the DFA is in state p and input symbol is a it will transit to state q if it is in state p and input symbol is b then it will transit to state p. Similarly, on state q on input symbol a it will transit to r and so on that is how we define a transition function clearly this is a DFA because we have defined all these elements q sigma delta p and f. We normally use the small letters p q r with or without subscript to denote states of a DFA. Now instead of explicitly giving all the components of the quintuple of a DFA for example, the state of states q input alphabet sigma transition table delta say the final states f and so on. We will simply point out the initial state and the final states of the DFA in the table of transition function which is called a transition table. For instance we may use an arrow to point the initial state and we encircle all the final states. Thus we can have an alternative representation of a DFA as all the components of the DFA now can be interpreted from this representation. For example, the DFA that we have just given can be denoted with a following transition table. So, in this case p is a star state. So, we have written the same transition table. So, p is pointed by an arrow meaning that p is a star state and the state r is encircled indicating that r is a r is the final state or only final state. So, in this case all the elements of the quintuple can be found or can be determined from this transition table because the state of states contains only 3 states p q and r. Input interval for width contains 2 symbols a and b. Then the transition table is defined like this the star state is p and the set of final states contains only one state it is r. Therefore, we need not give separately or explicitly all the elements of the quintuple instead we can describe the DFA by using this kind of transition table. So, this is another representation for giving a DFA normally we associate some graphical representation to understand abstract components better. So, in this context also we have a diagram of representation for a DFA say containing these 5 tuples which is called state transition diagram or simply a transition diagram. So, to give the diagram representation every state in q will be dependent by a node if delta p a equal to q as different transition table then there is an arc from the node p to the node q leveled on a. If there are multiple arcs from level a 1 a 2 up to a k minus 1 a k one state to another state then we simply put only one arc leveled a 1 comma a 2 up to a k from one state to the other state. And there is an arrow with no source to the initial state q naught and all the final states are indicated by double circle. For example, consider transition diagram for the DFA that we have already given by the transition table which is as per rule that we have described. So, right now we can draw the transition diagram as below. So, the table is given by this delta on a and b we have 3 states p q and r p is the star state r is the final state p on a goes to q p this goes to r p and this is r r. Now according the rule that we have defined for constructing transition diagram for a given DFA we create nodes for the states. So, it is the star state we indicated by a circle from an arrow from nowhere to this state. We create a state for node for other states p q and since r is a final state we indicate by double circle. And as per the transition from p on a goes to q is indicated by giving an arrow level a from p to q. Similarly, p on b goes to p is indicated by giving a self loop to p on symbol b. Then q on a goes to r an arrow level a goes to r q on b goes to p q on b goes to p then r on a and b remains at state r. So, on a and b it remains at state r itself. So, instead of giving 2 loops over here we are using a single loop and we have labeled by a comma b. So, this is the given transition diagram for the given example. So, we have got this particular transition diagram for the example already destroyed. The two transitions from the state r on symbols a and b are represent by a single arc from r to r level a b as indicated earlier. Now the transition function delta assigns a state for each state and an input symbol. Naturally this can be extended to all strings in sigma star assigning a state for each state and an input string. That means we can have an extension function from q cross sigma star to sigma which is defined as below for all q belonging to q set of states and string any string x belonging to sigma star and some symbol belonging to sigma delta hat is an extension function and q on empty string will give q. That means without taking any input it will remain on the same state and delta hat q comma x a where x is a string and a is a symbol together x is a string can be defined as recursively delta of delta hat q x which will give us a state comma a. That means we first apply this x n transition function on x starting at q and then apply this delta original transition function on single input a. Now just consider this extended the same example that they have already given and let us consider how to compute this x n transition function on a string say a b a. So in this case this string a b can be considered x according to definition and we apply delta hat on the string a b. So p comma a b delta hat p comma a b and then we apply delta on whatever state we arrive at here comma a. That means we use the second rule. Next we can apply it recursively inside the same rule can we apply over here that means delta hat p a comma b and then apply delta on apply the same function delta on a. Similarly we can continue further since here after this a we have only epsilon we apply it delta hat on p epsilon and then we apply the first rule since delta hat p epsilon is p itself because it will remain the same state. Therefore the next step we will get from this we will get only p itself and hence it will be delta p a that is why we are getting here delta p a. Now since delta p a is already defined in our transition function p a gives you q. So the next step will be delta p a is q. So q b now apply delta q b delta q b is again p and it will be delta of p a. So delta of p a is now q. So it will give now q. Therefore applying delta hat extension function on a b a starting with this p we get the state q. So this is how we compute extension function. Now we are in a position to define the notion of acceptance of a string and consequently acceptance of a language by a DFA. A string x belonging to sigma star is said to be accepted by DFA a if delta hat q 0 x belongs to f. That means if we process the string x starting in the initial state q 0 then if we arrive at the final state then we say that the string x is accepted by the DFA a. Now the set of all such strings except by the DFA a is said to be the language accepted by a and it is denoted by L of a. That means L of a is a set of all strings x belonging to sigma star such that delta hat q 0 x belongs to f. Now consider the DFA which contains these five states with the following the traditions as given in the figure. Now if we look carefully the only way to reach from the initial state q 0 to the final states the final state q 2 is through the string a b because they follow the path from q 0 to q 1 and q 1 to q 2 that is the only path through which we can arrive at q 2 starting at q 0. And again from q 0 we can arrive at the other final states q 3 following the path q 0 to q 1 q 1 to q 2 then q 2 to q 3. So, where the level the path is a a b b. That means we can reach the final states either q 2 or q 3 by following the strings following the paths with levels as a strings a b and a b b. That means the language accepted by the DFA is only two strings a b and a b b no other strings will be accepted by the DFA. So, in this case it is a DFA because you have defined the traditions on every state on every input symbol. You see that here t is a trap state because there is no path out of t from t once we have arrived at t then there is no way to go out of t to any other state. So, you have to remain in a same state. Consider the example that we have already described. So, let us see the language of this DFA. If we observe carefully you find that if there is a a in the input is a and a a in the input then DFA leads us from the initial state p to the final state r. That means the string a a is accepted by the DFA. So, once we are in the state r then we continue to stay on r whatever the input we consider on any subsequent input we have to be in the same state r. So, if the input does not contain a a then we will be suffering between the state p and the state q because whatever we take it is a string of b is will be here in the same state p. If we take a single a we will come to a q and from q if we do not take an a any b will lead us again to p. So, we have to suffer between p and q. Therefore, the language except by the DFA is a set of all strings a b having a a a sub string which can be written as set of all strings out of form x a a y such that x y belongs to sigma star. So, that means any string which has a a a sub string will be accepted by the DFA and no other string will be accepted by the DFA. Let us consider some more examples just consider the example for which we have given a regular grammar. That means the set of all strings over a b set of all strings over a b having odd numbers of h. We have already given a regular grammar for this one and we have given a regular grammar for this one. Now, since it contains the set of all strings over a b containing odd numbers of h we need to remember the numbers of h encounters so far and the states has to remember that information. Note that if this is a star state say q whatever so if we first take b as an input you see that we have to be in a same state because it need not remember the numbers of bits you need to ignore the numbers of bits. So, therefore, on b it will remain on the same state. So, as soon as it reads the first a it has to go to some other state next state to remember that it has read odd numbers of h. So, on a it will enter under a state. So, call it as q odd and call this state as q even because the first set will in fact remember the odd numbers of h encounters so far and the second state will remember that it has encountered so far odd numbers of h and the first that first that will remember even numbers of h. So, in the second state that means q odd if it gets in b again so it need not do anything it will remain the same state because it need not to remember numbers of bits, but once it gets an input as a. So, it has to transit from this state to the under state which is nothing but the first state because in such a case the numbers of h will be even. Therefore, it is very clear that if the d f a remains in the state q even the numbers of h in the strings read so far or process so far will be even and the numbers of h process so far will be odd if it is in the state q odd. Therefore, if we make q odd as a final state then this d f a will accept all strings having odd numbers of h. So, therefore, these are required d f a for a given language over a b set of all strings over a b having odd numbers of h. Similarly, instead of making this state as final state if we make this state as the final state first one then clearly this d f a will accept all those strings having even numbers of h. Just remember that the diagram preparation that have given for the language the set of all strings having odd numbers of h was like this is e o. So, this was the diagram preparation for the given language which we constructed for from the given regular language. Now, we see that these two are identical if we assume that this is a final state. So, in this case of course, the differ by this state and this transition epsilon and we do not allow normally in d f a this kind of transition on input epsilon, but later on we will see that we if we allow this kind of transition we get some other toss of final automata which we discussed later. Let us consider another example of a d f a. Say this d f a has q 0 as a first state on input b suppose it remains a same state on a it transits to q 1 then on a it remains in the same state on b it goes to the state q 2 and say q 2 is a final state on b it remains a same state and on a q 2 goes to state q 3 which is again suppose a final state. So, on q 3 on a it remains in q 3 itself and on b it goes to say q 4 and q 4 on a b it remains in a same state. Now, let us see the language accepted by the d f a we will see the behavior of this d f a by observing what its states represents or what information its state retains. It is clear that if the input contains only b is that the d f a remains in the initial state q 0 on b q 0 on b will remain in the same state. On the other hand if the input has an a then the d f a goes to state q 1 from q 0 it goes to state q 1 on input a and on any subsequent is it will remain in the same state q 1. Thus the role of state q 1 is to remember that or understand that the input has at least one a. So, that is what information will be remembered by the state q 1 further the d f a goes from state q 1 to q 2 by a b. So, on input b the d f a will go from q 1 to q 2 and remains in the state q 2 on any further input which is b. Thus q 2 recognizes that the input has an occurrence of a b because once it arrives at q 2 the input must have an occurrence of a b and since on any input in any further b remain in the same state q 2. Now, here q 2 you observe that q 2 is a final state therefore, the d f a accepts all those things which have one occurrence of a b. If it has one occurrence of a b in the string then they are stringly accepted by this d f a. Subsequently we see that if we have a number of a's q 2 on a it will go to q 3 and q 3 on any further a's will remain on the same state q 3 itself and q 3 is also a final state. So, all such strings will be accepted if it has one a b subsequently terminated by any number of b's or any number of a's but from q 3 if it takes input b then arrive at state q 4 here q 4 is a trap state because from q 4 on any input it will remain in the state q 4 itself and q 4 is not a final state or accepted. So, therefore, we see that the language of this d f a is nothing but the set of all strings x belonging to a b such that the number of a's such that the sub string a b occurs exactly once. So, this is what the language accepted by the given d f a. So, here the roles of the states are very clear in recognizing language consider another example. Suppose the language the set of all strings over a b such that say numbers of a's in a string a is debatable by say 3. Let us construct a d f a to accept this language let us consider this to be a star state say q 0. Now, this automaton need not remember how many b's it has raised so far. So, the states has to remember the numbers of a's only if the numbers of a's in the string is debatable by 3 then it should accept otherwise it should reject should not accept. So, q 3 on b it will remain in the same state it simply ignores the numbers of b's in the input. So, once it gets an input as input a as an input then it will go to under state say it is q 1. That means, in q 1 it is clear that instead whenever it arrives at state q 1 the numbers of a's raised so far is at least 1 a it has raised that what will remember at this point. So, again it will ignore any b's that it has raised again on input a it will arrive at state say q 2 instead q 2 instead q 2 it is clear that it has raised 2 a's so far. So, again it will ignore any b's it has raised that means and it will remain the same state q 2 on q 2 if it gets an a's and input it should go to q 0 because at the point it has raised 3 a's. So, any numbers of b's but it has got so far 3 a's. So, therefore, if you make q 0 as the final state you see that. So, numbers of a's raised so far will be divisible by 3 because we can take the same path again from q 0 q 1 that means if we from q 0 again after taking it once if it goes from q 0 to q 1 there will be 4 a's from q 2 to q 1 to q 2 when goes on input a it has got 5 a's from q 2 to q 0 again it has got 6 a's. So, as soon as it is in state q 0 the numbers of a's raised so far will be multiple of 3. Similarly, the same automaton can be modified to accept the state of all strings over a b such that numbers of a's when you divide by 3 it gives 1 as remainder. So, to accept this language simply what you to do instead of this as final state we need to make q 1 as a final state. Similarly, if you want to have a's if you divide the numbers of a's by 3 and the remainder is 2 in such a case q 2 has to be a final state instead of q 0 or q 2. So, therefore, here the roles of the states are very clear remembering what information or what input it has raised so far. Now, just consider the example or language x belonging to a b c star the state of all strings over a b c such that numbers of a's and numbers of b's is divisible by 3. Just considering the concept that we have described in the previous example we can easily construct a DFA for this language. Similarly, you can have many other variations. So, the roles in our a b c such that numbers of x and numbers of b's in the string when you divide by 3 say it is 2 is the remainder and you can have any combinations from this. Now, you want to give the behavior of a DFA in formal way, but prior to that we first see since we have described we have said that a DFA is a computing device we introduce the notion of computation. We first depict the behavior of a DFA by using a figure that will facilitate to understand how it behaves. Just consider we are going to explain the behavior of DFA by using this kind of figure. So, DFA contains normally an infinite tap. So, these are infinite tap and this tap is left justified that means left side is justified and to the right side it can goes to infinity there is a reading head which reads the input from the input tap the reading head and there is a finite control the input tap is normally divided into some cells. So, to the right side it is infinite. So, there will be infinite numbers of cells in it. So, every cell can contain a symbol from the input input of habit say it is a b a a b and so on and the reading head can read one symbol at a time from the input tap. The reading head is connected to the finite control with the finite control finite control contains various states of the finite automata say it is q 0 q 1 q 2 and so on how to say some q n and there is a pointer to point to a particular state the state which the finite automata will be in at any given point will be pointed to by this pointer. Now, with this diagram we can describe the behavior of the d f a or finite automata in informal manner. So, as shown in the figure there are mainly three components namely input tap, reading head and finite control we assume that the d f a has a left justified infinite tap to accommodate the input of any length because towards the right side it is it may go to infinity. The input tap is divided into cells such that it is can accommodate one input symbol from a input of habit and the reading head is connected to the input tap from the finite control which can read one symbol at a time from the input tap. The finite control has the states and the information of the transition function along with the pointer that points to exactly one state. At a given point of time the d f a will be in some internal state say p called the current set pointed by the pointer and the reading head will be reading a symbol say a from the input tap called the current symbol. That means at any itself time it is reading a symbol a from the input tap and it is a particular state suppose it is instead p pointed to by the pointer this p is the current set and a is the input it is reading from the input tap. Now, there is transition defined by this d f a which is defined as delta say p a. So, based on the transition this automaton or this d f a will transit automatically suppose delta p a equal to q then it will automatically go to the state q and the pointer will now point to that particular state q to which it has transit to and the reading head will move one cell towards the right to read the next cell on the input tap. So, that is how the automaton d f a will behave. So, if delta p a equal to q then at the next point of time the d f a will send its internal state from p to q and the pointer will point to q and the reading head will move one cell to the right. Now, we can initialize the d f a with an input string x by initialization we mean that x is placed on the input tap from the left most first that means the first cell of the tap with the reading head placed on the first cell. So, x will be placed on the input tap starting from the left and the reading head will point to the very first cell that means it will be reading the first input and the pointer in the finite control will point to the initial state or the start step and that is the current state of the d f a. Now, since every transition is defined on any state on any input symbol some transition is defined. Therefore, the d f a will transit to a next to the next state as the variable transition table automatically and will continue until the input is exhausted. So, by the time the input is exhausted the current state of the d f a is a final state then the input x is accepted by the d f a there is a notion of acceptance by the d f a. Similarly, if the current state after exhausting the input is not a final state or accepted then we say that x is rejected by the d f a. So, that is how the d f a behaves. Now, we will see how we can compute by using a d f a to see the computation we first described configurations the notion of configuration of a d f a. A configuration or an instance of description of a d f a gives the information about the current state and the person yet to be read. Formally a configuration is an element of q cross sigma star. Now, for a given input string x the initial configuration will always be q 0 x because the initial state is q 0 and the person yet to be read is x the whole input string. And the final state will be the final configuration of d f a will be of the form p epsilon that means the input string is exhausted this x is exhausted that is why we have got epsilon and we have arrived at some state p. So, this is the initial configuration and this is the final configuration the notion of the computation in a d f a can be described through configurations.