Flat CH 2
Flat CH 2
• 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
machine is called Deterministic Finite Machine or Deterministic Finite
Automaton.
• 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,
given 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
input 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’.
– 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 → ε } )
Steps:
Pick start state
and output is on
symbol '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 so we will get the
then we will go below production.
for each output.
B -> aB/bB/ε
• B is final state so we have
to add ε
Example: FA RLG
Final answer:
So final we got
right linear
grammar as: A -> aB
B -> aB/bB/ε
Equivalence with finite automata: FA LLG
Remove
unreachable states
Example: FA LLG
Step 2:Then write right linear grammar following the previous lesson
we will write
down "right linear
grammar" for it. B -> aB/bB/aA
A -> ε
Example: FA LLG
Step 3: Then take reverse of the right linear grammar
reverse the right linear
grammar to get the
ouput = left linear
B -> aB/bB/aA B -> Ba/Bb/Aa
Grammar
A -> ε A -> ε
Formula
FA -> Reverse of FA -> Right Linear Grammar -> Reverse of Right Linear
Grammar = 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
reverse of the
above FA (this is
final output)
1. Closure properties.
2. Decision properties.
Properties of regular languages: Closure properties
• Closure properties on regular languages are defined as certain
operations 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
states 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
them (remove unreachable states).
– If the resulting machine contains at least one final states, so then the
finite automata accepts the non-empty language.
– if the resulting machine is free from final state, then finite automata
accepts empty language.
Decision properties: Finiteness and Infiniteness
• Algorithm:
– Select the state that cannot be reached from the initial state & delete
them (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
automata 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
certain sets are non-regular. The general methodology
followed during its applications is :
Choose s to be 0p1p.
1. y is only 0s. xyyz has more 0s than 1s, thus a contradiction via
condition 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
but 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
different 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
merged together.
So, Our minimal DFA is-
Exercise