FLAT - Ch.2
FLAT - Ch.2
FLAT - Ch.2
y
Prof. Sachin Jain,Prof.Atul kumar,Prof. vaibhavi Patel
Assistant Professor
Computer Science & Engineering
CHAPTER-2
Regular Language and Finite Automata
Regular Expression
What is Regular Expression?
• An expression which is constructed over alphabet ∑ using the operators * , . ,
+ is called as regular expression.
• For every regular language we can construct an equivalent R.E.
• Regular Operator
▪ The operators * , . , + are called regular operators
* is kleen closure operator
. is concatenation operator
+ is union operator
• Operator precedence
I. Including € r=(a+b)*
II. Excluding € r=(a+b)+
III. Where each string start with ab r=ab(a+b)*
IV. Where each string end with ab r=(a+b)* ab
V. Contain substring aba r=(a+b)* aba (a+b)*
VI. Start and end with a r=a (a+b)* a +a
VII. Third symbol from LHS is a r= (a+b) (a+b) (a+b)(a+b)*
Finite Automata
Definition (DFA)
• It is finite state automata which is used to accept or reject a sequence
of string
• In DFA, for each input symbol, there must be only one state. Hence, it is
called Deterministic Automaton. As it has a finite number of states, the m
achine is called Deterministic Finite Machine or Deterministic Finite Auto
maton.
• Now we will satisfy all state with every input and then we will get
Construction of DFA (Example)
• Construct DFA which ends with “b”, given input symbol {a , b}
• DFA will start with “a” and “b” both but necessarily end with “b” only.
• L={b,ab,bb,aab,abab….}
• Minimal string = b
• After following above all rules we will get below designed DFA
Construction of DFA (Example)
• Construct DFA which starts and ends with same character, give
n input symbol {a , b}
• L={a,b,aa,bb,aba,bab,abba,baab…..}
• Minimal string = {a,b}
• After following above all rules we will get below designed DFA
Construction of DFA (Example)
• Draw a DFA for the language accepting strings starting with ‘ab’ over inp
ut alphabets ∑ = {a, b}
• L={101,1010101,1010000,…..}
• Minimal string = {101}
• After following above all rules we will get below designed DFA
Construction of DFA (Example)
• Construct a DFA that accepts a language L over input alphabets ∑ = {a, b}
such that L is the set of all strings starting with ‘aa’ or ‘bb’.
Empty string transitions are not seen in D NDFA permits empty string transitions.
FA.
Backtracking is allowed in DFA In NDFA, backtracking is not always possi
ble.
Requires more space Requires less space.
A string is accepted by a DFA, if it transits A string is accepted by a NDFA, if at least
to a final state. one of all possible transitions ends in a fin
al state.
Equivalence of NDFA and Regular Expression
• If a language is accepted by NDFA then L is denoted by a Regular
expression.
• Regular expression and Non-deterministic FA, both have the same com
putational power.
• For each and every regular expression we can design NDFA such that L(R
)=L(NF).
L(R)= Language accepted by regular expression
L(NF)= Language accepted by non-deterministic finite automat
a
Regular Grammar
Grammars
– Here,
• S and A are Non-terminal symbols.
• a and b are Terminal symbols.
• ε is an empty string.
• S is the Start symbol, S ∈ N
• Production P : S → aAb, aA → aaAb, A → ε
Derivations from a Grammar
• Strings may be derived using the productions in a grammar.
• For Example
Let us consider the grammar −
G2 = ({S, A}, {a, b}, S, {S → aAb, aA → aaAb, A → ε } )
Note: We have added ε because either you could continue the derivatio
n or would like to stop it. So to stop the derivation we have written
ε
Example: FA → RLG
Steps:
Pick start state a
nd output is on s
ymbol 'a' we are So we will write as :
going on state B
A -> aB
Example: FA → RLG
Steps:
And then we will
pick state B and t so we will get the bel
hen we will go for ow production.
each output.
B -> aB/bB/ε
• B is final state so we have t
o add ε
Example: FA → RLG
Final answer:
So final we got ri
ght linear gramm
ar as: A -> aB
B -> aB/bB/ε
Equivalence with finite automata: FA → LLG
Remove unreacha
ble states
Example: FA → LLG
Step 2:Then write right linear grammar following the previous lesson
Formula
FA -> Reverse of FA -> Right Linear Grammar -> Reverse of Right Linear Gram
ar = Left Linear Grammar
Equivalence with finite automata: RLG → FA
• A -> aB/bA/b
• B -> aC/bB
• C -> aA/bC/a
Equivalence with finite automata: LLG → FA
• Steps for Converting left linear grammar to Finite Automata:
Formula
Left Linear Grammar -> Reverse of left Linear Grammar-> FA -> Reverse of FA
Example: LLG → FA
Step 1:
Step 2:
Step 3:
Now take revers
e of the above F
A (this is final out
put)
•Closure properties.
1.Decision properties.
Properties of regular languages: Closure properties
• Closure properties on regular languages are defined as certain operatio
ns on regular language which are guaranteed to produce regular language
.
• Proof:
– Construct a DFA for 𝐿
– This can be transformed into a DFA for 𝐿 by making all accepting st
ates non-accepting and vice versa.
Closure properties: Closure under Reversal
1.Emptiness
2.Finiteness
3.Equivalence
4.Membership
Decision properties: Emptiness and Non-emptiness
• Algorithm:
– Select the state that cannot be reached from the initial states & delete th
em (remove unreachable states).
– If the resulting machine contains at least one final states, so then the finit
e automata accepts the non-empty language.
– if the resulting machine is free from final state, then finite automata acce
pts empty language.
Decision properties: Finiteness and Infiniteness
• Algorithm:
– Select the state that cannot be reached from the initial state & delete the
m (remove unreachable states).
– Select the state from which we cannot reach the final state & delete them
(remove dead states).
– If the resulting machine contains loops or cycles then the finite automata
accepts infinite language.
– If the resulting machine do not contain loops or cycles then the finite auto
mata accepts finite language.
Decision properties: Equivalence
• Algorithm:
– Convert 𝐿1 and 𝐿2 to DFAs.
– Convert 𝐿1 and 𝐿2 to minimal DFAs. (Refer slide no 40 )
– Determine if the minimal DFAs are the same.
Decision properties: Membership
Examples:
101 ⇒ 1(01)*
000001 ⇒ (0)*1
110100 ⇒ 1(1)*0100
Pumping lemma for regular languages
Application:
• The pumping lemma is extremely useful in proving that cert
ain sets are non-regular. The general methodology followed d
uring its applications is :
Choose s to be 0p1p.
1.y is only 0s. xyyz has more 0s than 1s, thus a contradiction via con
dition 1 of PL.
2.y is only 1s. Also a contradiction.
3.y is both 0s and 1s. xyyz may have same number of 1s and 0s, but
will be out of order, with some 1s before 0s, also a contradiction.
•For ant regular language, more than one DFA can possible bu
t there is only one minimal DFA for that language.
Minimization of finite automata: Equivalence Theorem
• Step 1:
– Eliminate all the inaccessible(unreachable) states from the given DFA (if any).
• Step 2:
– Draw the transition table for all pair of states.
• Step 3:
– We will divide Q (set of states) into two sets. One set will contain all final states and
other set will contain non-final states. This partition is called P0 (0 equivalence)
• Step 4:
– Initialize k = 1
Minimization of finite automata: Equivalence Theorem
• Step 5:
– Find Pk by partitioning the different sets of Pk-1.
– In each set of Pk-1, we will take all possible pair of states.
– If two states of a set are distinguishable, we will split the sets into differen
t sets in Pk.
• Step 6:
– Stop when Pk = Pk-1 (No change in partition)
• Step 7:
– All states of one set are merged into one. No. of states in minimized DFA
will be equal to no. of sets in Pk.
Minimization of finite automata: Equivalence Theorem
P0 = { q0 , q1 , q2 , q3 } { q4 }
P1 = { q0 , q1 , q2 } { q3 } { q4 }
P2 = { q0 , q2 } { q1 } { q3 } { q4 }
P3 = { q0 , q2 } { q1 } { q3 } { q4 }
P0 = { q0 } { q1 , q2 }
P1 = { q0 } { q1 , q2 }
From P1, we infer that states q1 and q2 are equivalent and can be m
erged together.
So, Our minimal DFA is-
Exercise