Open In App
Related Articles

Introduction of Finite Automata

Improve Article
Save Article
Like Article

Finite Automata(FA) is the simplest machine to recognize patterns.It is used to characterize a Regular Language, for example: /baa+!/.
Also it is used to analyze and recognize Natural language Expressions. The finite automata or finite state machine is an abstract machine that has five elements or tuples. It has a set of states and rules for moving from one state to another but it depends upon the applied input symbol. Based on the states and the set of rules the input string can be either accepted or rejected. Basically, it is an abstract model of a digital computer which reads an input string and changes its internal state depending on the current input symbol. Every automaton defines a language i.e. set of strings it accepts. The following figure shows some essential features of general automation.

Figure: Features of Finite Automata

The above figure shows the following features of automata:

  1. Input
  2. Output
  3. States of automata
  4. State relation
  5. Output relation

A Finite Automata consists of the following: 

Q : Finite set of states.
Σ : set of Input Symbols.
q : Initial state.
F : set of Final States.
δ : Transition Function.

Formal specification of machine is 

{ Q, Σ, q, F, δ }

FA is characterized into two types: 

1) Deterministic Finite Automata (DFA):

DFA consists of 5 tuples {Q, Σ, q, F, δ}. 
Q : set of all states.
Σ : set of input symbols. ( Symbols which machine takes as input )
q : Initial state. ( Starting state of a machine )
F : set of final state.
δ : Transition Function, defined as δ : Q X Σ --> Q.

In a DFA, for a particular input character, the machine goes to one state only. A transition function is defined on every state for every input symbol. Also in DFA null (or ε) move is not allowed, i.e., DFA cannot change state without any input character. 

For example, construct a DFA which accept a language of all strings ending with ‘a’.
Given:  Σ = {a,b}, q = {q0}, F={q1}, Q = {q0, q1}

First, consider a language set of all the possible acceptable strings in order to construct an accurate state transition diagram.
L = {a, aa, aaa, aaaa, aaaaa, ba, bba, bbbaa, aba, abba, aaba, abaa}
Above is simple subset of the possible acceptable strings there can many other strings which ends with ‘a’ and contains symbols {a,b}.

Fig 1. State Transition Diagram for DFA with Σ = {a, b} 

Strings not accepted are,
ab, bb, aab, abbb, etc.

State transition table for above automaton,

⇣State\Symbol⇢ a b
q0 q1 q0
q1 q1 q0

One important thing to note is, there can be many possible DFAs for a pattern. A DFA with a minimum number of states is generally preferred. 

2) Nondeterministic Finite Automata(NFA): NFA is similar to DFA except following additional features: 

  1. Null (or ε) move is allowed i.e., it can move forward without reading symbols. 
  2. Ability to transmit to any number of states for a particular input. 

However, these above features don’t add any power to NFA. If we compare both in terms of power, both are equivalent. 

Due to the above additional features, NFA has a different transition function, the rest is the same as DFA. 

δ: Transition Function
δ:  Q X (Σ U ε ) --> 2 ^ Q. 

As you can see in the transition function is for any input including null (or ε), NFA can go to any state number of states. For example, below is an NFA for the above problem. 

Fig 2. State Transition Diagram for NFA with Σ = {a, b}

State Transition Table for above Automaton,

⇣State\Symbol⇢ a b
q0 {q0,q1} q0

One important thing to note is, in NFA, if any path for an input string leads to a final state, then the input string is accepted. For example, in the above NFA, there are multiple paths for the input string “00”. Since one of the paths leads to a final state, “00” is accepted by the above NFA. 

Some Important Points: 

  • Justification:
Since all the tuples in DFA and NFA are the same except for one of the tuples, which is Transition Function (δ) 

In case of DFA
δ : Q X Σ --> Q
In case of NFA
δ : Q X Σ --> 2Q

Now if you observe you’ll find out Q X Σ –> Q is part of Q X Σ –> 2Q.

On the RHS side, Q is the subset of 2Q which indicates Q is contained in 2Q or Q is a part of 2Q, however, the reverse isn’t true. So mathematically, we can conclude that every DFA is NFA but not vice-versa. Yet there is a way to convert an NFA to DFA, so there exists an equivalent DFA for every NFA

  1. Both NFA and DFA have the same power and each NFA can be translated into a DFA. 
  2. There can be multiple final states in both DFA and NFA. 
  3. NFA is more of a theoretical concept. 
  4. DFA is used in Lexical Analysis in Compiler. 
  5. If the number of states in the NFA is N then, its DFA can have maximum 2N number of states.

See Quiz on Regular Expression and Finite Automata

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 27 Jun, 2023
Like Article
Save Article
Similar Reads