Unit 1: Finite State Machines
Unit 1: Finite State Machines
Unit 1: Finite State Machines
1)Symbol:
Symbol is a character.
Ex: a,b,c,……..z
0,1,2,…….9
+,-,%,…………special characters
2) Alphabet:
• Example
Let’s consider w=’Theory’ is defined with prefix, x=’The’ and suffix ,
y=’ry’.
The substring is v=’o’, because, w=xvy and Theory= Thevry
Therefore, v=o
3) Kleene star operation :
• Let ‘w’ be a string. w’ is a set of strings obtained by applying any
number of concatenations of w with itself, including empty string.
• Example
a*= { ε,a,aa,aaa,………}
4)Reversal:
• If ‘w’ is a string, then wR is the reversal of the string in backwards.
• Rules
The rules for the reversal operation are as follows −
x=(xR)R
(xz)R= zR.xR
Example
A string x is defined as x= tutorial then (xR)R is tutorial. This is because,
X= tutorial
(x)R= lairotut
(xR)R= tutorial
Deterministic Finite Automata
• DFA refers to deterministic finite automata. Deterministic refers to the
uniqueness of the computation.
• The finite automata are called deterministic finite automata if the
machine is read an input string one symbol at a time.
• In DFA, there is only one path for specific input from the current state
to the next state.
• DFA does not accept the null move, i.e., the DFA cannot change state
without any input character.
• DFA can contain multiple final states. It is used in Lexical Analysis in
Compiler.
In the following diagram, we can see that from state q0 for input a,
there is only one path which is going to q1. Similarly, from q0, there is
only one path for input b going to q2.
A DFA is a collection of 5-tuples same as we described in the definition
of FA.
1)Q: finite set of states
2)∑: finite set of the input symbol
3)q0: initial state
4)F: final state
5)δ: Transition function
Example 1:
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and
ends with 0.
Solution:
The FA will have a start state q0 from which only the edge with input 1
will go to the next state.
Example 2:
Design a FA with ∑ = {0, 1} accepts the only input 101.
Solution:
Example 3:
Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.
Solution:
This FA will consider four different stages for input 0 and input 1. The stages could
be:
Example 4:
Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's.
Solution:
The strings that will be generated for this particular languages are 000, 0001, 1000,
10001, .... in which 0 always appears in a clump of 3. The transition graph is as
follows:
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.
A NFA is a collection of 5-tuples same as we described in the
definition of FA.
1)Q: finite set of states
2)∑: finite set of the input symbol
3)q0: initial state
4)F: final state
5)δ: Transition function
Example 1:
NFA with ∑ = {0, 1} accepts all strings with 01.
Solution:
δ a b
a
q0 q1
q0 {q0,q1} q0
q1 q2 q1
a
q2 q3 q3
a,b
q3 q2 q3 - q2
b
b
δ a b b
a
q0 [q0,q1] q0 q0 q0,q1
a
a,b
q0,q1,q2,q3
Conversion of epsilon NFA to NFA
1
0 0 1
q2 q3
q3
FINITE AUTOMATA
NFA with ϵ
λ 0Q =Δ λ 0Q * Ʃ = Δ