FLAT Unit-I Lecture Notes
FLAT Unit-I Lecture Notes
Coverage Topics:
1
1. Central Concepts of Automata Theory:
1.1 Symbol:
A symbol is the smallest building block (an abstract entity), which can be any alphabet,
letter, or any picture.
Example: Frequently used symbols are: a, b, c, ……, z, A, B,……,Z, 0, 1, …..9
1.2 Alphabet:
An alphabet is a finite set of symbols. It is denoted by Σ(Sigma).
Example: Frequently used alphabets are:
Σ = {0,1} is an alphabet of binary digits
Σ = {0,1,2,….9} is an alphabet of decimal digits
Σ = {a,b,c} is one alphabet
Σ = {A,B,C,….,Z} is an alphabet of Capital Letters
Σ = {0,1,a,b} is one alphabet
1.3 String:
A string is a finite sequence of symbols chosen from some alphabet. It is generally
denoted by w and string is also called a word.
Examples:
a , b , aa , ab , ba , …… are the strings from the alphabet Σ={a,b}
01101 is a string from the binary alphabet Σ={0,1}
2
1.3.2 Powers of Σ (Powers of an alphabet):
Let Σ be an alphabet, then ΣK is nothing but set of all strings of length K, over Σ.
If Σ={a,b}
Σ1 is nothing but set of all strings over Σ of length ‘1’
Σ1 ={a,b} and total strings is: |Σ1| = 2
Σ+ = Σ1 U Σ2 U Σ3................ Σn
Σ+ = {{a,b} U {aa,ab,ba,bb} ..................... }
3
1.3.6 Substring:
A part of a string is called a substring.
Examples:
1. Set of all strings of length 2 that can be generated over the alphabet Σ ={a,b}
L1 = {aa, ab, ba, bb} // This is a “Finite Language”
2. Set of all strings which start with a that can be generated over the alphabet Σ ={a,b}
L2 = {a, aa, ab, aab, aba, aaa, ………………} //This is an “Infinite Language”
3. Set of all strings which end with 0, that can be generated over the alphabet Σ ={0,1}
L3 = {0, 00, 10, 000, 010, 100, 110, ………………} //This is an “Infinite Language”
Note:
2. L={} that is an empty set is also a valid language; it is called empty language. It
is denoted by Φ(phi).
3. L={ε} is the set consisting of an empty string(epsilon) is also a valid language but not
an empty language.
5
digital computers to recognize patterns(languages). It is a recognizer for regular languages.
Note:
Abstract means existing in thought or as an idea but not having a physical existence.
A device need not even be a physical hardware.
An automaton with finite states is called a Finite Automaton (FA) or Finite State
Machine (FSM).
1.7.1 Formal Definition of Finite Automata:
Where:
1. Q is a finite set of states.
2. ∑ is a finite set of input symbols called the alphabet of the automaton.
∑ is called Sigma.
3. δ (delta) is the transition function which denotes the transition from one state to another
over an input symbol.
Ex: δ(q,a) = p, where q and p are states, a is an input symbol. The FA is in state q, and
upon reading an input symbol a, it goes to state p.
4. 𝑞0 is the initial state/starting state from where any input is processed (𝑞0 ∈ Q).
5. F is a set of final state/states (F ⊆ Q).
A transition diagram or state transition diagram is a special kind of flow chart or a directed
graph where the vertices correspond to the states of FA and edges correspond to transitions
from one state to another on an input symbol. Among the states, the first stage is denoted as
the initial state and is represented by an arrow before the vertex, and the final states are
denoted by double circles.
6
Example: A FA that all strings that begins with 1 is as follows:
In the above transition diagram, q0 is initial state, q1 is final state and q2 whenever it reaches,
the FA can never enter final state. So, this state is called either dead state or trap state. The
transitions over q1 are self-loop over 0,1.
Transition Table: Transition table for the above transition diagram is as follows:
2. For all strings w and input symbol a there exist the transitions:
A language is a regular set /language if it is the set accepted by some finite automata.
• They can describe the operation of a small device, like the control component of an alarm
clock or a microwave.
• They are also used in lexical analyzers to recognize well-formed expressions in
programming languages like XML:
• ab1 is a legal name of a variable in Java
• 5u= is not
• Similarly, the Email address is validated using simple Lexical analyzers.
8
1.8 Deterministic Finite Automata (DFA):
It is a Finite Automata in which exactly one transition should exist from every state on
every input symbol.
In DFA, one can determine the state to which the machine will move for each input
symbol. Hence, it is called Deterministic Automaton. The machine is called Deterministic Finite
Automaton because it has a finite number of states.
1.8.1 Definition of DFA: DFA consists of 5-tuples of
Where q0 is the initial state, q1 is the final state, and q2 is the dead or trap state.
9
The idea is very simple, follow the steps below, and you will understand.
1. Start with initial state q0, it is evident from the problem that the first transition must be
on ‘a’ as every string begins with ‘a’. Since ‘a’ also accepted string, the transitioned
state say q1 becomes the final state. Two states are confirmed: start/initial state and
final state i.e q0 and q1.
2. Once we reach the final state, the string accepts everything on ∑ so, we have a loop
on ‘a’ and ‘b’ input symbols.
3. And if the first input is something other than ‘a’ then string should not be accepted.
So, from q0 there a transition on ‘b’ to state q2 and is considered as dead/trap stae
having gone, the FA can never reach the final state.
10
1.9.2 Acceptance of String by NFA:
In DFA, the string is said to be accepted if the finite automata stop at a final
state after processing the entire string.
Since there is only one path, one can confirm acceptance deterministically.
In the case of NFA, for a string ‘w,’ multiple paths may exist for the given string;
some paths may lead to the final state(s), and some may not.
If at least we find a path that takes the finite automata to a final state after processing
the entire string, then we can conclude that NFA accepts the string ‘w’.
Example 1: Design a NFA which accepts set of all strings over an input alphabet
Σ={a,b}, that starts with ‘a’ and ends with ‘b’.
Ans: The given language is set of all strings over an alphabet Σ={a,b}, that start with ‘a’ and
end with ‘b’.
i.e L = {ab, aab, abb, aaab, aabb, abab, abbb, aaabb, aababbab, ….}, an infinite language as
there are infinite strings.
Transition Diagram:
Where q0 is the initial state, q1 is the intermediate state, and q2 is the final state.
Limitations of NFA:
11
Note:
12
1.10 Equivalence of NFA with DFA:
▶ A language L, described by some NFA, can also be described by some DFA.
▶ A DFA can have up to 2𝑛 states, while NFA has n states for the same language
▶ The subset construction method is used to prove the equivalence of DFA and NFA.
▶ 𝐹𝐷 is the set of all final states that contain the final states of 𝑄𝑁.
▶ 𝛿𝐷 is denoted as 𝑄𝐷 × ∑ → 𝑄𝐷
Step 1: Initialize QD = {[q0]} ( [q0] the initial state of MD where q0 - the initial state of MN )
Step 2: Then, find transitions over all input symbols in ∑ on the initial state of MD as:
𝛿𝐷 ([𝑞0], 𝑥) = [𝑞1, 𝑞2, 𝑞3,….. 𝑞𝑗] iff 𝛿𝑁 (𝑞0, 𝑥) = {𝑞1, 𝑞2, 𝑞3,….. 𝑞𝑗}
Then add [𝑞1, 𝑞2, 𝑞3,….. 𝑞𝑗] as a new state to the MD
i.e., in the MN, if the transitions take to multiple states, then combine all the states as a single
state and add as a new state to QD if not exist already.
Step 3: For every new state in QD, find the transitions on each input symbol as:
Step 4: Repeat step 3 until no more new states are added to QD.
Step 5: In the obtained DFA MD, make the state as final state when at least one state contains in
the states of FN (final states of NFA)
13
Example: Conversion of NFA to DFA
▶ Let M=({𝑞0, 𝑞1},{0,1},δ, 𝑞0,{𝑞1}) be NFA where δ(𝑞0, 0) = {𝑞0, 𝑞1}, δ(𝑞0, 1) = {𝑞1},
δ(𝑞1, 0) = ∅ ,δ(𝑞1, 1) = {𝑞0, 𝑞1}. Construct the equivalent DFA.
Solution: Let us draw a transition diagram & table for the given NFA
Step 4: Find the transitions for the new states with all the input symbols in ∑.
δD(([𝑞1],0) = ∅
δD(([𝑞1],1) = [𝑞0, 𝑞1]
δD(([𝑞0, 𝑞1], 0) = [𝑞0, 𝑞1]
δD(([𝑞0, 𝑞1], 1) = [𝑞0, 𝑞1].
Step 5: No new state is obtained from the above transitions. So, we will stop the process and
an equivalent DFA is obtained.
14
1.11 ε-NFA (NFA with ε-moves):
In general, for finite automata, there is no transition over ε i.e., 𝛿 (q, ε) = q and We can extend
the class of NFA’s by allowing instantaneous ε transitions. The automaton may change its
state without reading any input symbol.
ε -NFAs add a convenient feature, but (in a sense) they bring us nothing new. They do not
extend the class of languages that can be represented. Both NFA & ε -NFAs recognize the
same languages.
However, to distribute the design's complexity or enhance the reader's
understanding, the NFA can be extended by including transitions on ‘ε’. The final
automaton doesn’t include ‘ε’ transitions.
In obtaining finite automata from regular expressions, generally, the ε-NFA is only
produced.
Formally NFA with ε-moves defined as a 5-tuple machine M=(Q,∑, 𝛿, q0, F) where
3. 𝛿 - transition function Q × ∑ U { ε } → 2Q
i.e., 𝛿( q , a ) consisting of a state ‘p’ such that there is a transition labeled ‘a’
from q to p, where a is either ε or input symbol.
4. q0-initial state
5. F-Set of final states.
15
Example1: Design a ε-NFA (NFA with ε-moves) which accept set of all strings over an
input alphabet Σ={0,1, 2}, that any number of 0’s followed by any number of 1’s
followed by any number of 2’s.
Ans: The given language is set of all strings over an alphabet ={0,1, 2}, that any number of
0’s followed by any number of 1’s followed by any number of 2’s.
i.e L = { ε , 0, 1, 2, 00, 01, 02, 11, 12, 22, 011, 012, 0012, ……..000111122,....... }
Ex. For the string W = 012, the path sequence as follows: q0 (0) q0 (ε) q1 (1) q1 (ε) q2 (2) q2.
Any Finite automata with ε-moves is always a NFA with ε-transitions/moves as DFA can’t have
ε – transitions.
For constructing 𝛿 , it is important to compute the set of states reachable from a given state q
with ε – transitions only. To obtain those state we need to compute ε-closure from the state ‘q’.
ε-closure of a state or ε-closure(q) is defined as the set of all states reachable from a given
state q using ε-transitions only.
Redefining 𝛿 as follows:
1. 𝛿 (q, ε) = ε-closure (q)
2. 𝛿 (q, wa) = ε-closure (𝛿(𝛿 (𝑞, 𝑤), a))
Let DFA Mε = (𝑄ε, ∑, 𝛿ε, 𝑞0, 𝐹ε) be the ε-NFA and we need to construct its
equivalent NFA as MN (𝑄𝑁, ∑, 𝛿𝑁, 𝑞0, 𝐹𝑁).
In NFA is constructed the same way the moves of ε-NFA. So, all 𝑄𝑁, 𝛿𝑁, 𝑞0, 𝐹𝑁
are same as ε-NFA and the transitions are obtained by
Example
Convert the given NFA with epsilon to NFA without epsilon.
17
Solution
First find ε-closure of each state i.e., find ε-reachable states from the current state.
18
Now, we will summarize all the computed δN transitions as given state transition table as
States\inputs 0 1 2
q1 Φ {q1,q2} {q2}
q2 Φ Φ {q2}
▶ A DFA can have up to 2𝑛 states, while NFA has n states for the same language
▶ The subset construction method is used to prove the equivalence of DFA and NFA.
▶ 𝐹𝐷 is the set of all final states that contain the final states of 𝑄ε.
▶ 𝛿𝐷 is denoted as 𝑄𝐷 × ∑ → 𝑄𝐷
Step 2: Then, find transitions over all input symbols in ∑ on all the new states in QD of MD as:
𝛿𝐷 ([𝑞], 𝑥) = ε-closure(𝑞1, 𝑞2, 𝑞3,….. 𝑞𝑗) iff 𝛿ε(𝑞, 𝑥) = {𝑞1, 𝑞2, 𝑞3,….. 𝑞𝑗}
Then add [𝑞1, 𝑞2, 𝑞3,….. 𝑞𝑗] as a new state in QD of MD
19
Or
𝛿𝐷 ([𝑞0 𝑞1], 𝑥) = ε-closure( 𝛿ε(𝑞0, 𝑥) U 𝛿ε(𝑞0, 𝑥))
i.e., in the Mε, if the transitions take to multiple states, then find the ε-closure() on all states and
combine them as a single state and add as a new state to QD if not exist already.
Step 3: Repeat step 2 until no more new states are added to QD.
Step 4: In the obtained DFA MD, make the state as final state where at least one state contains
in the states of Fε (final states of NFA)
Example 1:
Solution:
Now, let ε-closure {q0} = {q0, q1, q2} so, make [q0 q1 q2] be the initial state and call it as A.
= ε-closure {q3}
= [q3] call it as state B.
20
δD ([q0 q1 q2], 1) = ε-closure {δ((q0, q1, q2), 1) }
= ε-closure {q3}
= [q3] = B.
= ε-closure {q4}
= [q4] i.e. state C
For state C:
21
Example 2:
Now we will obtain δ' transition. Let ε-closure(q0) = {q0, q1, q2} and make [q0 q1 q2] as
initiatial state and it as state A.
= ε-closure{q0}
= ε-closure{q1}
= [q1, q2] call it as state B
= ε-closure{q2}
= [q2] call it state C
1. δ'(A, 0) = A
2. δ'(A, 1) = B
3. δ'(A, 2) = C
22
The partial DFA will be:
Now we will find the transitions on states B and C for each input.
Hence
= ε-closure{ϕ} = ϕ
= ε-closure{q1}
= [q1, q2] i.e. state Bitself
= ε-closure{q2}
= [q2] i.e. state C itself
23
Now we will obtain transitions for C:
= ε-closure{ϕ} = ϕ
= ε-closure{ϕ} = ϕ
= [q2]
As A = [q0, q1, q2] in which final state q2 lies hence A is final state. B = [q1, q2] in which the
state q2 lies hence B is also final state. C = [q2], the state q2 lies hence C is also a final state.
24
1.12 Finite Automata with Output.
Finite automata may have outputs corresponding to each transition. Two types of finite state
machines that generate output are:
Mealy Machine
Moore machine
Next state
Present
input = 0 input = 1
state
State Output State Output
→a b x1 c x1
b b x2 d x3
c d x3 c x1
d d x3 d x2
25
The state transition diagram of the above Mealy Machine is −
Next State
Present
Output
state
Input = 0 Input = 1
→a b c x2
b b d x1
c c d x2
d d d x3
26
The state transition diagram of the above Moore Machine is −
Output depends both upon the present Output depends only upon the present
state and the present input state.
Generally, it has fewer states than Generally, it has more states than Mealy
Moore Machine. Machine.
The value of the output function is a The value of the output function is a
function of the transitions and the function of the current state and the
changes, when the input logic on the changes at the clock edges, whenever
present state is done. state changes occur.
Mealy machines react faster to inputs. In Moore machines, more logic is required
They generally react in the same clock to decode the outputs resulting in more
cycle. circuit delays. They generally react one
clock cycle later.
27
1.12.4 Converting Moore Machine to Mealy Machine
Input − Moore Machine
Output − Mealy Machine
Step 1 − Take a blank Mealy Machine transition table format.
Step 2 − Copy all the Moore Machine transition states into this table format.
Step 3 − Check the present states and their corresponding outputs in the Moore Machine state
table; if for a state Qi output is m, copy it into the output columns of the Mealy Machine state
table wherever Qi appears in the next state.
Example
Let us consider the following Moore machine −
Next State
Present
Output
State
a=0 a=1
→a d b 1
b a d 0
c c c 0
d b a 1
Next State
Present
a=0 a=1
State
State Output State Output
→a d b
b a d
c c c
d b a
Step 3 −
28
Next State
Present
a=0 a=1
State
State Output State Output
=> a d 1 b 0
b a 1 d 1
c c 0 c 0
d b 0 a 1
Example
Let us consider the following Mealy Machine −
Next State
→A d 0 b 1
B a 1 d 0
C c 1 c 0
D b 0 a 1
29
Here, states ‘a’ and ‘d’ give only 1 and 0 outputs respectively, so we retain states ‘a’ and ‘d’.
But states ‘b’ and ‘c’ produce different outputs (1 and 0). So, we divide b into b0,
b1 and c into c0, c1.
Next State
Present State Output
a=0 a=1
→a d b1 1
b0 a d 0
b1 a d 1
c0 c1 C0 0
c1 c1 C0 1
D b0 a 0
30