theory of automata and formal languages unit 1
TRANSCRIPT
05/01/2023 Abhimanyu Mishra(CSE) JETGI
THEORY OF AUTOMATA AND FORMAL LANGUAGES
UNIT-I
ABHIMANYU MISHRAASSISTANT PROF.(CSE)
JETGI
05/01/2023 Abhimanyu Mishra(CSE) JETGI
What is Automata?AUTOMATAAn Automation derived from the Greek word which means "self-acting". An automaton (Automata in plural) is an theoretical self-propelledcomputing device which follows a predetermined sequence of operations automatically. “A set of string all of which are chosen form some ∑*,where ∑ is particular alphabet, is called a language". If ∑ is an alphabet, and L<= ∑*, then L is said to be language over alphabet ∑.
KLEENE CLOSURE“If S is a set of words then by S* we mean the set of all finite strings formed by concatenating words from S, where any word may be used as often we like, and where the null string is also included”
For example if ∑={0,1}
∑* ={ €,0,1,00,01,10,11,000,001,…………}
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Finite automation is called “finite” because number of possible states and number of letter in the alphabet are both finite, and “automation” because the change of the state is totally governed by the input. it is deterministic, since, what state is next is automatic not will-full, just as the motion of the hands of the clock is automatic, while the motion of hands of a human is presumably the result of desire and thought.
THERE ARE TWO TYPES OF FINITE AUTOMATA
(A) DETERMINISTIC FINITE AUTOMATA(DFA)(B) NON DETERMINISTIC FINITE AUTOMATA(NDFA)
FINITE AUTOMATA
05/01/2023 Abhimanyu Mishra(CSE) JETGI
DETERMINISTIC FINITE AUTOMATA(DFA) IS A QUINTUPLE (Q,Σ, δ,q0,F)
1. where :Q is a finite set of states.2. Σ is a finite set of symbols, called the alphabet of the automaton.3. δ is the transition function, that is, δ: q × Σ → Q.4. q0 is the start state, that is, the state of the automaton before any input has been processed, where q0 Q.∈5. F is a set of states of q (i.e. F Q) called ⊆ accept states.
(A) DETERMINISTIC FINITE AUTOMATA(DFA)
05/01/2023 Abhimanyu Mishra(CSE) JETGI
A.1 PROCESSING OF STRINGS BY DFA
• Suppose a1,a2,………………… an is a sequence of input
symbols. We start out with deterministic finite automata having q1,q2,………………… qn states where q0 is the initial state and qn is the final state and transition function and processed as………..
δ(q0, a1 ) = q1
δ(q1, q2 ) = q2
. . . . δ(qn-1 , qn ) = qn Input a1,a2,………………… an is said to be “accepted” since qn is the member of the final states, and if not then it is “ rejected”
05/01/2023 Abhimanyu Mishra(CSE) JETGI
A.2 TRANSITION GRAPH
• A transition graph is a collection of three things:1. A finite set of states, at least one of which is designated as the start state. start state
final state
2. An alphabet Σ of possible input letters from which input strings are formed.
3. A finite set of transitions that show how to go from some states.
05/01/2023 Abhimanyu Mishra(CSE) JETGI
A.3 TRANSITION DIAGRAM
Transition Diagram Notations: A transition diagram for DFA, M=(Q,Σ, δ,q0,F) is a graph defined as follows:
(a) For each state in Q there is a node represented by the circle.(b) For each state q in Q and each input symbol a in Σ, let δ(q,a)=P. a a a,b or or b
(c) If any state q in Q is the starting state then it represented by the circle with arrow as
q P q P q P
q
05/01/2023 Abhimanyu Mishra(CSE) JETGI
A transition table is a conventional, tabular representation of a function like δ that takes two arguments and return a state. The rows of the table correspond to the states, and the columns correspond to the input.State δ(q,a). For example:
q0 is the starting state and q2 is the final state
A.4 TRANSITION TABLES
δ/ Σ a b
q0 q1 q2
q1 q2 q0
q2 q2 q2
05/01/2023 Abhimanyu Mishra(CSE) JETGI
And the transition diagram:
b a
a
a,b
Q={q0, q1, q2 }F={q2 }δ(q0 , a) = q1 , δ(q0 , b) = q2
δ(q0 , a) = q2 , δ(q0 , b) = q0
δ(q0 , a) = q2 , δ(q0 , b) = q2
q0
q0
q1
q2
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Example 1:-• Design a FA that accepts set of strings such that every string end in 00, over
alphabet: {0,1} Σ = { 0,1}
Sol:- We have M= (Q,Σ, δ,q0,F) be the DFA q0 : initial state, Σ : {0,1} is given
0,1 Start 0 0
First we will decide the approach to design FA. It is not an easy task to think FA as a whole, So first we have to fulfill minimum condition i.e every string end in 00.
q0 q1q2
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Facts in Designing Procedure of Finite Automata
(a) In the designing of FA, First of all we have to analyze the set strings language which is accepted by the FA.
(b) Make sure that every state is check for the output state for every symbol of Σ.
(c) Make sure, that there is one initial state and at least one final state in transition diagram of FA.
(d) Make sure that no state must have two different output state for a single input symbol.
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Nondeterministic finite automaton with ε-moves (NFA-ε) is a further simplification to NFA. this automaton replaces the transition function with the one that allows the empty string ε as a possible input. the transitions without overwhelming an input symbol are called ε-transitions.
Let M be NFA then M is Defined as: M = (Q,Σ, δ,q0,F)(1) a finite set of states q0
(2) a finite set of input symbol Σ(3) a transition function δ : q × Σ → P(q).(4) an initial (or start) state q0 Q∈(5) a set of states f distinguished as accepting (or final) states F Q⊆
(B) NON DETERMINISTIC FINITE AUTOMATA(NDFA)
05/01/2023 Abhimanyu Mishra(CSE) JETGI
0,1
0,1 0 0
START 0,1
1 1
according to analysis it is clear that NFA will accepts the strings of the pattern 00,11,101000,101100,……………………..
Example 1: Design a NFA for the language L= all strings over {0,1} that have at least two consecutive 0 and 1.
q0
q1
q2
q2
q4
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Procedure for converting NFA to equivalent DFA.1) intially Q=ɸ.2) Put {q0 } into Q.3) Then for each state q in Q do the following add this new state, add δ(q,a) = ᴜp€q δ(p,a) to δ on the right hand side is that of NFA4) Repeat step 3 till new states.
TRANSFORMATION OF NFA TO DFA
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Example:1 Convert the following NFA in to DFA
a,b b• Start a a a,b b
q0
q3
q2q1
05/01/2023 Abhimanyu Mishra(CSE) JETGI
SolutionStep 1 ( We get new state)δ(q0, a ) = {q0, q1 } New single state δ(q0, b ) = {q0 }Step 2 In step 1 we are getting a new state {q0, q1 }. Now repat step 1 for this
new state only, so all transition of a and b from {q0, q1 } as δ({q0 , q1 },a) = δ(q0, a ) U δ(q1, a ) = {q0, q1 } U {q0 } = {q0, q1, q2 } New single state δ({q0 , q1 },b) = δ(q0, b ) U δ(q1, b ) = {q0, q1 } Step3 Repeat step 2 δ({q0 , q1, q2 },a) = δ(q0, a ) U δ(q1, a ) U δ(q2, a) = {q0, q1 } U {q2 }U {q3 } = {q0 , q1, q2, q3 } New single state
δ({q0 , q1, q2 },b) = δ(q0, b ) U δ(q1, b ) U δ(q2, b) = {q0 , q1, q3 } New single state
05/01/2023
Step 4: Repeat Step 3 δ({q0 , q1, q2, q3 },a) = {q0 , q1, q2, q3 } OLD STATE δ({q0 , q1, q2, q3 },b) = {q0 , q1, q2, q3 } OLD STATE Step 5: Repeat Step 4 δ ({q0 , q1, q3 },a) = {q0 , q1, q2, q3 } OLD STATE δ ({q0 , q1, q3 },b) = {q0 , q1, q2, q3 } OLD STATE Now Transition table
δ/ Σ a b
q0 {q0, q1 } {q0 }
{q0, q1 } {q0, q1, q2 } {q0, q1 }
{q0, q1, q2 }* {q0 , q1, q2, q3 } {q0 , q1, q3 }
{q0 , q1, q2, q3 }* {q0 , q1, q2, q3 } {q0 , q1, q2, q3 }
{q0 , q1, q3 }* {q0 , q1, q2, q3 } {q0 , q1, q2, q3 }
Abhimanyu Mishra(CSE) JETGI
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Lets Mark the whole structure in Alphabets
q0 A
{q0, q1 } B
{q0, q1, q2 } C
{q0 , q1, q2, q3 } D
{q0 , q1, q3 } E
05/01/2023 Abhimanyu Mishra(CSE) JETGI
A is initial state and C,D and E are final states since they contain q2, q3 as member which are final states of NFA
• Transition Table
δ/ Σ a b A B A
B C B
*C D E
*D D D
*E D D
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Final Transition Diagram
• b b• Start a
• a
• b
• a a• b• a,b
A
D
E
C
B
05/01/2023 Abhimanyu Mishra(CSE) JETGI
NFA with -Transitions ∈
• IF a FA is modified to permit transition without input symbols, along with zero, one or more transition on input symbols, then we get NFA with -∈transition, because the transition made without symbols are called as -∈transitions.
0 1 0 Start ∈ ∈
q0 q1q2
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Example:2 Consider the NFA with -transition M =(Q,Σ, δ,q∈ 0,F)Q={q0, q1, q2 }Σ={a,b,c} and moves∈Initial state ={q0 }F= { q2 }
δ/ Σ a b c ∈
q0 {q0} {ɸ} {ɸ} {q1}
q1 {ɸ} {q1} {ɸ} {q2}
*q2 {ɸ} {ɸ} {q2} {ɸ}
05/01/2023 Abhimanyu Mishra(CSE) JETGI
And the transition Diagram: NFA with -∈ transition
a b c
Start ∈ ∈ q0 q1q2
05/01/2023 Abhimanyu Mishra(CSE) JETGI
SOLUTION:- Step 1- Find the states of NFA without -transition including initial state and ∈ final states as follows:(i) Initial state will be -closure of initial state of NFA with -transitions in ∈ ∈ -closure(q∈ 0) = {q0, q1, q2 } (New Initial state for NFA without transition)∈(ii) Rest of the states are: -closure(q∈ 1) ={q1, q2 } New State -closure(q∈ 2) ={q2} New State(iii) The final states of NFA without -transition are all those new states which ∈ contains final state of NFA with - transition as members.∈ M’ =(Q’,Σ’, δ’,q0’,F’) Q’ =({q0, q1, q2 } ,{q1, q2 }, {q2} )Step 2-Now we have to decide δ’ to find out the transition as follows
δ’ ({q0, q1, q2},a) = -closure(δ(∈ q0, q1, q2 ),a) = -closure(δ(∈ q0, a)U(δ(q1, a)U(δ(q2, a)) = -closure(δ(∈ q0U ɸU ɸ) = -closure(∈ q0) = {q0, q1, q2 }
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Similarly, δ’ ({q0, q1, q2},b) = -closure(δ(∈ q0, q1, q2 ),b) = -closure(δ(∈ q0, b)U(δ(q1, b)U(δ(q2, b)) = -closure(δ(∈ ɸ U q1U ɸ) = -closure(∈ q1) = {q 1, q2 } δ’ ({q0, q1, q2},c) = -closure(δ(∈ q0, q1, q2 ),c) = -closure(δ(∈ q0, c)U(δ(q1, c)U(δ(q2, c)) = -closure(δ(∈ ɸ U ɸU q2) = -closure(∈ q2) = { q2}
So we write same for others, δ’ ({q1, q2},a) = ɸ δ’ ({q1, q2},b) = {q1, q2} δ’ ({q1, q2},c) = {q2} δ’ ({q2},a) = ɸ δ’ ({q2},b) = ɸ δ’ ({q2},c) = {q2}
05/01/2023 Abhimanyu Mishra(CSE) JETGI
So, transition table for NFA -transition will be as:∈
δ/ Σ a b c
{q0, q1, q2}* {q0, q1, q2} {q1, q2 } { q2}
{q1, q2 }* ɸ {q1, q2 } { q2}
{ q2}* ɸ ɸ { q2}
05/01/2023 Abhimanyu Mishra(CSE) JETGI
{q0, q1, q2} as qx
{q1, q2 } as qy
{ q2} as qz
• a b start b
c c
c
NFA without -transition∈
qx
qz
qy
05/01/2023 Abhimanyu Mishra(CSE) JETGI
MINIMIZATION ALGORITHM FOR DFA
(i) all states are unreachable from the initial state via any set of transition of DFA M are removed(ii) draw the transition tables for rest states, after removing the unreachable states(iii) split the transition table in two tables(iv) find the similar rows(v) Repeat the same process(vi) Now combined the Reduced tables, and removing non reachable states, dead states.
Minimization of DFA’S
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Example 1 : Minimize the DFA given below
• Start b a b
b a a b a a b a
a b a b b
q0
q4
q7
q6
q1
q0
q3
q2
05/01/2023 Abhimanyu Mishra(CSE) JETGI
STEP 1: Remove the unreachable states from the given DFA. the DFA given in diagram q3 is unreachable state so remove it.STEP 2: Draw the Transition table for rest states.
Solution :
δ/ Σ a b
q0 q5 q1
q1 q2 q6
*q2 q2 q0
q4 q5 q7
q5 q6 q2
q6 q7 q6
q7 q2 q6
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Step 3: Now divide rows of transition table in two sets as:• (i)
• (ii)
q0 q5 q1
q1 q2 q6
q4 q5 q7
q5 q6 q2
q6 q7 q6
q7 q2 q6
*q2 q2 q0
05/01/2023 Abhimanyu Mishra(CSE) JETGI
row 2 and row 6,are similar since q1 and q7 transit to same states on a and b, so skip of them row 6 then q7 is replaced by q1 in the rest
Step 4: Apply step 4 on both the sets individually. Now consider set (i)
q0 q5 q1
q1 q2 q6
q4 q5 q7
q5 q6 q2
q6 q7 q6
q7 q2 q6
05/01/2023 Abhimanyu Mishra(CSE) JETGI
q0 q5 q1
q1 q2 q6
q4 q5 q1
q5 q6 q2
q6 q4 q6
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Step 5 Repeat step 4 same processAgain Row 1 and Row 3 Similar
q0 q5 q1
q1 q2 q6
q4 q5 q1
q5 q6 q2
q6 q4 q6
q0 q5 q1
q1 q2 q6
q5 q6 q2
q6 q0 q6
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Step 6 Combined Set minimized setsNow below minimized Transition table.
δ/ Σ a b
q0 q5 q1
q1 q2 q6
q5 q6 q2
q6 q0 q6
*q2 q2 q0
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Transition Diagram of Minimized DFA
Start b b a b a a a b
b a
q6
q0
q2q5
q1
05/01/2023 Abhimanyu Mishra(CSE) JETGI
Myhill-Nerode theorem is used to eliminate useless states from a DFA.
Myhill-Nerode Theorem says the three statements are equivalent:
(i) The language L, a subset of Σ*, is accepted by a DFA (ii) L is the union of some of the equivalence classes of right invariant equivalence relation of finite index.(iii) Let equivalence relation RL be defined by: xRLy if and only if for all Z in Σ*, xz is in L exactly when yz is in L. Then RL is of finite index
THANKS
MYHILL-NERODE THEOREM