Finite Automata

Introduction

The term ‘automata’ has some typical pronounceable symmetry with the term ‘automatic’. In a computer, all processes appear to be done automatically. A given input is processed in the CPU, and an output is generated. We are not concerned about the internal operation in the CPU, but only about the given input and the received output. However, in reality, the input is converted to ‘0’ and ‘1’ and assigned to the process for which the input was given. It then performs some internal operation in its electronic circuit and generates the output in ‘0’ and ‘1’ format. The output generated in the ‘0’ and ‘1’ format is converted to a user-understandable format and we get the output. From the discussion, it is clear that the CPU performs machine operations internally. In automata, we shall learn about how to design such machines. To get a clear idea about the automata theory, we need to travel back to the history of computer science. The engineering branch ‘electrical engineering’ stands on the base of physics. Electronics engineering came from electrical engineering. The hardware of a computer is a complex electronics circuit. The circuit understands only binary command, which is impossible for a human user to memorize. Then, mathematics extends its hand for developing the logic. Mathematics and electronics have jointly given birth to a new branch of engineering called ‘computer science and engineering’.

The name of the subject is formal language and automata theory. We have a basic idea about the automata theory. Now what is formal language? Let us discuss what language is. Language is a communication medium through which two persons communicate. For every nation, there is some language to communicate such as Hindi, English, Bengali, etc. It is the same for communicating with a computer, wherein the user needs some language called the programming language. C, C++, and Java are some examples of programming languages. The characteristics of these types of languages are that they are similar to the English language and are easily understandable by the user. However, the computer does not understand English-like statements. It understands only binary numbers. Therefore, the computers have a compiler that checks the syntax and acts as a converter between English-like statements to binary numbers and vice versa. But, to design the compiler, some logic is needed. That logic can be designed using mathematics. For each language, there is a grammar. Grammar is the constructor for any language. Similarly, the languages that are used for computer programming purpose have some grammar to construct them. These rules and grammar and the process of converting these grammar and languages to machine format are the main objectives of this subject.

3.1  History of the Automata Theory

Theoretical computer science or automata theory is the study of abstract machines and the computational problems related to these abstract machines. These abstract machines are called automata. The origin of the word ‘automata’ is from a Greek word (Aυτóματα) which means that something is doing something by itself.

Around   1936, when there were no computers, Alen Turing proposed a model of abstract machine called the Turing machine which could perform any computational process carried out by the present day’s computer. A formal version of the finite automata model was proposed in   1943 in the McCulloch–Pitts neural network models. Finite automata and finite state machines got a complete form by the efforts of George H. Mealy at the Bell Labs and Edward F. Moore in IBM around   1960. The machines are named as Mealy and Moore machines, respectively. In mid-1950s, Noam Chomsky at the Harvard University started working on formal languages and grammars. Grammar is a set of rules that are performed to produce sentences in the language. Chomsky structured a hierarchy of formal languages based on the properties of the grammar required to generate the languages. The Chomsky hierarchy drives the automata theory one step forward. In   1971, Stephen Arthur Cook in his research paper ‘The Complexity of Theorem Proving Procedures’ formalized the notions of polynomial-time reduction and NP-completeness. He separated those problems that can be solved efficiently by the computer from the set of problems that can be solved but with so much time-taking. These second classes of problems are called NP-hard.

This subject is sometimes called the ‘Theory of Computation’ because it includes all of these rules for constructing a computer language and converts them into machine format. That is the theory of computer science. Basically formal language and automata theory and the theory of computation are different names for a single subject that covers all the aspects of the theoretical part of computer science.

3.2  Use of Automata

It is unfruitful to study a subject without knowing its usefulness. The subject ‘automata theory’ is called one of the core subjects of computer science. Some of the uses of this subject in different fields of computer science and engineering are as follows:

  • The main usefulness of the automata theory is in the compiler design. The first phase of compiler called lexical analyser is designed by the finite automata. In syntax analysis part, a common error called syntax error is checked by the rules of context-free grammar.
  • The working principle of the software used for checking the behaviour of digital circuits is based on the automata theory.
  • The software for natural language processing (NLP) takes the help of the automata theory.
  • Automata is useful for designing the software for counting the occurrence of a particular word, pattern, etc., in a large text.

3.3  Characteristics of Automaton

The word ‘automata’ is plural and the singular is ‘automaton’. A Finite Automaton, in short FA, provides the simplest model of a computing device. It is called finite because it has a finite number of states. The state of the system memorizes the information concerning the past input. It is necessary to determine the future behaviour of the system.

Definition: An automaton is a system where materials, energy, or information are transformed and transmitted for performing some operation without the direct participation of a human.

Any automated machine can be given as an example of automaton. A model of finite automata is given in Fig. 3.1.

Fig.3.1

Fig. 3.1 Block Diagram of Finite Automata

3.3.1  Characteristics

  • Input (I/P): The input is taken in each clock pulse. For every single instance of time t 1 , t 2 , t 3 …. t n , the inputs are taken as I 1 , I 2 , I 3 …… I n . As there are a number of input lines, n number of inputs will be taken in each single time instance. The input for each input line is finite and taken from a set called the set of input alphabets Σ.
  • Output (O/P): The output is generated in each clock pulse. For every single instance of time t 1 , t 2 , t 3 …. t m , the outputs are generated as O 1 , O 2 , O 3 …… O m . The output generated from each output line is finite and belongs to a set called the output alphabet set.
  • State: At any discrete instance of time, the automaton can be in one of the states q 1 , q 2 , q 3 …. q n . The state belongs to a set called ‘State’ Q.
  • State transition: At any instance of time, the automaton must be in one of the states that belong to the set Q. By getting an input in a clock pulse, the automaton must reside in a state. The state in which the automaton resides by getting that particular input is determined by state transition. The state transition is a function of the present state and the present input, which produces the next state. The function is represented as δ.
  • Output relation: Similar to the state transition for state, there is a relation for output. The output depends either on the present state and present input or on the present state only depending on the type of machine.

3.4  Finite Automata

Definition: Finite automata (singular: automaton) are the machine formats of regular expression, which is the language format of type 3 grammar. An FA is defined as

M = {Q, Σ, δ, q 0 , F}

where Q : finite non-empty set of states

    Σ : finite non-empty set of input symbols

    δ : transitional function

    q 0 : beginning state

    F : finite non-empty set of final states

Finite automata are one type of the finite state machine. It has a finite number of states. Finite automata can be thought of as a finite state machine without output.

Mechanically, finite automata can be described as an input tape containing the input symbols (Σ) with a reading head scanning the inputs from left to right. The inputs are fed to finite control which contains the transitional functions (δ). According to the transitional functions, the state (Q) change occurs.

The mechanical diagram of finite automata is given in Fig. 3.2.

Fig.3.2

Fig. 3.2 Mechanical Diagram of Finite Automata

  • Input tape: The input tape contains the input symbol. It is divided into several squares, which contain single characters of the input alphabet. Both the left and right ends of the input tape contain end markers. Between two end markers, the input string is placed. This string is needed to be processed from left to right.
  • Reading head: The head scans each square in the input tape and reads the input from the tape. The head can move from left to right or right to left. But, in most of the cases, the head moves from left to right. In two-way finite automata and the Turing machine, the head can move in both directions.
  • Finite control: Finite control can be considered as the control unit of an FA. An automaton always resides in a state. The reading head scans the input from the input tape and sends it to finite control. In this finite control, it is decided that ‘the machine is in this state and it is getting this input, so it will go to this state’. The state transition relations are written in this finite control.

3.5  Graphical and Tabular Representation of FA

Finite automata can be represented in two ways: (i) graphical and (ii) tabular.

  1. In the graphical representation, a state is represented as image

    A beginning state is represented as image

    A final state is represented as image

    An FA is represented in graphical format in Fig. 3.3.

    Fig.3.3

    Fig. 3.3 Graphical Representation of Finite Automata

    Here

    image

  2. In the tabular format, a state is represented by the name of the state.

    The beginning state is represented as image

    The final state is represented as image

    For the previous finite automata, the tabular format is

    image

    Here

    image

3.6  Transitional System

A transitional system (sometimes called the transitional graph) is a finite-directed graph in which each node (or vertex) represents a state, and the directed arc indicates the transition of the state. The label of the arc indicates the input or output or both.

A transitional function has two properties.

  1. Property I: δ(q, Λ) → q. It means if the input is given null for a state, the machine remains in the same state.

  2. Property II: For all string X and input symbol a ε Σ,

    image

3.6.1  Acceptance of a String by Finite Automata

There are two conditions for declaring a string to be accepted by a finite automaton. The conditions are

Condition I: The string must be totally traversed.

Condition II: The machine must come to a final state.

In short, it can be said that if δ(q 0 , W) = q n , where W is the string given as input to the FA, q 0 is the beginning state, and q n belongs to the set of final states, then the string W can be said to be accepted by the FA.

If these two conditions are fulfilled, then we can declare a string to be accepted by an FA.

If any of the conditions are not fulfilled, then we can declare a string to be not accepted by an FA.

The following examples ( Examples 3.1 and 3.2 ) describe this.

Example 3.1

Check whether the string 011001 is accepted or not by the following FA.

image

Solution: For the given FA, Q = {q 0 , q 1 , q 2 , q 3 } Σ = {0, 1}. The beginning state is q 0 and the final state is q 3 .

The transitional functions are given in the table.

For checking whether a string is accepted by an FA or not, we will assume that the input string is given input in the beginning state q 0 . But only a single input is given in each clock pulse. So, at first, the left most character is given the input to the beginning state. From the transitional function given in the table, the next state is determined. The next character of the input string is treated as the input to the state just achieved. And it will process like this till the string is finished or such a condition has arrived so that there is no transitional function mentioned in the table.

If the string is finished and the state achieved is the final state, then the string will be declared accepted by the machine.

If it does not happen, then the string will be declared not accepted.

image

q 3 is the final state of the FA. So, the two conditions for acceptability of a string by an FA is fulfilled. So, the string 011001 is accepted by the given finite automata.

Example 3.2

Test whether the strings 010010 and 01010 are accepted by the finite automata given in Fig. 3.4 or not.

Fig. 3.4

Fig. 3.4

Solution:

image

q 2 is the final state of the FA. So, the string 010010 is accepted by the FA.

image

q 1 is not the final state of the FA. The string is finished, but the machine has not come to the final state. So, the string is not accepted by the FA.

3.7  DFA and NFA

Finite automata are of two types: deterministic finite automata or DFA and non-deterministic finite automata or NFA.

DFA is a finite automata where, for all cases, when a single input is given to a single state, the machine goes to a single state, i.e., all the moves of the machine can be uniquely determined by the present state and the present input symbol.

A DFA can be represented as

M DFA = {Q, Σ, δ, q 0 , F},

where δ is a transitional function mapping Q × Σ → Q, where | Q | = 1. The meanings of all other notations are the same as finite automata.

Non-deterministic finite automata or NDFA or NFA is a finite automaton where, for some cases, when a single input is given to a single state, the machine goes to more than one states, i.e., some of the moves of the machine cannot be uniquely determined by the present state and the present input symbol.

An NFA can be represented as

M NFA = {Q, Σ, δ, q 0 , F},

where δ is a transitional function mapping Q × Σ → 2 Q , where 2 Q is the power set of Q.

(A power set means the set of all subsets of the set. For a set with n number of elements, the number of subsets or power set is 2 n . For example, for the set {1, 2, 3}, the subsets are { }, {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, and {1, 2, 3}. A total of 8, i.e., 2 3 .)

As an example, consider the following machine.

image

Here, for the state q 0 for input 0, it can go to q 0 or q 1 . So, it is an example of NDFA or NFA.

For a DFA, it can be easily determined whether a string is accepted by it or not. However, for an NFA, it is difficult.

(In real life, an NFA can be thought of driving through a path with multiple wing paths. An inexperienced driver can make mistake in choosing the wings to reach to the destination. If he/she chooses the right wing, he/she will be able to reach, but choosing the wrong route will cost failure.)

Consider Example 3.3 to clarify this.

Example 3.3

Test whether the string ‘00101’ is accepted by the following finite automata given in Fig. 3.5 or not.

Fig. 3.5

Fig. 3.5

Solution: In the previous given FA, we see that from q 0 for input 0 it can go to q 0 and q 1 . That is, for q 0 for input 0 there are two paths.

Let us draw a transaction diagram like Fig. 3.6 to make the understanding clear.

Fig.3.6

Fig. 3.6 Transitional Path for Testing the Acceptability of 00101

From the transaction diagram, from q 0 for input string 00101, we get three paths. For traversing the string 00101, we get the last states as q 1 , q 2 , and q 1 , respectively. Among them, q 2 is the final state. That is, for the string 00101 from q 0 we can reach the final state. So, the string 00101 is accepted by the FA.

But, if someone follows path 1 and path 3, it will not be possible to reach the final state. Then, it can be declared that the string is not accepted by the FA. That means it depends on the path which is being followed by the FA.

A string w ε Σ* is accepted by an NFA if δ(q 0 , w) contains some final state.

So, the string 00101 is accepted by the FA.

3.8  Conversion of an NFA to a DFA

For a DFA, δ is a transitional function mapping Q × Σ → Q, where | Q | = 1

For an NFA, δ is a transitional function mapping Q × Σ → 2 Q , where 2 Q is the power set of Q.

For an NFA, for a single input given to a single state, the machine can go to more than one state. So, for an NFA, it is hard to decide for a string to be accepted by the NFA or not. If an NFA can be converted to a DFA, then this type of problem will not arise.

That means, we have to convert Q × Σ → 2 Q to Q′ × Σ → Q′, where Q is the finite set of states for an NFA, and Q′ is the set of states for the converted DFA.

3.8.1  Process of Converting an NFA to a DFA

  • Start from the beginning state of the NFA. Take the state within [ ].
  • Place the next states for the beginning state for the given inputs in the next state columns. Put them also in [ ].
  • If any new combination of state appears in next state column, which is not yet taken in the present state column, then take that combination of state in the present state column.
  • If in the present state column more than one state appears, then the next state for that combination will be the combination of the next states for each of the states.
  • If no new combination of state appears, which is not yet taken in the present state column, stop the process.
  • The beginning state for the constructed DFA will be the beginning state of the NFA.
  • The final state or final states for the constructing DFA will be the combination of states containing at least one final state.

Consider the following examples ( Examples 3.4 to 3.6 ).

Example 3.4

Construct a DFA from the given NFA.

image

Solution:

Present State
Next State
0
1
[q 0 ]
[q 0 , q 1 ]
[q 2 ]
[q 0 , q 1 ]
[q 0 , q 1 , q 2 ]
[q 1 , q 2 ]
[q 1 , q 2 ]
[q 1 , q 2 ]
[q 1 , q 2 ]
[q 0 , q 1 , q 2 ]
[q 0 , q 1 , q 2 ]
[q 1 , q 2 ]
[q 1 ]
[q 2 ]
[q 1 ]

Let us replace [q 0 ] as A, [q 0 , q 1 ] as B, [q 1 , q 2 ] as C, [q 0 , q 1 , q 2 ] as D, [q 2 ] as E, and [q 1 ] as F.

Then, the constructed finite automata is

Present State IP
Next State
0
1
A
B
E
B
D
C
C
C
C
D
D
C
E
F
E
F
E
F

In the finite automata, we are seeing that, for a single state, for a single input the machine can go to only one state. So it is a DFA.

The beginning state is [q 0 ], i.e., A. The final states are [q 1 , q 2 ], i.e., C, [q 0 , q 1 , q 2 ], i.e., D, and [q 2 ], i.e., E.

The transaction diagram for the DFA is given in Fig. 3.7.

Fig. 3.7

Fig. 3.7

Example 3.5

Construct a DFA from the given NFA.

image

Solution:

Present State
Next State
0
1
[q 0 ]
[q 0 , q 1 ]
[q 0 ]
[q 0 , q 1 ]
[q 0 , q 1 , q 2 ]
[q 0 , q 1 ]
[q 0 , q 1 , q 2 ]
[q 0 , q 1 , q 2 , q 3 ]
[q 0 , q 1 , q 3 ]
[q 0 , q 1 , q 3 ]
[q 0 , q 1 , q 2 ]
[q 0 , q 1 , q 2 ]
[q 0 , q 1 , q 2 , q 3 ]
[q 0 , q 1 , q 2 , q 3 ]
[q 0 , q 1 , q 2 , q 3 ]

Let us replace [q 0 ] as A, [q 0 , q 1 ] as B, [q 0 , q 1 , q 2 ] as C, [q 0 , q 1 , q 3 ] as D, and [q 0 , q 1 , q 2 , q 3 ] as E.

image

In the finite automata, we are seeing that, for a single state, for a single input the machine can go to only one state. So it is a DFA.

The beginning state is A. The final states are D and E.

The transaction diagram for the DFA is given in Fig. 3.8.

Fig. 3.8

Fig. 3.8

Example 3.6

Construct an equivalent DFA for the given NFA.

image

Solution:

Present State IP
Next State
a
b
[q 0 ]
[q 0 , q 1 ]
[q 2 ]
[q 0 , q 1 ]
[q 0 , q 1 ]
[q 1 , q 2 ]
[q 1 , q 2 ]
[q 0 ]
[q 0 , q 1 ]
[q 2 ]
[–]
[q 0 , q 1 ]
[–]
[–]
[–]

Here, for the state q 2 for input ‘a’ in the given NFA, no state was mentioned. So, we have taken it as a new state [–], when converting from NFA to DFA. For the new state [–], as no next state is mentioned in the NFA, we have taken the same state [–] for both the inputs a and b.

(Soon we shall learn that these types of states are called dead state.)

Let us replace [q 0 ] by A, [q 0 , q 1 ] by B, [q 1 , q 2 ] by C, [q 2 ] by D, and [–] by E. The tabular representation of the DFA is as follows.

Present State IP
Next State
a
b
A
B
D
B
B
C
C
A
B
D
E
B
E
E
E

In the finite automata, we are seeing that, for a single state, for a single input the machine can go to only one state. So, it is a DFA.

The beginning state is A. The final states are C and D as both of them contain q 2 .

The transaction diagram for the DFA is given in Fig. 3.9.

Fig. 3.9

Fig. 3.9

3.9  NFA wit ε (null) Move

If any finite automata contains any ε (null) move or transaction, then that finite automata is called NFA with ε moves. As an example,

Fig. 3.10

Fig. 3.10

The finite automata in Fig. 3.10 contain two null moves. So, the previous FA is NFA with null move according to the definition.

Now, in this stage, the question comes—why is this called an NFA? From the definition of an NFA, we know that for an NFA from a single state for a single input the machine can go to more than one state, i.e., Q × Σ → 2 Q , where 2 Q is the power set of Q.

From a state by getting ε input, the machine is confined into that state (Ref. Property of transitional system ). An FA with null move must contain at least one ε move. For this type of finite automata, for input ε, the machine can go to more than one state. (One is that same state and another is the ε-transaction next state). So, a finite automata with ε move can be called as an NFA.

For the previous finite automata in Fig. 3.10.

image

An NFA with ε move can be defined as

M NFA, null = {Q, Σ, δ, q 0 , F}

where Σ: set of input alphabets including ε, and δ is a transitional function mapping. Q × Σ → 2 Q , where 2 Q is the power set of Q.

3.9.1  Usefulness of NFA with ∈ Move

If we want to construct an FA which accepts a language, sometimes it becomes very difficult or seems to be impossible to construct a direct NFA or DFA. But if NFA with ε moves is used, then the transitional diagram can be constructed and described easily.

Consider the following example.

Example 3.7

Let us assume that we are given to construct a DFA that accepts any combinations of string of a, b, c. That means the string can start with a or b or c. After any symbol, any of the symbols can come in any combination and all strings are accepted. The DFA for this is given in Fig. 3.11.

Fig. 3.11

Fig. 3.11

Solution: But it is not clearly understandable as to how any combinations of a, b, c can come. In this case, an NFA with ε move plays its role as represented by the transitional diagram in Fig. 3.12.

Fig. 3.12

Fig. 3.12

Now it is clearly understandable that the string can start with a or b or c. And for the null transitions from any state, we can move to any other state with no input. So, if c comes after ‘a’, we can go from q 0 to q 2 easily with no input. The same thing can occur for all the other states.

3.9.2  Conversion of an NFA with ε Moves to DFA without ε Move

Let us assume that in the NFA we want to remove the ε move which exists between the states S 1 and S 2 .

This can be removed in the following way

  • Find all the edges (transitions) those start from the state S 2 .
  • Duplicate all these transitions starting from the state S 1 , keeping the edge label the same.
  • If S 1 is the initial state, also make S 2 as the initial state.
  • If S 2 is the final state, also make S 1 as the final state.

Consider the following examples.

Example 3.8

Convert the following NFA with null move in Fig. 3.13 to an equivalent DFA without ε move.

Fig. 3.13

Fig. 3.13

Solution: Three null moves exist in the previous transitional diagram. The transitions are

  1. from q 0 to q 1
  2. from q 1 to q 2
  3. from q 0 to q 2

These null transitions are removed step by step.

Step I:

  1. Between the states q 0 and q 1 , there is a null move. If we want to remove that null transition, we have to find all the edges starting from q 1 . The edges are q 1 to q 1 for input 1 and q 1 to q 2 for input ε.

  2. All these transitions starting from the state q 0 are duplicated, keeping the edge label the same. q 0 is the initial state, so make q 1 also an initial state. The modified transitional diagram is given in Fig. 3.14.

    Fig. 3.14

    Fig. 3.14

Step II:

  1. Between q 1 and q 2 , there is a null transaction. To remove that null transition, find all the edges starting from q 2 . The edge is q 2 to q 2 for input 2.

  2. Duplicate the transition starting from the state q 1 , keeping the edge label the same. q 1 is the initial state, so make q 2 also an initial state. q 2 is the final state, so make q 1 also a final state. The modified transitional diagram is given in Fig. 3.15.

    Fig. 3.15

    Fig. 3.15

Step III:

  1. Between q 0 and q 2 , there is a null transaction. To remove that null transition, find all the edges starting from q 2 . The edge is q 2 to q 2 for input 2.

  2. Duplicate the transition starting from the state q 0 , keeping the edge label the same. q 0 is the initial state, so make q 2 also an initial state. q 2 is the final state, so make q 0 also a final state. The modified transitional diagram is given in Fig. 3.16.

    Fig. 3.16

    Fig. 3.16

This is the equivalent NFA without ε move obtained from the NFA with null transaction.

Example 3.9

Convert the following NFA with null move to an equivalent NFA without ε move as given in Fig. 3.17.

Fig. 3.17

Fig. 3.17

Solution: In the given NFA with ε move, there are three ε transitions: from A to B, from B to D, and from B to C. The three ε transitions are removed step by step.

Step I: There is a ε transition from A to B. To remove that ε transition, we have to find all the edges starting from B. The edges are B to C for input c and B to D for input ε.

Duplicate the transition starting from the state A, keeping the edge label the same. A is the initial state, so make B also an initial state. The modified transaction diagram is shown in Fig. 3.18.

Fig. 3.18

Fig. 3.18

Step II: Again there are three ε transactions in the NFA. These are from A to D, from B to D, and from C to B.

Let us remove the ε transaction from B to D. The edge starting from D is D to D for input a. Duplicate the transition starting from the state B, keeping the edge label the same. As B is the initial state, D will also be the initial state. As D is the final state, B will also be the final state. The modified transaction diagram will be as shown in Fig. 3.19.

Fig. 3.19

Fig. 3.19

Step III: Now we are going to remove the ε transaction from A to D. The edge starting from D is D to D for input a. Duplicate the transition starting from the state A, keeping the edge label the same. As A is the initial state, D will also be the initial state. As D is the final state, A will also be the final state. The modified transaction diagram will be as shown in Fig. 3.20.

Fig. 3.20

Fig. 3.20

Step IV: There is only one ε transaction from C to B. To remove this, find the edges starting from B. There are two: from B to D for input a and from B to C for input c. Start these edges from C. B is the final state, so make C as the final state. The modified transitional diagram will be as shown in Fig. 3.21.

Fig. 3.21

Fig. 3.21

This is the equivalent NFA without ε move obtained from the NFA with null transaction.

3.10  Equivalence of DFA and NFA

A DFA can simulate the behaviour of an NFA by increasing its number of states. The DFA does not contain any null move and any transitional functions of a state and input reaching to more than one states. In this section, we shall prove the following:

‘If a language L is accepted by an NDFA, then there exists a DFA that accepts L’.

Proof: Let M be an NDFA denoted by {Q, Σ, δ, q 0 , F} which accepts L.

We construct a DFA M′ = {Q′, Σ, δ′, q ′ 0 , F ′}, where Q′ contains the subsets of Q, i.e., Q′ = 2 Q .

Q′ may be denoted by [q 1 , q 2 , . . . . . q n ] as a single state where q 1 , q 2 , . . . . . q n ∈ Q

Initial state q′ 0 = [q 0 ]

Final state F′ = set of all states in Q′ containing at least one final state of M.

Transitional function δ′is defined as

image

This is the case for a single input ‘a’. Now, we shall prove it for some input string x. x may be of length 0 to length n. We prove this by induction.

Let | x | = 0, i.e., x is a null string.

δ′(q′ 0 , x) = [q 0 ] as q′ 0 = [q 0 ] and δ(q 0 , x) = δ(q 0 , ε) = q 0 .

Thus, the induction has a base condition.

Let us assume that it is true for each string of length n. Now we need to prove that the result is true for any string of length (n + 1).

image

By induction, it is proved that δ′(q′ 0 , x) = [P 1 , P 2 , . . . . . P k ] if and only if

δ(q 0 , x) = {P 1 , P 2 , . . . . . P k }

So, δ′(δ′(q′ 0 , x)a) = δ′([P 1 , P 2 , . . . . . P k ], a) = [r 1 , r 2 , . . . . . r k ] if and only if

image

Thus δ′(q′ 0 , xa) = δ′(δ′(q′ 0 , x)a) = [r 1 , r 2 , . . . . . r k ]

It is proved that the result is true for a string of length n + 1, if it is true for a string of length n. Now δ′(q′ 0 , x) ∈ F′ when δ(q 0 , x) to a state of Q in F.

Therefore, it is proved that L(M) = L(M′).

3.11  Dead State

The name dead state was mentioned in Example 3.6 of converting an NFA to an equivalent DFA. Dead state is a state where the control can enter and be confined till the input ended, but there is no way to come out from that state. (The string is dead or finished on entering the state.)

Fig. 3.22

Fig. 3.22

An example for the previous finite automata is shown in Fig. 3.22; from q 0 for input 0, there is a path to go to q 1 . But there is no path mentioned from q 0 for input 1. The same thing happens also for q 2 for input 0. Now, let a string 101 be given as input to the FA to test the acceptability of the string by the finite automata.

According to the condition of the acceptability, the first condition, i.e., the string will be totally traversed, is not fulfilled. Obviously, the second condition is also not fulfilled.

We have to decide that the string is not accepted by the finite automata without traversing the string totally!

For making the string totally traversed, we have to include an extra state, say q f , where the control will go from the states for which there is only one path for one input. In the state q f , for the inputs, there will be a self-loop. Here, q f is the dead state.

By including the dead state, the finite automata becomes as shown in Fig. 3.23.

Dead state makes the string totally traversed.

Fig. 3.23

Fig. 3.23

3.12  Finite Automata with Output

Till now, we were discussing machines with no output. But two things, output and output relations, are omitted. This was mentioned in the characteristics of the automaton. As FA is a machine, it must produce output. In this section, we shall discuss finite automata with output. Finite automata with output can be divided into two types:

  1. The Mealy machine
  2. The Moore machine

3.12.1  The Mealy Machine

The Mealy machine was proposed by George H. Mealy at the Bell Labs in 1960.

The Mealy machine is one type of finite automata with output, where the output depends on the present state and the present input.

The Mealy machine consists of six touples

M = (Q, Σ, Δ, δ, λ, q 0 ),

where

     Q : finite non-empty set of states

     Σ : set of input alphabets

     Δ : set of output alphabets

     δ : transitional function mapping Q × Σ → Q

     λ : output function mapping Q × Σ → Δ

     q 0 : beginning state

3.12.2  The Moore Machine

The Moore machine was proposed by Edward F. Moore in IBM around 1960.

The Moore machine is one type of finite automata where output depends on the present state only, but the output is independent of the present input.

The Moore machine consists of six touples

M = (Q, Σ, Δ, δ, λ, q 0 ),

where

     Q : finite non-empty set of states

     Σ : set of input alphabets

     Δ : set of output alphabets

     δ : transitional function mapping Q × Σ → Q

     λ : output function mapping Q → Δ

     q 0 : beginning state

3.12.3  Tabular and Transitional Representation of the Mealy and Moore Machines

3.12.3.1  Tabular

The output of the Mealy machine depends on both the present state and the present input. So, for the mealy machine, there will be n number of output columns if there are n number of input.

The tabular format of the Mealy machine is as follows.

image

The output of the Moore machine depends on the present state only. As in a machine, there is only one present state column, so there is only one output column.

The tabular format of the Moore machine is given in the following table.

image

3.12.3.2  Transitional

The Mealy machine is one type of finite automata with output. The transitional diagram is like finite automata, but the output is mentioned. As we know, the output of a Mealy machine depends on the present state and the present input. So, for a Mealy machine, the transitional arc will be labelled with both input and output like the example in Fig. 3.24.

Fig. 3.24

Fig. 3.24

The output of the Moore machine depends only on the present state. For a Moore machine, the states are labelled with the state name and the output like the example shown in Fig. 3.25.

Fig. 3.25

Fig. 3.25

The following are some examples of finite automata with output.

Example 3.10

Design a Mealy machine to get complement of binary number.

Solution: For input 0, the machine gives the output 1, and for input 1 the machine will give the output 0. The Mealy machine is constructed as shown in Fig. 3.26.

Fig. 3.26

Fig. 3.26

Example 3.11

Design a Moore machine which determines the residue mod-3 for each binary string treated as binary integer.

Solution: Binary string consists of two types of characters 0 and 1. Binary integer means the decimal equivalent of a binary string as integer number. Residue mod-3 means the reminder received when the decimal equivalent of the binary number is divided by 3.

If a decimal number is divided by 3, only three types of reminders 0 or 1 or 2 are generated. The output of the Moore machine depends only on the present state. So, for three types of reminders (output), three states are needed.

Let us assume that state q 0 is producing output 0, state q 1 is producing output 1, and state q 2 is producing output 2. Now, it is needed to construct the transitional arcs. Before construction, take a table containing binary equivalent of decimal numbers from 0 to 9 and the reminders for each of them, when divided by 3.

Decimal
Binary
Reminders
0
0
0
1
1
1
2
10
2
3
11
0
4
100
1
5
101
2
6
110
0
7
111
1
8
1000
2
9
1001
0

Input 0, output is 0. The transitional function is δ(q 0 , 0) → q 0 , because q 0 state produces output 0. Input 1, output 1, the transitional function is δ(q 0 , 1) → q 1 , because q 1 state produces output 1. Input 10, output is 2. So, the transitional function is δ(q 1 , 0) → q 2 , because q 2 state produce output 2. Input 11, output is 0. So, the transitional function is δ(q 1 , 1) → q 0 . By this process, all the transitional functions can be produced.

The Moore machine is given in Fig. 3.27 for the given problem.

Fig. 3.27

Fig. 3.27

Example 3.12

Design a Mealy machine which determines the residue mod-3 for each binary string treated as a binary integer.

Solution: The machine is a Mealy machine, and so the outputs depend on the present state and the present input.

For input 0, output is 0. The transitional function is δ(q 0 , 0) → q 0 and output function λ is q 0 × 0 → 0. For input 1, output is 1. The transitional function becomes δ(q 0 , 1) → q 1 and the output function λ is q 0 × 1 → 1. For input 10, output is 2. So, the transitional function is δ(q 1 , 0) → q 2 , and the output function λ is q 1 × 0 → 2. For input 11, output is 0, which makes the transitional function as δ(q 1 , 1) → q 0 , and the output function λ is q 1 × 0 → 0. By this process, all the transitional functions are constructed. The final Mealy machine for the problem is given in Fig. 3.28.

Fig. 3.28

Fig. 3.28

Example 3.13

Design a Moore machine which counts the occurrence of substring aba in a given input string.

Solution: It is one type of sequence detector. When the string aba occurs as a substring, then output 1 is produced. For all the other cases, the output 0 is produced (overlapping sequences are also accepted).

We have to design a Moore machine, i.e., the output depends only on the present state. For a string length of 3, we need four states if from a state with single input the machine goes to another new state. Let us name the states as q 0 , q 1 , q 2 , and q 3 . Except q 3 , all the states produce output 0. In state q 0 , we can get two types of input, a or b. If we get ‘a’, then there is a chance to get ‘aba’. So, it moves forward to q 1 . If we get ‘b’, then there is no chance to get ‘aba’, so it confines to the same state. In q 1 , again two types of input can occur, ‘a’ and ‘b’. If we get ‘a’, then by considering this ‘a’ there is a chance to get ‘aba’. So, it confines to the same state. If we get b, then we are two steps forward to get ‘aba’. So, the machine moves forward to state q 2 . In q 2 , if we get ‘b’ then there is no chance to get ‘aba’ except starting from the beginning. So, it traverses to q 0 . If we get ‘a’, we have got the string aba. The machine will go to state q 3 . In q 3 , if we get ‘a’, then again there is a chance to get ‘aba’. From q 0 , by getting ‘a’, the machine has moved forward to q 1 . So, from q 2 by getting ‘a’ the machine will go to q 1 . If we get ‘b’, then by considering the previous ‘a’ again there is a chance to get ‘aba’, so the machine moves to state ‘q 2 ’.

From the earlier discussions, the transitional functions can easily be derived. As it is a Moore machine, the outputs are included with the state (output depends only on the present state and not on the present input), and so there is no need to derive the output functions. The constructed Moore machine for the earlier problem is given in Fig. 3.29.

Fig. 3.29

Fig. 3.29

Example 3.14

Design a Mealy machine which counts the occurrence of substring aab in a given input string.

Solution: The machine will be a Mealy machine, that is, the output depends on the present state and the present input. (Discussions will be like previous.)

The machine is given in Fig. 3.30.

Fig. 3.30

Fig. 3.30

3.13  Conversion of One Machine to Another

Mealy and Moore are two different machines. In the Mealy machine, the output depends on the present state and the present input. For this reason, the length of the output is the same as the given input string. But in the Moore machine, the output depends only on the present state. One output is counted as the traversal starts from the initial state without taking any input character. For this reason, the length of the output is one more than the length of the input string.

It can be proved that if M = (Q, Σ, Δ, δ, λ, q 0 ) is a Moore machine, then there exists an equivalent Mealy machine M′ = (Q, Σ, Δ, δ, λ′, q 0 ), where λ′ (Q, a) = λ (δ(Q, a)).

The following section covers how to convert a Moore machine to a Mealy machine and vice versa.

3.13.1  Tabular Format

3.13.1.1 Conversion of a Moore Machine to a Mealy Machine

  • Draw the tabular format of a Mealy machine.
  • Put the present states of the Moore machine in the present state column of the constructing Mealy machine.
  • Put the next states for the corresponding present states and input of the Moore machine in the next state column for those present states and input, respectively, of the corresponding Mealy machine.
  • For the output, look into the present state column and the output column of the Moore machine. The output for Q Next (next state for the present state Q Present and input I P of the constructing Mealy machine) will be the output for that state (Q Next ) as a present state in the given Moore machine.

The following examples ( Examples 3.15 to 3.17 ) describe the previous method.

Example 3.15

Construct a Mealy machine equivalent to the given Moore machine.

image

Solution:

image

In the Moore machine, for q 1 as a present state, the output is 1. So, in the constructing Mealy machine, for q 1 as a next state the output will be 1.

In the Moore machine, for q 2 as a present state, the output is 0. So, in the constructing Mealy machine, for q 2 as a next state the output will be 0.

Example 3.16

Construct a Mealy machine equivalent to the given Moore machine.

image

Solution:

image

Example 3.17

Construct a Mealy machine equivalent to the given Moore machine.

image

Solution:

image

3.13.1.2  Conversion of a Mealy Machine to a Moore Machine

  • Draw the tabular format of a Mealy Machine first.
  • Look into the next state and output columns of the given Mealy machine.
  • If for the same next state in the next state column, the output differs in the output column, break the state q i into different number of states. The number is equal to the number of different outputs associated with q i .
  • Put the states of the present state column in the new table. Put the broken states in the place of those states that are broken into a number of different states.
  • Change the next states in the next state columns according to the new set of states.
  • Put the output from the output column of the original Mealy machine in the new machine also.
  • Draw the tabular format of a Moore machine.
  • Put the present states and next states from the newly constructed Mealy machine into the constructed Moore machine.
  • For output, look into the next state and output column of the newly constructed Mealy machine. For a state as a next state (let q i ) in the new constructed Mealy Machine if output is 0 then for the state (q i ) as a present state in the constructing Moore Machine; the output will be 0.
  • For the Moore machine, the output depends only on the present state. This means that from the beginning state for Λ input, we can get an output. If the output is 1, the newly constructed Moore machine can accept zero length string, which was not accepted by the given Mealy machine. To make the Moore machine not to accept Λ string, we have to add an extra state q b (new beginning state), whose state transactions will be identical with those of the existing beginning state, but with output as 0.

(For a Mealy machine with m number of states and n number of outputs, the Moore machine will be of n number of outputs but not more than mn + 1 number of states.)

The following examples ( Example 3.18 to 3.20 ) describe the previous method.

Example 3.18

Convert the given Mealy machine to an equivalent Moore machine.

image

Solution: Look into the next state and output columns of the given Mealy machine. For I/P 0 for q 1 as a next state, the output is 1. For I/P 1 for q 1 as a next state, the output is 0. The same thing happens for q 2 as a next state for input 0 and input 1. So the state q 1 is broken as q 10 and q 11 , and the state q 2 is broken as q 20 and q 21 . After breaking, the modified Mealy machine becomes

image

For the present state q 0 for input 1, the next state is q 10 , because there is no q 1 in the modified Mealy machine. It has been broken into q 10 and q 11 depending on the output 0 and 1, respectively. For the present state q 0 for input 1, the output is 0. So the next state is q 10 . The same cases occur for the others also. For the broken states, the next states and outputs are the same as the original, from where the broken states have come.

From this, the Moore machine becomes

image

For Moore machine the beginning state is q 0 and the corresponding output is 1. That means, with null length input (no input), we are getting an output of 1. That is, the Moore machine accepts 0 length sequence [because here output depends only on the present state] which is not acceptable for the Mealy machine. To overcome this situation, we must add a new beginning state q b with the same transactions as q 0 , but with output as 0. By including the new state, the Moore machine is

image

Example 3.19

Convert the given Mealy machine to an equivalent Moore machine.

image

Solution: For q 0 for input 0, the output differs. For q 2 for inputs 0 and 1, the output differs. So the states are broken as q 00 , q 01 and q 20 , q 21 . According to the new states, the modified Mealy machine becomes

image

image

From this modified Mealy machine, the Moore machine is

image

Example 3.20

Convert the given Mealy machine to an equivalent Moore machine.

image

Solution: In the next state column of the given Mealy machine, the output differs for q 1 and q 3 as the next state. So, the states are divided as q 10 , q 11 and q 30 , q 31 , respectively. After dividing the states, the modified Mealy machine becomes

image

In the next state column of the modified Mealy machine, when q 0 is a next state, the output is 0. So, in the constructing Moore machine, for the present state q 0 , the output is also 0. Similarly, for the present state q 2 , the output is 0. For the divided states like q 10 , q 11 , there is no need to mention the output as they were divided according to the distinguished output. So, the constructing Moore machine is

image

To get rid of the problem of the occurrence of null string, we need to include another state, q a , with same transactions as of q 0 but with output 0.

The modified final Moore machine equivalent to the given Mealy machine becomes

image

3.13.2  Transitional Format

From the transitional diagram of a Moore or Mealy machine, conversion can be done easily. That process is described here.

3.13.2.1  Moore Machine to Mealy Machine

Let us assume that a Moore machine M o is to be converted to an equivalent Mealy machine M C . There are certain steps for this conversion.

Step I: For a Moore machine, each state is labelled with the output, because for a Moore machine, output depends only on the present state. For the conversion, let us take a state S, which is labelled with output O. Look into the incoming edges to the state S. These incoming edges are labelled by the input alphabets of the Moore machine. These incoming edges are relabelled by the input alphabet as well as the output of the state S. The output for the state must be removed.

Step II: Keep the outgoing edges from the state S as it was. (The outgoing edge of a state must be the incoming edge of some other state.)

Step III: Repeat these steps for each of the states. By this process, the Mealy machine-equivalent Moore machine is constructed. The process is described in Fig. 3.31.

Consider the following examples.

Fig. 3.31

Fig. 3.31 Process of Conversion of a Moore Machine to a Mealy

Example 3.21

Convert the following Moore machine into an equivalent Mealy machine as given in Fig. 3.32.

Fig. 3.32

Fig. 3.32

Solution:

  1. In this machine, A is the beginning state. So, start from A. For A, there are two incoming arcs, from C to A with input b and another in the form of the start-state indication with no input. State A is labelled with output 0. As the start-state indication contains no input, it is useless and, therefore, keep it as it is.

    Modify the label of the incoming edge from C to B including the output of state A. So, the label of the incoming state is C to A with label b/0.

  2. State B is labelled with output 1. The incoming edges to the state B are from A to B with input a, B to B with inputs a and b, and C to B with input a.

    Modify the labels of the incoming edges including the output of state B. So, the labels of the incoming states become A to B with label a/1, B to B with labels a/1 and b/1, and C to B with label a/1.

  3. State C is labelled with output 0. There is only one incoming edge to this state, from A to C with input b. The modified label is b/0.

    The converted Mealy machine is given in Fig. 3.33.

Fig. 3.33

Fig. 3.33

Example 3.22

Convert the following Moore machine into an equivalent Mealy machine as given in Fig. 3.34.

Fig. 3.34

Fig. 3.34

Solution: State A is labelled with output 0. The incoming edges to this state are C to A for input b, A to A for input b, and one as start-state indication with no input. Ignore the edge with start-state indication.

Modify the labels of the incoming edges by including the output of state A. So, the modified labels become A to A with label b/0 and C to A with label b/0.

State B is labelled with output 0. The incoming edges to this state are A to B for input a, B to B for input a, and D to B for input a. The modified labels are A to B with label a/0, B to B with label a/0, and D to B with label a/0.

State C is labelled with output 0. The incoming edges to this state are B to C for input b, and D to C for input b. The modified labels are B to C with label b/0 and D to C with label b/0.

State D is labelled with output 1. The incoming edge to this state is C to D for input a. The modified label is from C to D with label a/1.

The Mealy machine equivalent to the given Moore machine is given in Fig. 3.35.

Fig. 3.35

Fig. 3.35

3.13.2.2  Mealy Machine to Moore Machine

For a given Mealy machine M C , there is an equivalent Moore machine M o . These can be constructed in several steps.

Step I: In a Mealy machine, the output depends on the present state and the present input. So, in the transactional diagram of a Mealy machine, the transactional edges are labelled with input as well as output. For a state, there two types of edges, namely, incoming edges and outgoing edges. For incoming edges, it may happen that the output differs for two incoming edges like the example shown in Fig. 3.36.

Fig. 3.36

Fig. 3.36

In the transitional diagram for state S, the incoming edges are labelled as I 1 /O 1 , I 2 /O 2 , and I 2 /O 1 , and the outgoing edges are labelled as I 1 /O 2 and I 2 /O 2 . For state S for incoming edges, we get two types of output O 1 and O 2 . The state S is divided into n number of parts, where n = number of different outputs for the incoming edges to the state. The output edges are repeated for all the divided states. The transitional diagram for this case is shown in Fig. 3.37.

Fig. 3.37

Fig. 3.37

Step II: If a state has a loop like Fig. 3.38 , that state also needs to be divided as shown in Fig. 3.39.

Fig. 3.38

Fig. 3.38

Fig. 3.39

Fig. 3.39

[Here, for input I 1 , the output is O 1 as well as O 2 . So, the state S needs to be divided. S has a loop with input I 2 and output O 1 .]. The state S will be divided into two states S O1 and S O2 . As the loop for input I 2 is labelled with output O 1 , there will be a loop on state S O1 . But this loop is not possible on S O2 , because it produces the output O 2 . So, there will be a transition from S O2 to S O1 with input label I 2 .

Step III: Repeat the steps I and II. By this, the Moore machine equivalent to the Mealy machine is constructed.

The following examples ( Examples 3.23 and 3.24 ) describe the process.

Example 3.23

Convert the following Mealy machine to an equivalent Moore machine as given in Fig. 3.40.

Fig. 3.40

Fig. 3.40

Solution: For state q 0 , there are two incoming states, q 0 to q 0 with label a/0 and q 2 to q 0 with label b/1. Two incoming edges are labelled with two different outputs 0 and 1. So, the state q 0 needs to be divided into two states as q 00 and q 01 . A loop for input ‘a’ on q 00 is constructed. A transition is made from q 01 to q 00 with input label ‘a’. From both the states, transitions are made to the state q 1 with label b/1. The modified machine is given in Fig. 3.41.

Fig. 3.41

Fig. 3.41

For all the other states q 1 and q 2 the outputs for all the incoming edges are 1 and 0 respectively. So there is no need to divide the states. The final Moore machine is as given in Fig. 3.42.

Fig. 3.42

Fig. 3.42

Example 3.24

Convert the following Mealy machine as given in Fig. 3.43 to an equivalent Moore machine.

Fig. 3.43

Fig. 3.43

Solution: The machine contains four states. Let us start from the state q 1 . The incoming edges to this state are from q 2 to q 1 with label 0/1 and from q 3 to q 1 with label 1/1. There is no difference in the outputs of the incoming edges to this state and, therefore, in the constructing Moore machine, the output for this state is 1. The modified machine is as shown in Fig. 3.44.

Fig. 3.44

Fig. 3.44

Consider the state q 2 . This state contains two incoming edges: from q 1 to q 2 with label 1/0 and q 3 to q 2 with label 0/1. We get two different outputs for the two incoming edges (q 1 to q 2 output 0, q 3 to q 2 output 1). So, the state q 2 is divided into two, namely, q 20 and q 21 . The outgoing edges are duplicated for both the states generated from q 2 as shown in Fig. 3.45.

Fig. 3.45

Fig. 3.45

Consider the state q 3 . The incoming edges to this state are from q 1 to q 3 with label 0/0 and from q 4 to q 3 with label 1/0. There is no difference in the outputs of the incoming edges to this state and, therefore, in the constructing Moore machine, the output for this state is 0. The modified machine is given in Fig. 3.46.

Fig. 3.46

Fig. 3.46

Consider the state q 4 . This state contains three incoming edges, from q 20 to q 4 with label 1/0, from q 21 to q 4 with label 1/0, and from and q 4 to q 4 with label 0/1. We get two different outputs for the three incoming edges (q 20 to q 4 output 0, q 21 to q 4 output 0, and q 4 to q 4 output 1). So, the state q 4 will be divided into two, namely, q 40 and q 41 .

The modified Moore machine is given in Fig. 3.47.

Fig. 3.47

Fig. 3.47

3.14  Minimization of Finite Automata

The language (regular expression) produced by a DFA is always unique. But the reverse, i.e., a language produces a unique DFA, is not true. For this reason, there may be different DFAs in a given language. By minimizing, we can get a minimized DFA with minimum number of states and transitions which produces that particular language. The DFA determines how computers manipulate regular languages (expressions). The DFA size determines the space/time efficiency. So, a DFA with minimized states needs less time to manipulate a regular expression.

Before describing the process, we need to know the definitions of dead state, inaccessible state, equivalent state, distinguishable state, and k-equivalence in relation with finite automata.

  • Dead State: A state q i is called a dead state if q i is not a final state and for all the inputs to this state, the transitions are confined to that state. In mathematical notation, we can denote q i ∉ F and δ(q i , Σ) → qi.
  • Inaccessible State: The states which can never be reached from the initial state are called inaccessible states.

Here, q d is a dead state and q a is an inaccessible state as shown in Fig. 3.48.

Fig. 3.48

Fig. 3.48

  • Equivalent state: Two states q i and q j of a finite automata M are called equivalent if both δ(q i , x) and δ(q j , x) produce final states or both of them produce non-final states for all x ε Σ*. It is denoted by q i ≡ q j .
  • Distinguishable state: Two states q i and q j of a finite automata M are called distinguishable if, for a minimum length string x, for δ(q i , x) and δ(q j , x), one produces final state and another produces non-final state or vice versa for all x ε Σ*.
  • K-equivalent: Two states q i and q j of a finite automata M are called k-equivalent (k > = 0) if both δ(q i , x) and δ(q j , x) produce final states or both of them produce non-final states for all x ∈ Σ* of length k or less.

3.14.1  Process of Minimizing

  1. All the states are ‘0’ equivalent. Mark this as S 0 .
  2. Divide the set of states into two subsets: set of final states and set of non-final states. Mark this as S 1 .
  3. Apply all the inputs separately on the two subsets and find the next state combinations. If it happens that, for applying input on one set of states, the next states belong to different subsets, then separate the states which produce next states belonging to different subsets.
  4. Continue step (3) for n + 1 times.
  5. If S n and S n + 1 are the same, then stop and declare S n as an equivalent partition.
  6. Mark each subset of S n as a different state and construct the transitional table accordingly. This is the minimum automata.

Consider the following examples to make the minimization process clear.

Example 3.25

Construct a minimum state automaton from the transitional table given below.

image

Solution: In the finite automata, the states are {q 0 , q 1 , q 2 , q 3 , q 4 , q 5 }. Name this set as S 0 .

S 0 : {q 0 , q 1 , q 2 , q 3 , q 4 , q 5 }

All of the states are 0 equivalents.

In the finite automata, there are two types of states: final state and non-final states. So, divide the set of states into two parts, Q 1 and Q 2 .

image

The states belonging to the same subset are 1-equivalent because they are in the same set for string length 1. The states belonging to different subsets are 1-distinguishable.

For input 0 and 1, q 0 goes to q 1 and q 2 , respectively. Both of the states belong to the same subset. For q 1 and q 2 with input 0 and 1, the next states are q 2 , q 3 and q 2 , q 4 , respectively. For both of the states, for input 0, the next state belongs to one subset, and for input 1, the next state belongs to another subset. So, q 0 can be distinguished from q 1 and q 2 .

The next states with input 0 and 1 for states q 3 , q 4 , and q 5 belong to the same subset. So, they cannot be divided.

S 2 : {{q 0 }, {q 1 , q 2 }, {q 3 , q 4 , q 5 }}

q 0 is the single state in the subset. So, it cannot be divided.

For states q 1 and q 2 with input 0 and 1, for both of the cases, one state belongs to one subset and another state belongs to another subset. So, they cannot be divided.

The next states with input 0 and 1 for states q 3 , q 4 , and q 5 belong to the same subset. So, they cannot be divided.

So, in the next step,

S 3 : {{q 0 }, {q 1 , q 2 }, {q 3 , q 4 , q 5 }}

S 2 and S 3 are equivalent.

As step (n–1) and step n are the same, there is no need of further advancement.

In the minimized automata, the number of states is 3.

The minimized finite automata is presented in tabular format as follows:

State
Next State
I/P = 0
I/P = 1
{q 0 }
{q 1 }
{q 2 }
{q 1 , q 2 }
{q 2 }
{q 3 , q 4 }
{q 3 , q 4 , q 5 }
{q 3 , q 4 , q 5 }
{q 3 , q 4 , q 5 }

But {q 1 }, {q 2 }, and {q 3 , q 4 } do not exist under the column of present state. They are not states of the minimized finite automata, but they are subset of the states. In the next state columns, by replacing the subsets by proper state, the modified table becomes

State
Next State
I/P = 0
I/P = 1
{q 0 }
{q 1 , q 2 }
{q 1 , q 2 }
{q 1 , q 2 }
{q 1 , q 2 }
{q 3 , q 4 , q 5 }
{q 3 , q 4 , q 5 }
{q 3 , q 4 , q 5 }
{q 3 , q 4 , q 5 }

As q 0 is the beginning state of the original finite automata, {q 0 } will be the beginning state of minimized finite automata. As q 3 , q 4 , and q 5 are the final states of the original finite automata, the set of the states containing any of the states as element is final state. Here, all the states are contained in a single set {q 3 , q 4 , q 5 } and, therefore, it is the final state. By replacing {q 0 } as A, {q 1 , q 2 } as B, and {q 3 , q 4 , q 5 } as C, the modified minimized finite automata becomes

image

The transitional diagram of the minimized finite automata is given in Fig. 3.49.

Fig. 3.49

Fig. 3.49

Example 3.26

Construct a minimum state automaton from the following transitional table.

Present State
Next State
I/P = 0
I/P = 1
A
F
B
B
C
G
C
C
A
D
G
C
E
F
H
F
G
C
G
E
G
H
C
G

A is initial state and C is final state

Solution: In the Finite automata, the states are {A, B, C, D, E, F, G, H}. Name this set as S 0 .

S 0 : {A, B, C, D, E, F, G, H}

All of the states are 0 equivalents.

In the finite automata, there are two types of states: final state and non-final state. The set of states is divided into two parts, namely, Q 1 and Q 2 .

Q1 = {C} Q2 = {A, B, D, E, F, G, H}

S1: {{C} {A, B, D, E, F, G, H}}

The states belonging to the same subset are 1-equivalent because they are in the same set for string length 1. The states belonging to different subsets are 1-distinguishable.

C is a single state, and so it cannot be divided. Among the states {A, B, D, E, F, G, H} for {B, D, F, H}, for an input of either 0 or 1, the next state belongs to {C} which is a different subset (from B with input 0 goes to C, from D with input 1 goes to C, from F with input 1 goes to C, and from H with input 0 goes to C).

For the other states {A, E, G}, for an input of either 0 or 1, the next state belongs to Q 2 .

This divides Q 2 into two parts: {A, E, G} and {B, D, F, H}. Let us name them as Q 3 and Q 4 .

The divided sets are

S 2 : {{C}, {A, E, G}, {B, D, F, H}}.

Consider the subset of states {A, E, G}. A and E with input 0 and 1 both go to F, B and F, H, respectively, i.e., to the subset {B, D, F, H}. G with input 0 and 1 goes to E, G, i.e., the same subset. Here, {A, E, G} is divided into two subsets: {A, E} and {G}.

The subset {B, D, F, H} can be divided depending on the input and the next state combination. B and H produce the next states C and G for input 0 and 1, respectively.

D and F produce the next states G and C for input 0 and 1, respectively. So, the set {B, D, F, G} is divided into two subsets: {B, H} and {D, F}.

The divided sets are

S 3 : {{C}, {A, E}, {G}, {B, H}, {D, F}}.

The subsets cannot be divided further making these as the states of minimized DFA. Let us rename the subsets as q 0 , q 1 , q 2 , q 3 , and q 4 . The initial state was A, and so here the initial state is {A, E}, i.e., q 1 . The final state was C, and so here the final state is {C}, i.e., q 0 . The tabular representation of minimized DFA is

image

3.15  Myhill–Nerode Theorem

John Myhill and Anil Nerode of the University of Chicago proposed a theorem in 1958 which provides a necessary and sufficient condition for a language to be regular. This theorem can also be used to minimize a DFA. But before going into the details of the theorem statement, we need to know some definitions related to the theorem.

3.15.1  Equivalence Relation

  • A relation R in set S is reflexive if xRx for every x in S.
  • A relation R in set S is symmetric if for x, y in S, yRx whenever xRy.
  • A relation R in set S is transitive if for x, y, and z in S, xRz whenever xRy and yRz.

A relation R in set S is called an equivalence relation if it is reflexive, symmetric, and transitive.

3.15.1.1  Right Invariant

An equivalence relation R on strings of symbols from some alphabet Σ is said to be right invariant if for all x, y ∈ Σ* with xRy and all w ∈ Σ* we have that xw R yw. This definition states that an equivalence relation has the right invariant property if two equivalent strings (x and y) that are in the language still are equivalent if a third string (w) is appended to the right of both of them.

3.15.2  Statement of the Myhill–Nerode Theorem

The Myhill–Nerode theorem states that the following three statements are equivalent.

  1. The set L, a subset of Σ*, is accepted by a DFA, i.e., L is a regular language.
  2. There is a right-invariant equivalence relation R of finite index such that L is the union of some of the equivalence classes of R.
  3. Let equivalence relation R L be defined as xR L y, if and only if for all z in Σ*, xz is in L exactly when yz is in L then R L is of finite index.

3.15.3  Myhill–Nerode Theorem in Minimizing a DFA

Step I: Build a two-dimensional matrix labelled by the states of the given DFA at the left and bottom side. The major diagonal and the upper triangular parts are shown as dashes.

Step II: One of the three symbols, X, x, or 0 are put in the locations where there is no dash.

  1. Mark X at p, q in the lower triangular part such that p is the final state and Q is the non-final state.

  2. Make distinguished pair combination of the non-final states. If there are n number of non-final states, there are nC 2 number of distinguished pairs.

    Take a pair (p, q) and find (r, s), such that r = δ(p, a) and s = δ(q, a). If in the place of (r, s) there is X or x, in the place of (p, q), there will be x.

  3. If (r, s) is neither X nor x, then (p, q) is 0.

  4. Repeat (2) and (3) for final states also.

Step III: The combination of states where there is 0, they are the states of the minimized machine.

Consider the following examples to get the earlier discussed method.

Example 3.27

Minimize the following DFA using the Myhill–Nerode theorem.

image

Here C, D, F, G are final states.

Solution:

Step I: Divide the states of the DFA into two subsets: final (F) and non-final (Q–F).

F = {C, D, F, G}, Q–F = {A, B, E, H, I}

Make a two-dimensional matrix as shown in Fig. 3.50 labelled at the left and bottom by the states of the DFA.

Fig. 3.50

Fig. 3.50

Step II:

  1. The following combinations are the combination of the beginning and final state.

    (A, C), (A, D), (A, F), (A, G), (B, C), (B, D), (B, F), (B, G), (E, C), (E, D), (E, F), (E, G), (H, C), (H, D), (H, F), (H, G), (I, C), (I, D), (I, F), (I, G).

    Put X in these combinations of states. The modified matrix is given in Fig. 3.51.

    Fig. 3.51

    Fig. 3.51

  2. The pair combination of non-final states are (A, B), (A, E), (A, H), (A, I), (B, E), (B, H), (B, I), (E, H), (E, I), and (H, I).

    r = δ(A, a) → B s = δ(B, a) → C

    in the place of (B, C) there is X. So, in the place of (A, B), there will be x.

    Similarly,

    Equation

  3. The pair combination of final states are (C, D), (C, F), (C, G), (D, F), (D, G), and (F, G).

    Equation

    The modified matrix becomes as shown in Fig. 3.52.

    Fig. 3.52

    Fig. 3.52

    The combination of entries 0 are the states of the modified machine. The states of the minimized machine are [A], [B, E], [C, D], [C, F], [C, G], [D, F], [D, G], [F, G], and [H, I].

    For the minimized machine M′

    Q′ = ({A}, {B, E}, {C, D, F, G}, {H, I}). [C, D], [C, F], [C, G], [D, F], [D, G], and [F, G] are combined to a new state [CDFG].

    Σ = {a, b} δ′: (given in the following table)

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>a</div></th><th><div>b</div></th></tr><tr><td><div>{A}</div></td><td><div>{B, E}</div></td><td><div>{B, E}</div></td></tr><tr><td><div>{B, E}</div></td><td><div>{C, D, F, G}</div></td><td><div>{C, D, F, G}</div></td></tr><tr><td><div>{C, D, F, G}</div></td><td><div>{H, I}</div></td><td><div>{H, I}</div></td></tr><tr><td><div>{H, I}</div></td><td><div>{H, I}</div></td><td><div>{H, I}</div></td></tr></tbody></table>

q′ 0 : {A}

F′ : {C, D, F, G}

Example 3.28

Minimize the following finite automata by the Myhill–Nerode theorem.

image

Here F, G, H are final states.

Solution:

Step I: Divide the states of the DFA into two subsets: final (F) and non-final (Q–F).

F = {E, F, G}, Q–F = {A, B, C, D}

Make a two-dimensional matrix ( Fig. 3.53 ) labelled at the left and bottom by the states of the DFA.

Fig. 3.53

Fig. 3.53

Step II:

  1. The following combinations are the combination of the beginning and final states.

    (A, E), (A, F), (A, G), (B, E), (B, F), (B, G), (C, E), (C, F), (C, G), (D, E), (D, F), (D, G) Put X in these combinations of states. The modified matrix is given in Fig. 3.54.

    Fig. 3.54

    Fig. 3.54

  2. The pair combination of non-final states are (A, B), (A, C), (A, D), (A, E), (B, C), (B, D), (B, E), (C, D), (C, E), and (D, E).

    r = δ(A, a) → B s = δ(B, a) → A, in the place of (A, B), there is neither X nor x. So, in the place of (A, B), there will be 0.

    Similarly,

    Equation

  3. The pair of combinations of final states are (F, G), (F, H), and (G, H).

    Equation

    The modified table is given in Fig. 3.55.

    Fig. 3.55

    Fig. 3.55

    The combination of entries 0 are the states of the modified machine. The states of the minimized machine are (A, B), (A, E), (B, E), (C, D), (G, H), i.e., (A, B, E), (C, D), (G, H), and (F ) (As F is a final state of the machine, it is left in the state combinations).

    (A, B, E) for input ‘a’ gives the output (A, B, A) and for input ‘b’ gives the output (F, F, G), where (F, F) belongs to one set and (G) belongs to another set. So, it will be divided into (A, B), (E).

    The states of the minimized machines are (A, B),(E), (C, D), (G, H), and (F). Let us name them as S 1 , S 2 , S 3 , S 4 , and S 5 .

    For the minimized machine M′,

    image

    State Table (transitional function δ)

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>a</div></th><th><div>b</div></th></tr><tr><td><div>S <sub>1</sub></div></td><td><div>S <sub>1</sub></div></td><td><div>S <sub>5</sub></div></td></tr><tr><td><div>S <sub>2</sub></div></td><td><div>S <sub>1</sub></div></td><td><div>S <sub>4</sub></div></td></tr><tr><td><div>S <sub>3</sub></div></td><td><div>S <sub>4</sub></div></td><td><div>S <sub>1</sub></div></td></tr><tr><td><div>S <sub>4</sub></div></td><td><div>S <sub>1</sub></div></td><td><div>S <sub>3</sub></div></td></tr><tr><td><div>S <sub>5</sub></div></td><td><div>S <sub>4</sub></div></td><td><div>S <sub>3</sub></div></td></tr></tbody></table>

3.16  Two-way Finite Automata

Till now, we have studied automata where the reading head moves only in one direction, from left to right.

Two-way finite automata are machines which can traverse (read) an input string in both directions (left and right).

A two-way DFA (2DFA) consists of five touples M = {Q, Σ, δ, q 0 , F} where Q, Σ, q 0 , and F are defined like one-way DFA, but here the transitional function δ is a map from Q × Σ to Q × (L, R). L means left and R means right. Block diagram of a two-way finite automata is shown in Fig. 3.56.

Fig. 3.56

Fig. 3.56 Two-way Finite Automata

Consider the following example of a two-way DFA; M is given in the following table.

image

Let us give a string 101001 to check whether it is accepted by the 2DFA or not.

(A, 101001) → (B, 01001R) → (B, 1001R) → (C, 01001L) → (A, 1001R) → (B, 001R) → (B, 01R) → (B, 1R) → (C, 01L) → (A, 1R) → B

We have reached the final state, and the string is finished. So, the string 101001 is accepted by the 2DFA.

3.17  Applications of Finite Automata

Finite automata can be applied in different fields of computer science and in different engineering fields. Some of them are spelling checkers and advisers, multilanguage dictionaries, minimal perfect hashing, and text compression. Perhaps, the most traditional application is found in compiler construction where such automata can be used to model and implement efficient lexical analysers.

A typical example is given in Fig. 3.57 (transitional diagram for relational operators in C).

Fig. 3.57 Transitional Diagram for Relational Operators in C.

Fig. 3.57

( Source: “Compilers: Principles, Techniques and tools” Aho, Sethi, Ullman, Pearson Education.)

3.18  Limitations of Finite Automata

An FA is a finite state machine without considering the output. Thus, it has finite number of states. So, it cannot perform operations where infinite amount of memory is needed. As an example, let us check a string in the form a n b n , where n > 0. As n is a positive integer from 0 to any number, it is not possible to design a general finite automata for checking a string in the form a n b n . It is possible to design separate finite automata for ab, a 2 b 2 , a 3 b 3 . . . , but general finite automata for a n b n is not possible.

What We Have Learned So Far

  1. An FA has a finite number of states.
  2. An FA has five characteristics: (i) input, (ii), state, (iii) state transition, (iv) output, and (v) output relation.
  3. Finite automata M is represented as M = {Q, Σ, δ, q 0 , F}.
  4. A string is declared accepted by an FA if the string is finished and the machine has reached a final state.
  5. Finite automata can be of two types (i) deterministic finite automata (DFA) and (ii) non-deterministic finite automata (NDFA).
  6. For a DFA, for all cases for a single input given to a single state, the machine goes to a single state, i.e., Q × Σ → Q.
  7. For an NFA, for some cases for a single input given to a single state, the machine goes to more than one states, i.e., Q × Σ → 2 Q , where 2 Q is the power set of Q.
  8. NFA can be converted to an equivalent DFA.
  9. An FA is called an NFA with null move if there exists a null transaction, i.e., Q × ε → Q.
  10. A dead state is a state where the control can enter and be confined till the input ended, but there is no way to come out from that state.
  11. In a Mealy machine, the output depends on the present state and the present input.
  12. In a Moore machine, the output depends only on the present state.
  13. The Myhill–Nerode theorem is used to minimize finite automata.
  14. Two-way finite automata are machines which can traverse (read) an input string in both directions (left and right).
  15. Finite automata are used in designing lexical analysers.

Solved Problems

  1. Test whether the following strings are accepted by the following finite automata or not: (i) 0001101, (ii) 00000, (iii) 01010.

    image

    Solution:

    1. image

      As q 3 is the final state, the string is accepted by the given finite automata.

    2. image

      As q 1 is the non-final state, the string is not accepted by the given finite automata.

    3. image

      As q 0 is a non-final state, the string is not accepted by the given finite automata.

  2. Test whether the following strings are accepted by the following finite automata or not: (i) 0111100, (ii) 11111, (iii) 11010.

    image

    Solution:

    1. image

      As q 2 is the final state, the string is accepted by the given finite automata.

    2. image

      As q 3 is a non-final state, the string is not accepted by the FA.

    3. image

      As q 1 is a non-final state, the string is not accepted by the given finite automata.

  3. Test whether the string 10010 is accepted by the following NFA or not.

    image

    Solution:

    image

    For the string 10010, we get the terminal state as D which is a final state for two cases. Therefore, the string is accepted by the NFA.

  4. Convert the following NFA into an equivalent DFA.

    image

    Solution:

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>a = 0</div></th><th><div>a = 1</div></th></tr><tr><td><div>[q <sub>0</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>2</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>2</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> , q <sub>3</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> , q <sub>3</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>2</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> , q <sub>3</sub> ]</div></td></tr></tbody></table>

    For simplification, let us replace [q 0 ] by A, [q 0 , q 1 ] by B, [q 0 , q 2 ] by C, [q 0 , q 1 , q 3 ] by D, and [q 0 , q 2 , q 3 ] by E. Here, A is the initial state, and D and E are the final states as they contain the state q 3 .

    The simplified DFA is

    image

  5. Design an equivalent DFA corresponding to the following NFA.

    [WBUT 2005]

    image

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>0</div></th><th><div>1</div></th></tr><tr><td><div>q <sub>0</sub></div></td><td><div>{q <sub>0</sub> , q <sub>3</sub> }</div></td><td><div>{q <sub>0</sub> , q <sub>1</sub> }</div></td></tr><tr><td><div>q <sub>1</sub></div></td><td><div>Φ</div></td><td><div>q <sub>2</sub></div></td></tr><tr><td><div>q <sub>2</sub></div></td><td><div>q <sub>2</sub></div></td><td><div>q <sub>2</sub></div></td></tr><tr><td><div>q <sub>3</sub></div></td><td><div>q <sub>4</sub></div></td><td><div>Φ</div></td></tr><tr><td><div>q <sub>4</sub></div></td><td><div>q <sub>4</sub></div></td><td><div>q <sub>4</sub></div></td></tr></tbody></table>

    Solution:

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>0</div></th><th><div>1</div></th></tr><tr><td><div>[q <sub>0</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>3</sub> , q <sub>4</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>3</sub> , q <sub>4</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>3</sub> , q <sub>4</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>4</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>4</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>3</sub> , q <sub>4</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>4</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>3</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td></tr></tbody></table>

    For simplification, let us replace [q 0 ] by A, [q 0 , q 3 ] by B, [q 0 , q 3 , q 4 ] by C, [q 0 , q 1 , q 4 ] by D, and [q 0 , q 1 ] by E. Here, A is the initial state, and C and D are the final states as they contain the state q 4 . The simplified DFA is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>0</div></th><th><div>1</div></th></tr><tr><td><div>A</div></td><td><div>B</div></td><td><div>E</div></td></tr><tr><td><div>B</div></td><td><div>C</div></td><td><div>E</div></td></tr><tr><td><div>C</div></td><td><div>C</div></td><td><div>D</div></td></tr><tr><td><div>D</div></td><td><div>C</div></td><td><div>D</div></td></tr><tr><td><div>E</div></td><td><div>B</div></td><td><div>E</div></td></tr></tbody></table>

  6. Convert the following NFA to an equivalent DFA.

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Σ</div></th><th><div>0</div></th><th><div>1</div></th></tr><tr><th><div>States</div></th></tr><tr><td><div>q <sub>0</sub></div></td><td><div>q <sub>0</sub></div></td><td><div>q <sub>0</sub> , q <sub>1</sub></div></td></tr><tr><td><div>q <sub>1</sub></div></td><td><div>q <sub>2</sub></div></td><td><div>q <sub>2</sub></div></td></tr><tr><td><div>q <sub>2</sub></div></td><td><div>−</div></td><td><div>q <sub>2</sub></div></td></tr></tbody></table>

    (q 0 is the initial state and q 1 is the final state)

    Solution: Conversion is done in the following ways:

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Σ</div></th><th><div>0</div></th><th><div>1</div></th></tr><tr><th><div>States</div></th></tr><tr><td><div>[q <sub>0</sub> ]</div></td><td><div>[q <sub>0</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>1</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>2</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>2</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>2</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>2</sub> ]</div></td></tr><tr><td><div>[q <sub>0</sub> , q <sub>2</sub> ]</div></td><td><div>[q <sub>0</sub> ]</div></td><td><div>[q <sub>0</sub> , q <sub>1</sub> , q <sub>2</sub> ]</div></td></tr></tbody></table>

    Rename [q 0 ] as A, [q 0 , q 1 ] as B, [q 0 , q 1 , q 2 ] as C, and [q 0 , q 2 ] as D. The beginning state is A, and final states are B and C.

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Σ</div></th><th><div>0</div></th><th><div>1</div></th></tr><tr><th><div>States</div></th></tr><tr><td><div>A</div></td><td><div>A</div></td><td><div>B</div></td></tr><tr><td><div>B</div></td><td><div>D</div></td><td><div>C</div></td></tr><tr><td><div>C</div></td><td><div>D</div></td><td><div>C</div></td></tr><tr><td><div>D</div></td><td><div>A</div></td><td><div>C</div></td></tr></tbody></table>

  7. Convert the following NFA to an equivalent DFA.

    [UPTU 2005]

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Σ</div></th><th><div>0</div></th><th><div>1</div></th></tr><tr><th><div>States</div></th></tr><tr><td><div>p</div></td><td><div>{q, s}</div></td><td><div>{q}</div></td></tr><tr><td><div>q</div></td><td><div>{r}</div></td><td><div>{q, r}</div></td></tr><tr><td><div>r</div></td><td><div>{s}</div></td><td><div>{p}</div></td></tr><tr><td><div>s</div></td><td><div>Ø</div></td><td><div>{p}</div></td></tr></tbody></table>

    where p is the initial state and q and s are the final states.

    Solution:

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Σ</div></th><th><div>0</div></th><th><div>1</div></th></tr><tr><th><div>States</div></th></tr><tr><td><div>{p}</div></td><td><div>{q, s}</div></td><td><div>{q}</div></td></tr><tr><td><div>{q}</div></td><td><div>{r}</div></td><td><div>{q, r}</div></td></tr><tr><td><div>{r}</div></td><td><div>{s}</div></td><td><div>{p}</div></td></tr><tr><td><div>{s}</div></td><td><div>Ø</div></td><td><div>{p}</div></td></tr><tr><td><div>{q, r}</div></td><td><div>{r, s}</div></td><td><div>{p, q, r}</div></td></tr><tr><td><div>{r, s}</div></td><td><div>{s}</div></td><td><div>{p}</div></td></tr><tr><td><div>{p, q, r}</div></td><td><div>{q, r, s}</div></td><td><div>{p, q, r}</div></td></tr><tr><td><div>{q, r, s}</div></td><td><div>{r, s}</div></td><td><div>{p, q, r}</div></td></tr><tr><td><div>{q, s}</div></td><td><div>{r}</div></td><td><div>{p, q, r}</div></td></tr><tr><td><div>{Ø}</div></td><td><div>{Ø}</div></td><td><div>{Ø}</div></td></tr></tbody></table>

    Here {p} is the beginning state and {q}, {s}, {q, r}, {r, s}, {p, q, r}, {q, r, s}, and {q, s} are the final states. { image } is the dead state.

  8. Construct a DFA equivalent to the following NDFA given in the following figure.

    [UPTU 2004]

    image

    Solution: The tabular representation of the NDFA is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>0</div></th><th><div>1</div></th></tr><tr><td><div>q <sub>0</sub></div></td><td><div>q <sub>3</sub></div></td><td><div>{q <sub>0</sub> , q <sub>1</sub> }</div></td></tr><tr><td><div>q <sub>1</sub></div></td><td><div>Φ</div></td><td><div>q <sub>2</sub></div></td></tr><tr><td><div>q <sub>2</sub></div></td><td><div>q <sub>2</sub></div></td><td><div>{q <sub>2</sub> , q <sub>4</sub> }</div></td></tr><tr><td><div>q <sub>3</sub></div></td><td><div>q <sub>4</sub></div></td><td><div>Φ</div></td></tr><tr><td><div>q <sub>4</sub></div></td><td><div>q <sub>4</sub></div></td><td><div>q <sub>4</sub></div></td></tr></tbody></table>

    (q 0 is the initial state and q 4 is the final state)

    The corresponding DFA is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>0</div></th><th><div>1</div></th></tr><tr><td><div>{q <sub>0</sub> }</div></td><td><div>{q <sub>3</sub> }</div></td><td><div>{q <sub>0</sub> , q <sub>1</sub> }</div></td></tr><tr><td><div>{q <sub>3</sub> }</div></td><td><div>{q <sub>4</sub> }</div></td><td><div>{Φ}</div></td></tr><tr><td><div>{q <sub>4</sub> }</div></td><td><div>{q <sub>4</sub> }</div></td><td><div>{q <sub>4</sub> }</div></td></tr><tr><td><div>{q <sub>0</sub> , q <sub>1</sub> }</div></td><td><div>{q <sub>2</sub> }</div></td><td><div>{q <sub>2</sub> , q <sub>4</sub> }</div></td></tr><tr><td><div>{q <sub>2</sub> }</div></td><td><div>{q <sub>2</sub> }</div></td><td><div>{q <sub>2</sub> , q <sub>4</sub> }</div></td></tr><tr><td><div>{q <sub>2</sub> , q <sub>4</sub> }</div></td><td><div>{q <sub>2</sub> , q <sub>4</sub> }</div></td><td><div>{q <sub>2</sub> , q <sub>4</sub> }</div></td></tr><tr><td><div>{Φ}</div></td><td><div>{Φ}</div></td><td><div>{Φ}</div></td></tr></tbody></table>

    Here {q 0 } is the beginning state, and {q 4 }, and {q 2 , q 4 } are the final states.

    (Draw a transitional diagram to complete the answer.)

  9. Find the minimal DFAs for the language L = {a n b m , n ≥ 2, m ≥1}

    [Andhra University 2008]

    Solution: All ‘a’ will appear before ‘b’. There is atleast 2 ‘a’ and 1 ‘b’. The DFA is the following.

    image

  10. Design a DFA for the language L = {0 m 1 n , m ≥ 0, n ≥1}

    [JNTU 2007]

    Solution: All ‘0’s will appear before ‘1’. There is at least one ‘1’, but the number of ‘0’s may be zero. The DFA is shown in Fig. 3.58.

    Fig. 3.58

    Fig. 3.58

  11. Construct a DFA which accepts the set of all binary strings that, interpreted as the binary representation of an unsigned decimal integer, is divisible by 5.

    [WBUT 2008]

    Solution: For Mod 5, the remainders are 0, 1, 2, 3, and 4. We can assign the states as q 0 , q 1 , q 2 , q 3 , and q 4 .

    For any binary string, if we add a bit at LSB, then the previous value becomes doubled. (Let the string be 101. The decimal value is 5. If we add another 1 at LSB, the string becomes 1011. The decimal value of the previous 101 becomes 10.)

    In general, we can write that ‘n’ becomes 2n + b, where n is the previous number and b is the added bit.

    (2n + b) mod 5 = 2n mod 5 + b mod 5

    As b is either 0 or 1, b mod 5 = b.

    2n mod 5 is any one of 0, 1, 2, 3, or 4, i.e., 2 X (state number) + a.

    For this machine, the input alphabets are 0 and 1.

    image

    The transitional diagram is

    image

  12. Convert the following NFA with ε move to an equivalent DFA.

    image

    Solution: In the given automata, there are two ε moves: from q 0 to q 1 and from q 1 to q 2 . If we want to remove the first ε move, from q 0 to q 1 , then we have to find all the edges starting from q 1 . The edges are q 1 to q 1 for input a and q 1 to q 2 for input ε.

    Duplicate all these transitions starting from the state q 0 , keeping the edge label the same. q 0 is the initial state, and so make q 1 also an initial state. q 1 is the final state, and so make q 0 as the final state The modified transitional diagram will be

    image

    Again, there are two ε moves, from q 0 to q 2 and from q 1 to q 2 . If we want to remove the null transition from q 0 to q 2 , we have to find all the edges starting from q 2 . The edges are q 2 to q 0 for input b. Duplicate this transition starting from the state q 0 , keeping the edge label the same. The modified transitional diagram will be as follows. (As in q 0 there is a loop with label b, we need not make another loop with the same label).

    image

    If we want to remove the null transition from q 1 to q 2 , we have to find all the edges starting from q 2 . The edges are q 2 to q 0 for input b. Duplicate this transition starting from the state q 1 , keeping the edge label the same. q 1 is the initial state, and so make q 2 also an initial state. The modified transitional diagram will be

    image

  13. Convert the following Moore machine to an equivalent Mealy machine by the tabular format.

    image

    Solution: The equivalent Mealy machine is

    image

  14. Convert the following Moore machine to an equivalent Mealy machine by the tabular format.

    image

    Solution: The equivalent Mealy machine is

    image

  15. Convert the following Mealy machine to an equivalent Moore machine by the tabular format.

    image

    Solution: In the next state column of the given Mealy machine, the output differs for q 1 and q 3 as the next states. So, the states will be divided as q 10 , q 11 and q 30 , q 31 , respectively. After dividing the states, the modified Mealy machine becomes

    image

    The converted Moore machine is

    image

    image

    To get rid of the problem of occurrence of a null string, we need to include another state, q a , with the same transactions as that of q 0 but with output 0.

    The modified final Moore machine equivalent to the given Mealy machine is

    image

  16. Convert the following Mealy machine to an equivalent Moore machine by the tabular format.

    image

    Solution: In the next state column of the given Mealy machine, the output differs for q 1 and q 2 as the next states. So, the states will be divided as q 10 , q 11 and q 20 , q 21 , respectively. After dividing the states, the modified Mealy machine will be

    image

    image

    The converted Moore machine is

    image

    To get rid of the problem of occurrence of a null string, we need to include another state, q a , with the same transactions as that of q 0 but with output 0.

    The modified final Moore machine equivalent to the given Mealy machine is

    image

  17. Convert the following Mealy Machine to a Moore Machine.

    [WBUT 2008]

    image

    Solution: Q 3 and Q 4 as next states produce outputs 0 and 1, and so the states are divided into Q 30 , Q 31 and Q 40 , Q 41 . Thus, the constructing Moore machine contains six states. The Moore machine becomes

    image

  18. From the following Mealy machine, find the equivalent Moore machine. Check whether the Mealy machine is a minimal one or not. Give proper justification to your answer.

    [WBUT 2007]

    image

    Solution:

    1. In the Mealy machine, S 1 as the next state produces output 0 for some cases and produces output 1 for one case. For this reason, the state S 1 is divided into two parts: S 10 and S 11 . All the other states produce output 0.

      To get rid of the problem of occurrence of a null string, we need to include another state, S a , with the same transactions as that of S 10 but with output 0.

      The modified final Moore machine equivalent to the given Mealy machine will be as follows.

      The converted Moore machine is

      image

    2. All the states are 0 equivalents.

      P 0 = {S 1 S 2 S 3 S 4 S 5 }

      For string length 1, all the states produce output 0 except S 5 .

      P 1 = {S 1 S 2 S 3 S 4 } {S 5 }

      The next states of all the states (belong to the first subset) for all inputs belong to one set except S 4 . The modified partition is

      P 2 = {S 1 S 2 S 3 } {S 4 } {S 5 }

      By this process, P 3 = {S 1 S 2 } {S 3 } {S 4 } {S 5 }

      P 4 = {S 1 } {S 2 } {S 3 } {S 4 } {S 5 }

      The machine is a reduced machine as the number of subsets of the machine is the same as the number of states of the original Mealy machine. Hence, the machine is a minimal machine.

  19. Convert the following Moore machine into an equivalent Mealy machine by the transitional format.

    image

    Solution:

    1. In this machine, A is the beginning state. So start from A. For A, there are three incoming arcs, from A to A with input b, one in the form of start-state indication with no input, and the last is from D to A with input a. State A is labelled with output 1. As the start-state indication contains no input, it is useless and, therefore, keep it as it is.

      Modify the label of the incoming edge from D to A and from A to A including the output of state A. So, the label of the incoming state will be D to A with label a/1 and A to A with label b/1.

    2. State B is labelled with output 0. The incoming edges to the state B are from A to B with input a and from D to B with input b.

      Modify the labels of the incoming edges including the output of state B. So, the labels of the incoming states will be A to B with label a/0 and from D to B with label b/0.

    3. State C is labelled with output 0. There are two incoming edges to this state, from B to C with input b and from C to C with input a.

      The modified label will be B to C with label b/0 and C to C with label a/0.

    4. State D is labelled with output 1. There are two incoming edges to this state, from B to D with input a and from C to D with input b.

      The modified label will be B to D with label a/1, and C to D with label b/1.

      The converted Mealy machine will be

      image

  20. Convert the following Mealy machine into an equivalent Moore machine by the transitional format.

    image

    Solution: The machine contains four states. Let us start from the state A. The incoming edges to this state are from D to A with label a/0. There is no difference in the outputs of the incoming edges to this state, and so in the constructing Moore machine the output for this state will be 0.

    image

    For the state B, the incoming edges are B to B with label a/1, from A to B with label a/0, and from C to B with label b/1.

    We get two different outputs for two incoming edges (B to B output 1, A to B output 0). So, the state B will be divided into two, namely, B 0 and B 1 . The outgoing edges are duplicated for both the states generated from B. The modified machine is

    image

    For the state A, the incoming edges to this state are from B 0 to C with label b/0 and B 1 to C with label b/0. There is no difference in the outputs of the incoming edges to this state, and so in the constructing Moore machine the output for this state will be 0.

    image

    For the state D, the incoming edges are A to D with label b/0, from C to D with label a/0, and from D to D with label b/1.

    We get two different outputs for two incoming edges (D to D output 1, C to D output 0). So, the state D will be divided into two, namely, D 0 and D 1 . The outgoing edges are duplicated for both the states generated from D. The modified machine is

    image

  21. Convert the following Mealy machine into an equivalent Moore machine.

    [UPTU 2004]

    Solution: The state q 0 has two incoming edges: from q 1 with label a/0 and from q 3 with label b/1. As there is a difference in output, the state q 0 is divided into q 00 and q 01 with outputs 0 and 1, respectively. The states q 1 and q 3 have only one incoming edge each, and so there is no need of division. The state q 2 has three incoming edges; among those, two are of output ‘0’ and another is of output ‘1’. Thus, it is divided into q 20 and q 21 with outputs 0 and 1, respectively.

    image

    From q 1 input with label ‘a’ ends on q 00 , and from q 3 input with label ‘b’ ends on q 01 . The outputs from old q 1 state are duplicated from q 00 and q 01 .

    The state q 1 and q 3 are not divided. q 1 gets output ‘1’ and q 3 gets output ‘0’.

    Dividing the state q 0 and placing q 1 and q 3 , the intermediate machine becomes as follows

    image

    The state q 2 is divided into q 20 and q 21 . From q 00 and q 01 input with label ‘a’ ends on q 21 . From q 3 input with label ‘a’ ends on q 20 . There is a loop on q 2 . That loop will be on q 20 with label ‘b’. Another transition with label ‘b’ is drawn from q 21 to q 20 . The final Moore machine is as follows

    image

  22. Minimize the following finite automata.

    image

    Here F, G, and H are the final states.

    Solution: In the finite automata, the states are {A, B, C, D, E, F, G, H}. Name this set as S 0 .

    S 0 : {A, B, C, D, E, F, G, H}

    All of the states are 0 equivalents.

    In the finite automata, there are two types of states: final state and non-final states. So, divide the set of states into two parts, Q 1 and Q 2 .

    image

    The states belonging to same subset are 1-equivalent because they are in the same set for string length 1. The states belonging to different subsets are 1-distinguishable.

    The next states of F are H and C. The next states of G and H are A, D and A, C, respectively.

    A, D and A, C belong to the same subset but H and C belong to a different subset. So, F, G, and H are divided into {F}, {G, H}.

    For input 0, the next states of A, B, C, D, and E are B, A, G, H, and A, respectively. For input 1, the next states of A, B, C, D, and E are F, F, A, B, and G, respectively. So, the set {A, B, C, D, E} is divided into {A, B, E} and {C, D}.

    S 2 : {{F} {G, H} {A, B, E} {C, D}}

    By the same process, {A, B, E} is divided into {A, B}, {E}.

    image

    The set is not dividable further. So, these are the states of minimized DFA. Let us rename the subsets as q 0 , q 1 , q 2 , q 3 , and q 4 . The initial state was A, and so here the initial state is {A, B}, i.e., q 0 . The final state was F, G, and H, and so here the final states are {F}, i.e., q 3 and {G, H}, i.e., q 4 . The tabular representation of minimized DFA is

    image

  23. Design a Mealy and Moore machine for detecting a sequence 1010 where overlapping sequences are also accepted. Convert the Moore machine that you have got into a Mealy machine. Are there any differences? How will you prove that the two Mealy machines are equivalent?

    Solution: The Mealy machine is

    image

    The Moore machine is

    image

    The converted Mealy machine from the given Moore machine is (by using the transactional format)

    image

    This is surely different from the previously constructed Mealy machine in the number of states and in transactions.

    But these two Mealy machines are equivalent. This can be proved by finding the equivalent partitions of the second machine.

    The tabular format of the previous machine is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State, z</div></th></tr><tr><th><div>x = 0</div></th><th><div>x = 1</div></th></tr><tr><td><div>A</div></td><td><div>A, 0</div></td><td><div>B, 0</div></td></tr><tr><td><div>B</div></td><td><div>C, 0</div></td><td><div>B, 0</div></td></tr><tr><td><div>C</div></td><td><div>A, 0</div></td><td><div>D, 0</div></td></tr><tr><td><div>D</div></td><td><div>E, 1</div></td><td><div>B, 0</div></td></tr><tr><td><div>E</div></td><td><div>A, 0</div></td><td><div>D, 0</div></td></tr></tbody></table>

    P 0 = {A, B, C, D, E}

    P 1 = {A, B, C, E} {D}

    P 2 = {A, B} {C, E} {D}

    P 3 = {A} {B} {C, E} {D}

    P 4 = {A} {B} {C, E} {D}

    Rename the states as S 1 , S 2 , S 3 , and S 4 .

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State, z</div></th></tr><tr><th><div>x = 0</div></th><th><div>x = 1</div></th></tr><tr><td><div>S <sub>1</sub> (A)</div></td><td><div>S <sub>1</sub> , 0</div></td><td><div>S <sub>2</sub> , 0</div></td></tr><tr><td><div>S <sub>2</sub> (B)</div></td><td><div>S <sub>3</sub> , 0</div></td><td><div>S <sub>2</sub> , 0</div></td></tr><tr><td><div>S <sub>3</sub> (C, E)</div></td><td><div>S <sub>1</sub> , 0</div></td><td><div>S <sub>4</sub> , 0</div></td></tr><tr><td><div>S <sub>4</sub> (D)</div></td><td><div>S <sub>3</sub> , 1</div></td><td><div>S <sub>2</sub> , 0</div></td></tr></tbody></table>

    The machine is same as the first Mealy machine.

  24. Minimize the following DFA M using the Myhill–Nerode theorem.

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>I/P = a</div></th><th><div>I/P = b</div></th></tr><tr><td><div>A</div></td><td><div>A</div></td><td><div>D</div></td></tr><tr><td><div>B</div></td><td><div>C</div></td><td><div>F</div></td></tr><tr><td><div>C</div></td><td><div>D</div></td><td><div>E</div></td></tr><tr><td><div>D</div></td><td><div>A</div></td><td><div>F</div></td></tr><tr><td><div>E</div></td><td><div>A</div></td><td><div>G</div></td></tr><tr><td><div>F</div></td><td><div>B</div></td><td><div>E</div></td></tr><tr><td><div>G</div></td><td><div>B</div></td><td><div>D</div></td></tr></tbody></table>

    A is the initial state, and G is the final state.

    [WBUT 2003]

    Solution:

    Step I: Divide the states of the DFA into two subsets: final (F) and non-final (Q–F).

    F = {G}, Q–F = {A, B, C, D, E, F}

    Make a two-dimensional matrix labelled at the left and bottom by the states of the DFA.

    image

    Step II:

    1. The following combinations are the combination of the beginning and final states.

      (A, G), (B, G), (C, G), (D, G), (E, G), (F, G). Put X in these combinations of states.

      The modified matrix is

      image

    2. The pair combination of non-final states are (A, B), (A, C), (A, D), (A, E), (A, F), (B, C), (B, D), (B, E), (B, F), (C, D), (C, E), (C, F), (D, E), (D, F), and (E, F).

      r = δ(A, b) → D s = δ(B, b) → F, in the place of (DF), there is neither X nor x. So, in the place of (A, B), there will be 0.

      Similarly,

      image

      All these processes will result in 0, except (AE), (BE), (CE), (DE) and (EF) (these are x).

      The modified matrix is

      image

      The combination of entries 0 are the states of the modified machine. The states of the minimized machine are [AB], [AC], [AD], [AF], [BC], [BD], [BF], [CD], [CF], and [DF], which are simplified to [ABCDF]. It denotes that the machine is already minimized.

  25. Use the Myhill–Nerode theorem to minimize the following FA:

    image

    Solution: The tabular format of the finite automata is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>i = 0</div></th><th><div>i = 1</div></th></tr><tr><td><div>S <sub>0</sub></div></td><td><div>–</div></td><td><div>S <sub>1</sub></div></td></tr><tr><td><div>S <sub>1</sub></div></td><td><div>S <sub>3</sub></div></td><td><div>S <sub>2</sub></div></td></tr><tr><td><div>S <sub>2</sub></div></td><td><div>S <sub>1</sub></div></td><td><div>–</div></td></tr><tr><td><div>S <sub>3</sub></div></td><td><div>–</div></td><td><div>–</div></td></tr></tbody></table>

    Step I: Divide the states of the DFA into two subsets, final (F) and non-final (Q–F).

    F = {S 3 }, Q–F = {S 0 , S 1 , S 2 }

    Make a two-dimensional matrix labelled at the left and bottom by the states of the DFA.

    image

    Step II:

    1. The following combinations are the combination of the beginning and final states (S 0 , S 3 ), (S 1 , S 3 ), (S 2 , S 3 ).

      Put X in these combinations of states. The modified matrix becomes

      image

      The pair combination of non-final states are (S 0 , S 1 ), (S 0 , S 2 ), (S 1 , S 2 ).

      image

      The modified matrix becomes

      image

      The combination (S 0 , S 2 ) is filled by 0. But another two states S 1 and S 3 are left. The states of the minimized machine are (S 0 , S 2 ), S 1 , S 3 , where the final state is S 3 . The minimized DFA becomes

      <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>i = 0</div></th><th><div>i = 1</div></th></tr><tr><td><div>(S <sub>0</sub> , S <sub>2</sub> )</div></td><td><div>S <sub>1</sub></div></td><td><div>S <sub>1</sub></div></td></tr><tr><td><div>S <sub>1</sub></div></td><td><div>S <sub>3</sub></div></td><td><div>(S <sub>0</sub> , S <sub>2</sub> )</div></td></tr><tr><td><div>S <sub>3</sub></div></td><td><div>–</div></td><td><div>–</div></td></tr></tbody></table>

  26. Prove that the following two FA are equivalent.

    image

    Solution: The second one is an NFA. The tabular representation of the FA is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>i = 0</div></th><th><div>i = 1</div></th></tr><tr><td><div>A</div></td><td><div>A</div></td><td><div>A, B</div></td></tr><tr><td><div>B</div></td><td><div>–</div></td><td><div>C</div></td></tr><tr><td><div>C</div></td><td><div>C</div></td><td><div>C</div></td></tr></tbody></table>

    The DFA from the given NFA is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>i = 0</div></th><th><div>i = 1</div></th></tr><tr><td><div>[A]</div></td><td><div>[A]</div></td><td><div>[A, B]</div></td></tr><tr><td><div>[A, B]</div></td><td><div>[A]</div></td><td><div>[A, B, C]</div></td></tr><tr><td><div>[A, B, C]</div></td><td><div>[A, C]</div></td><td><div>[B, C]</div></td></tr><tr><td><div>[B, C]</div></td><td><div>[B, C]</div></td><td><div>[B, C]</div></td></tr><tr><td><div>[B, C]</div></td><td><div>[A, C]</div></td><td><div>[C]</div></td></tr><tr><td><div>[C]</div></td><td><div>[C]</div></td><td><div>[C]</div></td></tr></tbody></table>

    Simplifying this, the DFA becomes

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>i = 0</div></th><th><div>i = 1</div></th></tr><tr><td><div>S <sub>1</sub></div></td><td><div>S <sub>1</sub></div></td><td><div>S <sub>2</sub></div></td></tr><tr><td><div>S <sub>2</sub></div></td><td><div>S <sub>1</sub></div></td><td><div>S <sub>3</sub></div></td></tr><tr><td><div>S <sub>3</sub></div></td><td><div>S <sub>4</sub></div></td><td><div>S <sub>5</sub></div></td></tr><tr><td><div>S <sub>4</sub></div></td><td><div>S <sub>5</sub></div></td><td><div>S <sub>5</sub></div></td></tr><tr><td><div>S <sub>5</sub></div></td><td><div>S <sub>4</sub></div></td><td><div>S <sub>6</sub></div></td></tr><tr><td><div>S <sub>6</sub></div></td><td><div>S <sub>6</sub></div></td><td><div>S <sub>6</sub></div></td></tr></tbody></table>

    Here, S 1 is the initial and S 3 , S 4 , S 5 , and S 6 are the final states.

    Now try to minimize the DFA.

    image

    Rename (S 1 ) as A, (S 2 ) as B, and (S 3 S 4 S 5 S 6 ) as C. The minimized FA is

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State</div></th></tr><tr><th><div>i = 0</div></th><th><div>i = 1</div></th></tr><tr><td><div>A</div></td><td><div>A</div></td><td><div>B</div></td></tr><tr><td><div>B</div></td><td><div>A</div></td><td><div>C</div></td></tr><tr><td><div>C</div></td><td><div>C</div></td><td><div>C</div></td></tr></tbody></table>

    where A is the initial state and C is the final state.

    It is proved that the two DFA are equivalent.

  27. Draw the state transition of a deterministic finite state automaton which accepts all strings from the alphabet (a, b), such that no string has three consecutive occurrences of the letter b.

    [GATE 1993]

    Solution:

    image

  28. Construct a finite state machine with minimum number of states, accepting all strings over (a, b) such that the number of a’ s is divisible by two and the number of b’s is divisible by three.

    [GATE 1997]

    Solution:

    image

Multiple Choice Questions

  1. A language L from a grammar G = {V N , Σ, P, S} is

    1. Set of symbols over V N
    2. Set of symbols over Σ
    3. Set of symbols over P
    4. Set of symbols over S
  2. Which is true for δ(q, ab)

    1. δ(q, a) ∪ δ(q, b)
    2. δ(δ(q, a), b)
    3. δ(q, a), b
    4. δ(q, a) ∩ δ(q, b)
  3. The transitional function of a DFA is

    1. Q × Σ → Q  
    2. Q × Σ → 2 Q
    3. Q × Σ → 2 n  
    4. Q × Σ → Q n
  4. The transitional function of an NFA is

    1. Q × Σ → Q  
    2. Q × Σ → 2 Q
    3. Q × Σ → 2 n   
    4. Q × Σ → Q n
  5. The maximum number of states of a DFA converted from an NFA with n states is

    1. n    
    2. n 2
    3. 2 n   
    4. None of these
  6. A string after full traversal is called not accepted by an NFA if it results in

    1. Some non-final states
    2. All non-final states
    3. A single non-final state
    4. Some final states
  7. An NFA with a set of states Q is converted to an equivalent DFA with a set of states Q′. Find which is true.

    1. Q′ = Q   
    2. Q′ image Q
    3. Q image Q′ 
    4. None of these
  8. The basic limitations of a finite state machine is

    1. It cannot remember arbitrarily large amount of information
    2. It cannot remember state transitions
    3. It cannot remember grammar for a language
    4. It cannot remember language generated from a grammar
  9. The string WW R is not recognized by any FSM because

    1. An FSM cannot remember arbitrarily large amount of information
    2. An FSM cannot fix the mid-point
    3. An FSM cannot match W with W R
    4. An FSM cannot remember the first and last inputs.
  10. A finite automata recognizes

    1. Any language
    2. Context sensitive language
    3. Context-free language
    4. Regular language
  11. Which is true for a dead state?

    1. It cannot be reached anytime
    2. There is no necessity of the state
    3. If control enters, there is no way to come out from the state
    4. If control enters, FA is dead
  12. The language accepted by the given FA is

    image

    1. (ab)* 
    2. bb*a
    3. b(ba)*a
    4. Null
  13. In the previous FA, B is called

    1. Dead state
    2. Inaccessible state
    3. Both a and b
    4. None of these
  14. Which is true for a Moore machine?

    1. Output depends on the present state
    2. Output depends on the present input
    3. Output depends on the present state and the present input
    4. Output depends on the present state and the past input
  15. Which is true for the Mealy machine?

    1. Output depends on the present state
    2. Output depends on the present input
    3. Output depends on the present state and the present input
    4. Output depends on the present state and the past input
  16. Which is true for the inaccessible state?

    1. It cannot be reached anytime
    2. There is no necessity of the state
    3. If control enters, there is no way to come out from the state
    4. If control enters, FA is dead
  17. In Mealy Machine, O/P is a function of

    1. Present state only
    2. Next state only
    3. Present state and Input
    4. Input only
  18. In Moore Machine, O/P is associated with

    1. Present state only
    2. Next state only
    3. Present state and Input
    4. Input only
  19. Which type of string is accepted by the following finite automata?

    image

    1. All string
    2. Null string
    3. No string
    4. All of the above

Answers:

  1. b
  2. b
  3. a
  4. b
  5. c
  6. b
  7. d
  8. a
  9. b
  10. d
  11. c
  12. d
  13. b
  14. a
  15. c
  16. a
  17. b
  18. a
  19. b

GATE Questions

  1. Consider the strings u = abbaba, v = bab, and w = aabb. Which of the following statement is true for the given transitional system?

    image

    1. The automaton accepts u and v but not w.
    2. The automaton accepts each of u, v, and w.
    3. The automaton rejects each of u, v, and w.
    4. The automaton accepts u but rejects v and w.
  2. Consider the transitional system.

    image

    Which of the states are to be marked as starting state and final state, respectively, so as to turn the above system into a DFA that accepts all strings having odd number of zeros and even number of 1’s?

    1. q 0 , q 2  
    2. q 0 , q 1  
    3. q 1 , q 2  
    4. None of these
  3. Consider the following DFA in which S 0 is the start state and S 1 and S 3 are the final states. Which one is true?

    image

    1. All strings of x and y.
    2. All strings of x and y which have either an even number of x and even number of y or an odd number of x and odd number of y.
    3. All strings of x and y which have an equal number of x and y.
    4. All strings of x and y which have either an even number of x and odd number of y or an odd number of x and even number of y.
  4. Let N be an NFA with n states and let M be the minimized DFA with m states recognizing the same language. Which of the following is NECESSARILY true?

    1. m ≤ 2 n     
    2. n ≤ m
    3. M has one accept state
    4. m = 2 n
  5. If the final state and non-final states in the following DFA are interchanged, then which of the following languages over the alphabet (a, b) will be accepted by the new DFA?

    image

    1. Set of all strings that do not end with ab
    2. Set of all strings that begin with either an a or a b.
    3. Set of all strings that do not contain the substring ab.
    4. The set described by the regular expression b*aa*(ba)*b*
  6. A finite state machine with the following state table has a single input x and a single output z.

    <table><colgroup><col> <col> <col></colgroup><tbody><tr><th><div>Present State</div></th><th><div>Next State, z</div></th></tr><tr><th><div>X = 1</div></th><th><div>X = 0</div></th></tr><tr><td><div>A</div></td><td><div>D, 0</div></td><td><div>B, 0</div></td></tr><tr><td><div>B</div></td><td><div>B, 1</div></td><td><div>C, 1</div></td></tr><tr><td><div>C</div></td><td><div>B, 0</div></td><td><div>D, 1</div></td></tr><tr><td><div>D</div></td><td><div>B, 1</div></td><td><div>C, 0</div></td></tr></tbody></table>

    If the initial state is unknown, then the shortest input sequence to reach the final state C is:

    1. 01 
    2. 10   
    3. 101  
    4. 110
  7. Which of the following sets can be recognized by a deterministic finite state automaton?

    1. The numbers 1, 2, 4, 8, . . . 2 n written in binary.
    2. The numbers 1, 2, 4, . . . 2 n written in unary.
    3. The set of binary string in which the number of zeros is the same as the number of ones.
    4. The set {1, 101, 11011, 1110111, . . .}
  8. Consider the regular expression (0 + 1)(0 + 1) . . . . . N times. The minimum state FA that recognizes the language represented by this regular expression contains

    1. n states   
    2. (n + 1) states 
    3. (n + 2) states
    4. None of the above
  9. What can be said about a regular language L over {a} whose minimal finite state automation has two states?

    1. L must be {a n | n is odd}  
    2. L must be {a n | n is even}
    3. L must be {a n | n ≥ 0}   
    4. Either L must be {a n | n is odd} or L must be {a n | n is even}
  10. The smallest FA which accepts the language {x | length of x is divisible by 3} has

    1. 2 states
    2. 3 states 
    3. 4 states  
    4. 5 states
  11. Consider the following deterministic finite state automaton M.

    image

    Let S denote the set of seven-bit binary strings in which the first, fourth, and last bits are 1. The number of strings in S that are accepted by M is

    1. 1   
    2. 5  
    3. 7 
    4. 8
  12. The following finite state machine accepts all those binary strings in which the number of 1’s and 0’s are, respectively,

    image

    • divisible by 3 and 2   
    • odd and even
    • even and odd  
    • divisible by 2 and 3
  13. Consider the machine M.

    image

    The language recognized by M is:

    1. {w ε{a, b}* | every a in w is followed by exactly two b’s}
    2. {w ε{a, b}* | every a in w is followed by at least two b’s}
    3. {w ε{a, b}* | w contains the substring ‘abb’}
    4. {w ε{a, b}* | w does not contain ‘aa’ as a substring}
  14. A minimum state deterministic FA accepting the language L = {w | w ε {0, 1}*} where number of 0’s and 1’s in w are divisible by 3 and 5, respectively, has

    1. 15 states    
    2. 11 states   
    3. 10 states  
    4. 9 states
  15. Following are two finite automata (→ indicates the start state and F indicates the final state)

    image

    Which of the following represents the product automaton Z × Y?

    image

  16. image

    The given DFA accepts the set of all strings over {0, 1} that

    1. begin either with 0 or 1.   
    2. end with 0
    3. end with 00.    
    4. contain the substring 00.
  17. Let w be any string of length n in {0, 1}*. Let L be the set of all substrings of w. What is the minimum number of states in a non-deterministic FA that accepts L?

    1. n – 1  
    2. n   
    3. n + 1  
    4. 2 n – 1
  18. Definition of a language L with alphabet {a} is given as following {a nk | k > 0 and n is a positive integer constant}

    What is the minimum number of states needed in a DFA to recognize L?

    1. k + 1    
    2. n + 1   
    3. 2 n + 1     
    4. 2 k + 1
  19. A deterministic finite automation (DFA) D with alphabet ∑ = {a, b} is given as follows:

    image

    Which of the following finite state machines is a valid minimal DFA which accepts the same language as D?

    image

    image

Answers:

  1. d
  2. c
  3. d
  4. a
  5. a
  6. b
  7. a
  8. b
  9. a
  10. b
  11. a
  12. a
  13. a
  14. a
  15. a, b
  16. c
  17. c
  18. b
  19. a

Hints:

3.  If S 1 is the final state, then it accepts an odd number of x and even number of y. If S 3 is the final state, then an even number of x and odd number of y.

4.  The highest possibility is to be 2 n . May be less than that.

5.  The diagram is

image

6. Consider the initial state as A or B.

7.

image

9.

image

10.

image

11. The string is 1001001.

15. It came in the 2008 GATE CSE. All answers are wrong!

a is true if δ(S, a) → P and δ(S, b) → Q. b is true if δ(P, b) → R.

The cross-product of two DFA {Q 1 , ∑ 1 , δ 1 , q 01 , F 1 }, {Q 2 , ∑, δ 2 , q 02 , F 2 } is {Q, ∑, δ, q 0 , F} where q 0 = (q 01 , q 02 ), F = {F 1 , F 2 } and

δ(Q 1 , Q 2 , i/p e ∑) = δ(Q 1 , i/p ε ∑) ∪ δ(Q 2 , i/p ε ∑).

For the example, q 0 = (1, 1)(P) and F = (2, 2)(R)

 
A
b
(1, 1)(P)
(1, 2)
(2, 2)
(2, 1)(Q)
(2, 2)
(1, 2)
(2, 2)(R)
(2, 1)
(1, 1)
(1, 2)(S)
(1, 1)
(2, 1)

16. a is wrong as 10 is not accepted. b is wrong as 10 is not accepted. d is wrong as 1001 is not accepted.

17. Let w = 01. The FA is

image

18.

image

19. Minimize it.

Fill in the Blanks

  1. Finite automata is defined as M = {____, ____, ____, _____, ______}.
  2. Finite automata is one type of ______________ state machine.
  3. In the graphical format representation of finite automata, by double circle _________________ state is represented.
  4. In the tabular format representation of finite automata, by single circle ________________ state is represented.
  5. In the block diagram of finite automata, the input from input tape is read by ___________________.
  6. Finite control can be considered as a _______________ unit of a finite automaton.
  7. If the input is given null for a state of finite automata, the machine goes to the _______________.
  8. There are two conditions for declaring a string accepted by a finite automaton. The conditions are ________________ and ________________.
  9. For DFA, the transitional function δ is represented by Q × ∑ → _______________.
  10. DFA is a finite automata where for all cases for a single input given to a single state, the machine goes to a _______________ state.
  11. In NFA, δ is a transitional function mapping Q × ∑ → _________________.
  12. If any finite automata contains any ε (null) move or transaction, then that finite automata is called __________________ with ε moves.
  13. A state where the control can enter and be confined till the input ended, but there is no way to come out from that state is called _________________.
  14. The Mealy machine and Moore machine are example of finite automata with _________________.
  15. For the Mealy machine, the output depends on ___________________ and ________________.
  16. For the Moore machine, the output depends on ________________.
  17. The states which can never be reached from the initial state are called ______________ states.
  18. A relation R in set S is called equivalence relation if it is __________________, ______________, and ________________.
  19. A relation R in set S is _________________ if for x, y in S, yRx whenever xRy.
  20. A relation R in set S is _________________ if for x, y, and z in S, xRz whenever xRy and yRz.
  21. R is __________________ then for all x, y, and z, xRy image xzRyz.
  22. The Myhill–Nerode theorem is used for _________________.
  23. A two-way finite automata is like finite automata but can traverse in ________________.
  24. The lexical analyser is designed by _____________.
  25. The maximum number of states of a DFA converted from an NFA with n states is _______________.
  26. A finite automata recognizes _______________ language.

Answers:

  1. Q, Σ, δ, q 0 , F
  2. finite
  3. final
  4. final
  5. reading head
  6. control
  7. same state
  8. string must be totally traversed, the machine must come to a final state
  9. Q
  10. single
  11. 2 Q
  12. NFA
  13. dead state
  14. outputs
  15. present state, present input
  16. present state
  17. inaccessible
  18. reflexive, symmetric, transitive
  19. symmetric
  20. transitive
  21. right invariant
  22. minimization of FA
  23. both directions
  24. finite automata
  25. 2 n
  26. regular

Exercise

  1. Define finite automata. Can an FA have multiple initial and final states? Can an FA have no final state? Give reason in support of your answer.

  2. Is it possible that a single string is accepted by two different finite automata? Is it true for a single regular expression to be accepted by two non-equivalent finite automata? Give reason.

  3. Test whether the following strings are accepted by the given finite automata or not.

    1. 01010    
    2. 1010100   
    3. 1110011

    image

  4. Test whether the following strings are accepted by the given finite automata or not.

    1. 100010   
    2. 0001101   
    3. 1000

    image

  5. Test whether the following string 101001 is accepted by the given finite automata or not taking all possible combinations of the transitional path.

    image

    Why are you getting different results? Explain.

  6. Define NFA. Mention the differences between NFA and DFA. What is the necessity of converting an NFA to a DFA?

  7. Convert the following NFAs into equivalent DFAs.

    image

    D is final.

    image

    A, B, C, and D are final states.

  8. Why is an FA with ε transition called NFA? What is the necessity of NFA with ε transition? If in an FA a self-loop is made on a state with label ε, will it be called an NFA with ε move? Give reason.

  9. Convert the following NFAs with null move to equivalent DFAs.

    1.  

      image

    2.  

      image

  10. Define Mealy machine and Moore machine. If a sequence detector is designed for a string using Mealy and Moore machine, then the Moore is converted to a Mealy machine. Will the two Mealy machines be the same always?

    1. A Mealy machine is converted to an equivalent Moore Machine. A string is given input to both of the machines. Will the output be same always?

    2. Convert the following Moore machines into equivalent Mealy machines.

      1.  

        image

      2.  

        image

  11. Convert the following Mealy machines into equivalent Moore machines.

    1.  

      image

    2.  

      image

  12. Convert the following Moore machine into an equivalent Mealy machine by the transitional format.

    image

  13. Convert the following Mealy machine into an equivalent Moore machine by the transitional format.

    image

  14. Why is minimization of finite automata necessary? Define equivalent state and distinguishable state.

  15. Minimize the following finite automata by using the equivalent state method.

    1.  

      image

    2.  

      image

  16. Minimize the following finite automata by the Myhill–Nerode theorem.

    image