Chapter Two
Chapter Two
Introduction to Finite
Automata and Formal
Language
Introduction
Automata Theory models represent features at the core of all computers and
their applications.
To model the hardware of a computer, we introduce the notion of an automaton
(plural, automata).
An automaton is a construct that possesses all the indispensable features of a
digital computer.
It accepts input, produces output, may have some temporary storage, and can
make decisions in transforming the input into the output.
A formal language is an abstraction of the general characteristics of
programming languages.
A formal language consists of a set of symbols and some rules of formation by
which these symbols can be combined into entities called sentences.
Theory of automata
Grammar
A grammar defines a set of rules, and with the use of these
rules, valid sentences in a language are generated. Similar
to English language we have set of rules in automata,
which help us in creating sentences.
A popular way to derive a grammar recursively is phrase-
structure grammar.
Finite Automata
An automaton with a finite number of states is called a Finite automaton.
Finite Automata can be classified into :
Deterministic finite automata, non-deterministic finite automata, Regular
expression, context-free grammar, context-free language, Push down automata,
Turning machines, etc.
Finite automata are used to recognize patterns.
It takes the string of symbol as input and changes its state accordingly. When
the desired symbol is found, then the transition occurs.
At the time of transition, the automata can either move to the next state or stay
in the same state.
Finite automata have two states, Accept state or Reject state. When the
input string is processed successfully, and the automata reached its final state,
then it will accept.
Formal Definition of FA
1. DFA
DFA refers to deterministic finite automata. Deterministic refers to the uniqueness
of the computation. In the DFA, the machine goes to one state only for a particular
input character. DFA does not accept the null move.
2. NFA
NFA stands for non-deterministic finite automata. It is used to transmit any
number of states for a particular input. It can accept the null move.
Some important points about DFA and NFA:
1. Every DFA is NFA, but NFA is not DFA.
2. There can be multiple final states in both NFA and DFA.
3. DFA is used in Lexical Analysis in Compiler.
4. NFA is more of a theoretical concept.
DFA (Deterministic finite automata)
Example 1:
Q = {q0, q1, q2}
∑ = {0, 1}
q0 = {q0}
F = {q2}
Try This
Design FA with ∑ = {0, 1} accepts even number of 0's and even number of
1's.
NFA (Non-Deterministic finite
automata)
• NFA stands for non-deterministic finite automata. It is easy to construct
an NFA than DFA for a given regular language.
• The finite automata are called NFA when there exist many paths for
specific input from the current state to the next state.
• Every NFA is not DFA, but each NFA can be translated into DFA.
• NFA is defined in the same way as DFA but with the following two
exceptions, it contains multiple next states, and it contains ε transition.
In the following image, we can see that from state q0 for input a, there
are two next states q1 and q2, similarly, from q0 for input b, the next
states are q0 and q1.
Thus it is not fixed or determined that with a particular input where to
go next. Hence this FA is called non-deterministic finite automata.
example
Formal definition of NFA:
NFA also has five states same as DFA, but with different transition
function, as shown follows:δ: Q x ∑ →2Q
1. Q: finite set of states
2. ∑: finite set of the input symbol
3. q0: initial state
4. F: final state
5. δ: Transition function
Graphical Representation of an NFA
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
Conversion from NFA to DFA
In this section, we will discuss the method of converting NFA to its
equivalent DFA.
In NFA, when a specific input is given to the current state, the machine
goes to multiple states.
It can have zero, one or more than one move on a given input symbol.
On the other hand, in DFA, when a specific input is given to the current
state, the machine goes to only one state.
DFA has only one move on a given input symbol.
Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the language L(M).
There should be equivalent DFA denoted by M' = (Q', ∑', q0', δ', F')
such that L(M) = L(M').
Steps for converting NFA to DFA:
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
State 0 1
→[q0] [q0] [q1]
[q1] [q1, q2] [q1]
*[q2] [q2] [q1, q2]
*[q1, q2] [q1, q2] [q1, q2]
The End
Any question????