FLAT - Ch. 2 (Lecture Notes)
FLAT - Ch. 2 (Lecture Notes)
r=ф L = {}
r=€ L = {€}
r=a L = {a}
r = ab L = {ab}
r = (a+b) L = {a,b}
r = (a+b+c) L = {a , b , c}
r = w1 +w2 +w3 +…+wn L = { w1,w2,w3,…,wn }
= 0*
1. Construct the regular expression that generates all the string a’s and b’s
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)*
2. Construct the regular expression that generates all the string a’s and b’s
where the length of the string is
I. Exactly 3 r=(a+b)3
II. At least 3 r=(a+b)3 (a+b)*
III. At most 3 r=(a+b+ € )*
IV. Even r=[(a+b)2]*
V. Odd r=(a+b)[(a+b)2]*
VI. |w|≡2(mod 3) r =(a+b)2 [(a+b)3]*
3. Construct the regular expression that generates all the string a’s and b’s
where the number of a’s in the string is
I. Exactly 3 r=b*ab*ab*ab*
II. At most 3 r=b*(a+€ ) b*(a+€ ) b*(a+€ )b*
III. At least 3 r=(a+b)*a(a+b)* a(a+b)* a(a+b)*
IV. Even r=(b*ab*ab*)*b*
V. Odd r=(b*ab*ab*)*ab*
VI. |w|≡1(mod 3) r =b*ab*(b*a b*a b*ab*)*
Chapter:2 Deterministic Finite Automata
In DFA, for every single input symbol, user can determine the state to which the automata
will move. Therefore, it is called Deterministic Automaton. As DFA has a finite number
of states, the machine is called Deterministic Finite Machine or Deterministic Finite
Automaton.
Example
• Q = {a, b, c},
• ∑ = {0, 1},
• q0 = {a},
• F = {c}, and
Transition function δ as shown by the following table −
Present State Next state for input 0 Next state for input 1
a a b
b c a
c b c
In NDFA, for a specific input symbol, the automata can move to more than one state in
automata. In other words, the resultant state to which the automata moves cannot be
determined. Hence, it is called Non-deterministic Automaton. As it has finite number
of states, the machine is called Non-deterministic Finite Machine or Non-
deterministic Finite Automaton.
Example
• Q = {a, b, c}
• ∑ = {0, 1}
• q0 = {a}
• F = {c}
Present State Next state for input 0 Next state for input 1
a a,b b
b c a,c
c b,c c
The following table lists the differences between DFA and NDFA.
DFA NDFA
The transition from a state is to a single The transition from a state can be to
particular next state for each input multiple next states for each input symbol.
symbol. Hence it is called deterministic. Hence it is called non-deterministic.
Empty string transitions are not seen in NDFA permits empty string transitions.
DFA.
Example 1:-
Construct DFA which starts with “a”, given input symbol {a,b}.
➔ DFA which must Start with “a” but necessarily not with “b” i.e. If string will start from
“b” then input symbol “b” will move to dead state or trap state.
So, L={a,ab,abb,aab….}
Minimal string = a
Now we will have to satisfy each input symbol {a,b} at every state i.e. at q0 and qf.
We can observe that at q0 there is only one outgoing arrow with input symbol “a” so, we
need to satisfy input symbol “b” also and similarly we need to satisfy {a,b} at state qf
also. After above mentioned step 4 we will get:-
DFA which accepts all strings that will start with “a” and will reject all string starting with b
Example 2 :-
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 above steps we will get below designed DFA
Example 3:-
Construct DFA which starts and ends with same character, given input symbol {a,b}
➔ L={a,b,aa,bb,aba,bab,abba,baab…..}
After following above all rules we will get below designed DFA.
Example 4:-
Draw a DFA for the language accepting strings starting with ‘ab’ over input alphabets ∑
= {a, b}
After following above all rules we will get below designed DFA
Example 5:-
Draw a DFA for the language accepting strings starting with ‘101’ over input alphabets ∑
= {0, 1}
➔ L={101,1010101,1010000,…..}
After following above all rules we will get below designed DFA
Example 6:-
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’.
After following above all rules we will get below designed DFA
Example 6:-
Draw a DFA for the language accepting strings ending with ‘0011’ over input
alphabets ∑ = {0, 1}
L={0011,10011,110011,00011…..}
After following above all rules we will get below designed DFA
Equivalence of DFA and Regular Expression:-
Regular expression and Finite Automata, both have the same computational power.
For each and every regular expression we can design DFA such that L(R)=L(F).
where −
⮚ Example:
🞑 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 → ε
◻ The set of all strings that can be derived from a grammar is said to be the
language generated from that grammar.
◻ Regular Grammar generates Regular language which is accepted by Finite
automata.
◻ Regular Grammar also known as Type 3 grammar.
Regular grammars
⮚ Equivalence with finite automata: FA 🡪 RLG
Note: We have added ε because either you could continue the derivation or would like
to stop it. So to stop the derivation we have written ε
Example: FA 🡪 RLG
⮚ Equivalence with finite automata: FA 🡪 LLG
Example:
⮚ Equivalence with finite automata: RLG 🡪 FA
Example: RLG 🡪 FA
⮚ Equivalence with finite automata: LLG 🡪 FA
◻ Formula
Left Linear Grammar -> Reverse of left Linear Grammar-> FA -> Reverse of
FA
Example: LLG 🡪 FA
Properties of regular languages
1. Closure properties.
2. Decision properties.
⮚ Closure properties
◻ ””Closure “properties on regular languages are defined as certain operations on
regular language which are guaranteed to produce regular” language”.
◻ Let L and M be regular languages. Then the following languages are all regular:
🞑 Union: L ∪ M
🞑 Intersection: L ∩ M
🞑 Complement: L
🞑 Difference: L - M = L ∩ M
🞑 Concatenation: L . M
🞑 Reversal: LR
🞑 Kleen Closure: L∗
🞑 Positive Closure: L+
⮚ Decision properties
◻ Some examples:
❖Is 𝐿 empty?
❖Is 𝐿 finite?
1. Emptiness
2. Finiteness
3. Equivalence
4. Membership
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.”
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.”
⮚ Equivalence
Algorithm:
🞑 Convert 𝐿1 and 𝐿2 to DFAs.
🞑 Convert 𝐿1 and 𝐿2 to minimal DFAs.
🞑 Determine if the minimal DFAs are the same.
⮚ Membership:
◻ Let M is a finite automata that accepts some strings over an alphabet, and let ‘w’
be any string defined over the alphabet,
🞑 if there exist a transition path in M, which starts at initial state & ends in
anyone of the final state, then string ‘w’ is a member of M, otherwise ‘w’ is
not a member of M.”
Pumping lemma for regular languages
Important Ideas:
◻ Pumping:
◻ Pumping Length :
🞑 “All string in the language can be pumped if they are at least as long as a
certain special value, called the pumping length.”
“If A is a Regular Language, then there is a number p (the pumping length) where if s is
any string in A of length at least p, then s may be divided into 3 pieces, s = xyz,
satisfying the following conditions:
c. |xy| ≤ p.
◻ Application:
◻ The pumping lemma is extremely useful in proving that certain sets are non-
regular. The general methodology followed during its applications is :
🞑 Break the string s into x, y and z in accordance with the above conditions
imposed by the pumping lemma.
🞑 Now check if there is any contradiction to the pumping lemma for any
value of i.
Example: Use the pumping lemma to show that following language is not regular:
L = {0n1n|n>=1}
Choose s to be 0p1p.
Because s ∈ L and |s| ≥ p, PL guarantees s can be split into 3 pieces, s = xyz, where for
any i ≥ 0, xyiz ∈ L.
◻ Consider 3 cases:
1. y is only 0s. xyyz has more 0s than 1s, thus a contradiction via condition 1 of PL.
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.
◻ Contradiction is unavoidable, thus L is not Regular
◻ “DFA minimization stands for converting a given DFA to its equivalent DFA with
minimum number of states.”
◻ For ant regular language, more than one DFA can possible but there is only one
minimal DFA for that language.
⮚ Equivalence Theorem
Steps:
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
Step 5:
🞑 If two states of a set are distinguishable, we will split the sets into different
sets in Pk.
Step 6:
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.”
“Two states ( qi, qj ) are distinguishable in partition Pk if for any input symbol a, δ
( qi, a ) and δ ( qj, a ) are in different sets in partition Pk-1.”
Example1: minimize following DFA
Solution:
P0 = { q 0 , q 1 , q 2 , q 3 } { q 4 }
P1 = { q 0 , q 1 , q 2 } { q 3 } { q 4 }
P2 = { q0 , q2 } { q1 } { q3 } { q4 }
P3 = { q0 , q2 } { q1 } { q3 } { q4 }
From P3, we infer that states q0 and q2 are equivalent and can be merged
together.