THEORY OF COMPUTATION J. Veerendeswari /IT/RGCET Page 1 Finite Automata and Regular Expressions: Formal Languages and Regular expressions, Deterministic and Non-Deterministic Finite Automata, Finite Automata with ε-moves, Equivalence of NFA and DFA, Minimization of finite automata, Two-way finite automata, Moore and Mealy machines, Applications of finite automata. FINITE AUTOMATA Finite automata is a mathematical model of a system with discrete inputs and outputs .The system can be in any one of finite number of states and the state summarizes the history of inputs and determines the behaviour of the system for subsequent input. COMPONENTS OF FINITE AUTOMATA Block diagram of Finite Automata String to be processed The block diagram of the finite automata contains three components namely, 1 .Input tape 2. Reading Head Pointer 3. Finite Control Input Tape The input tape is divided into number of squares or cells. Each square contains single symbol or alphabet from the input alphabet Σ. The left end square of the tape contains ¢ and the right end square contains $ symbol. The absence of the end markers indicate that the tape is of infinite length. The left to right sequence of symbols between the end markers is the string to be processed. Reading Head Pointer The head examines only one square at a time and can move either one square to the left or to the right. We restrict the movement of the reading head pointer only to the right side. Finite Control The finite control contains the routines, which instruct the reading head pointer to move from one state to the next state by recognising each and every symbol or alphabet. The transition of reading head pointer from one state to another state by recognising an alphabet is indicated by δ( q ,a). For E.g.: Consider a Finite Automata with the transition diagram a b b b a ¢ A b b A b $ q0 q2 q1 FINITE CONTROL
19
Embed
THEORY OF COMPUTATION - Rajiv Gandhi College of ... YEAR/THEORY OF COMPUTATION/U… · THEORY OF COMPUTATION J. Veerendeswari /IT/RGCET Page 1 Finite Automata and Regular Expressions:
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 1
Finite Automata and Regular Expressions: Formal Languages and Regular expressions, Deterministic and
Non-Deterministic Finite Automata, Finite Automata with ε-moves, Equivalence of NFA and DFA, Minimization
of finite automata, Two-way finite automata, Moore and Mealy machines, Applications of finite automata.
FINITE AUTOMATA
Finite automata is a mathematical model of a system with discrete inputs and outputs .The system can be
in any one of finite number of states and the state summarizes the history of inputs and determines the behaviour
of the system for subsequent input.
COMPONENTS OF FINITE AUTOMATA
Block diagram of Finite Automata
String to be processed
The block diagram of the finite automata contains three components namely,
1 .Input tape
2. Reading Head Pointer
3. Finite Control
Input Tape
The input tape is divided into number of squares or cells. Each square contains single symbol or alphabet
from the input alphabet Σ. The left end square of the tape contains ¢ and the right end square contains $
symbol. The absence of the end markers indicate that the tape is of infinite length. The left to right
sequence of symbols between the end markers is the string to be processed.
Reading Head Pointer
The head examines only one square at a time and can move either one square to the left or to the right. We
restrict the movement of the reading head pointer only to the right side.
Finite Control
The finite control contains the routines, which instruct the reading head pointer to move from one state to
the next state by recognising each and every symbol or alphabet. The transition of reading head pointer
from one state to another state by recognising an alphabet is indicated by δ( q ,a).
For E.g.: Consider a Finite Automata with the transition diagram
a b b
b a
¢ A b b A b $
q0 q2 q1
FINITE
CONTROL
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 2
The transition graph or transition diagram is a finite labelled graph in which each vertex or node represent a state
and the directed arcs indicates the transition of a state and the edges are labelled with input/output .The initial
state is indicated with circle and arrow pointing towards it, and the final state is indicated by concentric circles.
A transition graph or a transition system is a finite directed graph in which each vertex or node represents
a state and the directed edge are labelled with output/input.
0/0 1/0 1/1
0/0
Automaton in which the output depends only on the input is called as an automaton without memory. An
automaton in which the output depends only on the states of the machine is called as Moore machine. An
automaton in which output depends only on the states as well as on the input at any instant of time is called a
Mealy machine. Both the Moore and Mealy machine are Finite automaton with output.
TYPES OF FINITE AUTOMATA
The finite automata can be divided into
a) Deterministic Finite Automata (DFA).
b) Non-deterministic Finite Automata (NFA or NDFA)
Deterministic Finite Automata
The finite automata is called deterministic finite automata if there is only only path for a specific input
from current state to next state.
The deterministic finite automata can represented by 5-tuples.If M is the deterministic finite automata then,
M= (Q, ∑, δ, q0, F)
Where,
Q is the finite set of states.
∑ is the finite set of inputs.
δ is the finite set of transitions where δ: Q X∑ Q
q0is the initial state.
F is the final state.
Consider an example,
a b b
b a
Here
Q= {q0, q1, q2}
∑= {a, b}
q0= {q0}
F= {q2}
Transition Table
This is a tabular representation of finite automata.
q0 q1
q0 q2 q1
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 3
δ a b
{q0} {q0} {q1}
{q1 } {q2} {q1}
{q2} ɸ {q2}
Non Deterministic Finite Automata
A non-deterministic finite automaton (NDFA) can be represented by 5 tuples namely
M= (Q, ∑, δ, q0, F)
Where,
M is the NFA with ε moves.
Q is the finite set of states.
∑ is the finite set of inputs.
δ is the finite set of transitions where Q x ∑ 2Q.
q0is the initial state.
F is the final state.
e.g.:
a b a
a,b a,b
Where,Q = {q0, q1, q2}
∑ = {a, b}
q0 = {q0}
F = {q2}
Transition Table
δ a b
q0 (q0, q1)(q1)
q1 (q2 ) ( q1, q2 )
q2 ( q2) ɸ
Difference Between NFA And DFA
The main difference between NFA and DFA is,
The deterministic finite automata contains only at most one transition from each and every state for each
input symbol but the non-deterministic finite automata contains more than one transition for each and
every symbol from each and every state.
Q0 Q2 Q1
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 4
The second difference is that DFA has the transition mapping Q x ∑ Q where as the NFA contains the
transition mapping Q x ∑ 2Q or Q´.
FINITE AUTOMATA WITH ε- MOVES to NFA WITHOUT ε
The ‘ε’ is a character used to indicate the null string i.e. the string which is used simply for transition from one
state to the other without any input.
The NFA with ε-moves can be shown below:
e.g.
a ε ε
a b ε
Let us define NFA with ε-transition asM(Q, ∑, δ ,q0,F)
Where,
M is the NFA with 𝜀 moves.
Q is the finite set of states.
∑ is the finite set of input.
δ is the finite set of transitions.
q0is the initial state of NFA.
F is the final state of NFA with 𝜀 −moves.
The transition mapping is given by
Q x (∑ U {𝜀})2Q or Q´.
Definition of 𝜺 closure
𝜀- closure(q) denotes the set of all states which are reachable from state p on 𝜀 transition such that
𝜀 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 (p)=p where p€Q
If there exists 𝜀 closure(p)={q} and δ(q,𝜀)=𝑟 𝑡ℎ𝑒𝑛𝜀 −closure(p)={q,r}
e.g.
Consider finite automata with 𝜀-moves
x y z
𝜀𝜀
The 𝜀 −closure for each and every state as follows:
𝜀 -closure(q0)= {q0,q1,q2}
𝜀 -closure(q1)= {q1,q2}
q0
q3
q1 q2
q0 q1 q2
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 5
𝜖 -closure(q2)= {q2}
CONVERSION OF NFA WITH 𝜺 −TRANSITION TO NFA WITHOUT 𝜺-TRANSITION
Steps:
In this method we try to remove all the є transition from given NFA. The method will be
1. Find out all the є transition from each state from q. That will be called as є - closure{qi} where qi єq.
2. Then δ’ transitioncan be obtained. The δ’ transition means an є- closure on δ moves.
3. Step-2 is repeated for each input symbol and for each state of given NFA.
4. Using the resultant states the transition table for equivalent NFA without є can be built.
Theorem:
If L is accepted by NFA with є transition, then there exist L which is accepted by NFA without є transitions.
Proof:
Let, M= (Q, ∑, δ, q0, F) be an NFA with є transitions.
Contruct M’=(Q,∑, δ’ ,q0,F’) where
F’={F={q0} if є- closure contains of F state
F otherwise
M’ is a NFA without є moves. The δ’ function can be denoted by δ’’ with some input. For example, δ’(q,a)
=δ’’(q,a) for some q in Q and a from ∑. We will apply the method of induction with input X. The X will not
be є because
δ’(q,є)={q0}
δ’’(q,є)= є- closure (q0). Therefore we will assume length of string to be 1.
Basis:|X|=1. Then x is a symbol a.
δ’(q,a) =δ’’(q,a)
Induction: :|X|>1 let X=wa
δ’(q,wa) =δ’(δ’(qa,w),a)
by inductive hypothesis,
δ’(q0,w) =δ’’(q0,w) =P
now we will show that δ’(p,a) =δ(q0,wa)
but δ’(p,a) =Uδ’(q,a) =Uδ’’(q,a)
q in p q in p
as p= δ’’(q0,w)
we have Uδ’’(q,a) =Uδ’’(q0,wa)
q in p
thus by definition δ’’
Rule for conversion;
δ’(q0, wa) = δ’’(q0, wa)
δ’(q,a) =є- closure (δ(δ^(q,є, a)
Where δ’(q,a) = є- closure(q)
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 6
Example:
a b c
𝜀𝜀
Consider a NFA with 𝜀-transition has 5 tuples
M= (Q,∑, δ ,q0,F)
Where,
Q={q0,q1,q2}
∑={a,b,c,𝜀 }
q0={ q0}
F={ q2}
δ is the transition function that maps,
Q x (∑ U {𝜀})2Q or Q´.
Transition table
δ a b c 𝜀
{ q0} { q0} ɸ ɸ { q1}
{ q1} ɸ { q1} ɸ { q2}
{ q2} ɸ ɸ { q2} ɸ
When converting NFA with 𝜀-transition to NFA without 𝜀-transition, one automaton contains
M´ = (Q,∑ ,δ ´,q0,F´)
Where,
Q= {q0,q1,q2}
∑= { a,b,c}
δ´ is the transition function for NFA without transition , then we first compute the 𝜀-closure of each and every
state.
𝜀 -closure(q0)= {q0,q1,q2}
𝜀 -closure(q1)= {q1,q2}
𝜀 -closure(q2)= {q2}
The transition function for each and every input symbol can be summarised as:
δ´( q0,a) =𝜀 -closure(δ(δ´( q0,𝜀 ),a))
=𝜀 -closure(δ({q0,q1,q2},a))
=𝜀 -closure(δ(q0,a)U δ ( q1,a)U δ (q2,a))
q0 q1 q2
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 7
=𝜀 -closure(q0UɸU ɸ)
=𝜀 -closure(q0)
={q0,q1,q2}
δ´( q0,b) =𝜀 -closure(δ(δ´( q0,𝜀 ),b))
=𝜀 -closure(δ({q0,q1,q2},b))
=𝜀 -closure(δ(q0,b)U δ ( q1,b)U δ (q2,b))
=𝜀 -closure(ɸUq1U ɸ)
=𝜀 -closure(q1)
={q1,q2}
δ´( q0,c) =𝜀 -closure(δ(δ´( q0,𝜀 ),c))
=𝜀 -closure(δ({q0,q1,q2},c))
=𝜀 -closure(δ(q0,c)U δ ( q1,c)U δ (q2 ,c))
=𝜀 -closure(ɸUɸ Uq2)
=𝜀 -closure(q2)
={q2}
δ´( q1,a) =𝜀 -closure(δ(δ´( q1,𝜀 ),a))
=𝜀 -closure(δ({q1,q2},a))
=𝜀 -closure(δ ( q1,a)U δ (q2,a))
=𝜀 -closure(ɸU ɸ)
=𝜀 -closure(ɸ)
=ɸ
δ´( q1,b) =𝜀 -closure(δ(δ´( q1,𝜀 ),b))
=𝜀 -closure(δ({q1,q2},b))
=𝜀 -closure(δ ( q1,b)U δ (q2,b))
=𝜀 -closure(q1U ɸ)
=𝜀 -closure(q1)
={q1,q2}
δ´( q1,c) =𝜀 -closure(δ(δ´( q1,𝜀 ),c))
=𝜀 -closure(δ({q1,q2},c))
=𝜀 -closure(δ( q1,c)U δ (q2 ,c))
=𝜀 -closure(ɸUq2)
=𝜀 -closure(q2)
={q2}
δ´( q2,a) =𝜀 -closure(δ(δ´( q2,𝜀 ),a))
=𝜀 -closure(δ({q2},a))
=𝜀 -closure(δ (q2,a))
=𝜀 -closure(ɸ)
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 8
=ɸ
δ´( q2,b) =𝜀 -closure(δ(δ´( q2,𝜀 ),b))
=𝜀 -closure(δ({q2},b))
=𝜀 -closure(δ (q2,b))
=𝜀 -closure(ɸ)
=ɸ
δ´( q2,c) =𝜀 -closure(δ(δ´( q2,𝜀 ),c))
=𝜀 -closure(δ({q2},c))
=𝜀 -closure(δ (q2 ,c))
=𝜀 -closure(q2)
={q2}
The transition for NFA without 𝜀-moves:
a a, b b b,c c
a,b,c
EQUIVALENCE OF NFA AND DFA
Statement:
Let ‘L’ be a set accepted by a non-deterministic finite automata then there exists a deterministic finite automaton
that accepts “L”.
To Prove:
The Language accepted by NFA is equal to the language set accepted by DFA.
i.e. L(M)=L(M´)
Where M is the NFA and M´ is the DFA.
Proof:
Let M= (Q,∑, δ ,q0,F) be an NFA ,accepting L and we can define a DFA
M´ = (Q,∑ ,δ´,q0,F´) as follows .
The states of M´ are all the subsets of the set of states of M.
That is, Q´=2Q
M´ will keep track in its states of all the states M could be in at any given time. F´ is the set all the states in Q´
containing the final state of M. An element of Q´ will be denoted by
[q1,q2,q3....qi] are in Q .
Observe that, [q1,q2,q3....qi] is a single state of DFA corresponding to the states of the NFA. Note q0´=[q0]
We define
δ´([q1,q2,q3....qi],a)= [P1,P2,P3....Pj]
if and only if
q0 q1 q2 q1
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 9
δ([q1,q2,q3....qi],a)= [P1,P2,P3....Pj]
that is
δ´ applied to an element [q1,q2,q3....qi] of Q´ is computed by applying δ to each state of Q represented by
[q1,q2,q3....qi] in applying δ to each of [q1,q2,q3....qi] and taking “union” we get some new set of states
P1,P2,P3....Pj. This new set of states has a representative P1,P2,P3....Pj in Q´ and that element is the value of
δ´([q1,q2,q3....qi],a).
It is easy to show by induction for the length of the input string x, that
δ´( q0´,x) =[q1,q2,q3....qi]
if and only if,
δ( q0,x) ={q1,q2,q3....qi}
Basis
Consider |x|=0 then x must be 𝜀 since q0´=[q0]
𝜀
Then
δ´( q0’, 𝜀)=( q0)
if and only if
δ( q0, 𝜀)= { q0}
Hence the result is trivial.
Induction
Let us assume that the hypothesis is true for inputs of length m, Let xa be a string of length m+1 with a in ∑, then
δ´( q0’, 𝑥𝑎)= δ´( δ´( q0
’, 𝑥), 𝑎)
By the inductive hypothesis ,
δ´( q0’, 𝑥) = [P1,P2,P3....Pj]
If and only if ,
δ( q0, 𝑥) = [P1,P2,P3....Pj]
But by the definition of δ´,
δ´[(P1,P2,P3....Pi),a]= [r1,r2,r3....rk]
If and only if,
δ[(P1,P2,P3....Pi),a]= [r1,r2,r3....rk]
Thus,
δ´( q0’, 𝑥𝑎)= [r1,r2,r3....rk]
If and only if,
δ( q0, 𝑥𝑎)= [r1,r2,r3....rk]
Which establishes the inductive hypothesis,
To complete the proof , we have only to add that δ´( q0’, 𝑥) is in F´ exactly when δ( q0, 𝑥) contains a state of Q that
is F.
Thus,
L(M)=L(M´)
CONVERSION OF NFA TO DFA
q0
THEORY OF COMPUTATION
J. Veerendeswari /IT/RGCET Page 10
Steps:The method of converting NFA to its equivalent DFA. Let M= (Q,∑, δ ,q0,F) is a NFA which accepts the
language L(M). There should be equivalent DFA denoted by M’=(Q’,∑’, δ’ ,q0’,F’) such that L(M)=L(M’).
The conversion method will follow following steps:
1. The start state of NFA M will be the start for DFA M’. Hence add qo of NFA(start state) to Q’.
Then find the transitions from this start state.
2. For each state[q1,q2..qi] in Q the transition for each input symbol ∑ can be obtained as,