Professional Documents
Culture Documents
Syllabus: Types of Finite Automata: Non-Deterministic Finite Automata (NDFA), Deterministic finite automata
machines, conversion of NDFA to DFA, minimization of automata machines, regular expression, Arden’s theorem.
Meaning of union, intersection, concatenation and closure, 2-way DFA.
Unit Objective: Relate practical problems to languages, automata, computability and complexity. Constructs abstract
models of computing and check their power to recognize the language.
…………………………………………………………………………………………………………………………………………………………………………..
Finite Automata: An automaton with a finite number of states is called a Finite Automaton (FA) or FiniteState
Machine (FSM).
An automaton has a mechanism to read input, which is string over a given alphabet. This input isactually written on
an input tape /file, which can be read by automaton but cannot change it. Input file is divided into cells each of which
can hold one symbol. Automaton has a control unitwhich is said to be in one of finite number of internal states.
Related Terminologies:
Example: Σ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and‘d’ are symbols.
Example: If the language takes all possible strings of length 2 over Σ = {a, b},then L = {ab, bb, ba, bb
We claim that this language A is regular. In order to prove this, we have to construct a finite automaton M such that
A =L(M).
The FA reads the input string w from left to right and keep scanning on the number of 1’s
After scanning the entire string, it counts the number of 1’s to check whether it is odd or even
If the number of 1’s is odd then the string is acceptable otherwise it is rejected
Using this approach, the finite automaton needs a state for every integer i ≥ 0; indicating that the number of 1s read
so far is equal to i. Hence, to design a finite automaton that follows this approach, we need an infinite number of
states. But, the definition of finite automaton requires the number of states to be finite. A better, and correct
approach, is to keep track of whether the number of 1s read so far is even or odd. This leads to the following finite
automaton:
• The set of states is Q = {q0, q1}. If the finite automaton is in state q1, then it has an even number of 1’s; if it is in
state q0, then it has an odd number of 1’s.
• The start state is q0, because at the start, the number of 1’s read by the automaton is equal to 0, and 0 is even.
• The set F of accept states is F = {q1}.
This finite automaton M = (Q, Σ, δ, q0, F) can also be represented by its state diagram.
0 0
1
q0 1
q1
Transition Graph: it is a finite directed labeled graph in which each vertex (or node) represent a state and the
directed edges indicate the transition of state. Edges are labeled with input symbol.
Transition Matrix: It is two-dimension matrixes between states of automata and Input symbol. Elements of matrix
are state form mapping (Σ X Q) into Q.
Deterministic automaton is one in which each move (transition from one state to another) is uniquelydetermined by
the current configuration. If the internal states input and contents of the storage are known it is possible to predict
the next (future) behavior of the automaton.
DFA can be represented by Transition Graph and Transition Diagram as shown in Table 1.1 and Figure 1.4
In NDFA, for a particular input symbol, the machine can move to any combination of thestates. In other words, the
exact state to which the machine moves cannotbe determined. Hence, it is called Non-deterministic Automaton.
2. when processing a string in DFA , there is always In NDFA several choices may exist for the next
a unique state to go next when each character is state. Can move to more than one states.
read. It is because for each state in DFA , there
is exactly one state that corresponds to each
character being read.
3. DFA can not use empty string transition. NDFA can use empty string transition.
4. In DFA we cannot move from one state to NDFA allows € (null) as the second argument of
another without consuming a symbol. the transition function. This means that the
NDFA can make a transition without consuming
an input symbol.
5 For every symbol of the alphabet, there is only We do not need to specify how does the NDFA
one state transition in DFA. react according to some symbol.
6 DFA can understood as one machine. NDFA can be understood as multiple title
machines computing at the same time.
7 DFA will reject the string if it end at other than If all the branches of NDFA dies or rejects the
accepting state string, we can say that NDFA reject the string.
10 For every input and output we can construct It is not possible to construct an NDFA machine
DFA machine. for every input and output.
3.
Transition Function Maps Q → (∑∪{λ}→2Q), the number of next states Q × ∑→Q, the number of
is zero or one or more. next states is exactly one
4. Time complexity
The time needed for executing an input string is The time needed for
more as compare to DFA. executing an input string is
less as compare to NFA.
Theorem
Let M = (Q, Σ, δ, q0, F) be a non-deterministic finite automaton. There exists a deterministic finite automaton M', such
that L(M') =L(M).
i.e. for every NDFA there exists a DFA which simulates the behavior of NDFA. Hence if language L is accepted by
N9DFA, then there exist a DFA M' which also accept L. Where M' = (Q', Σ, δ', q' 0, F’)
In NFA, when a specific input is given to the current state, the machine goes to multiple states. It can have zero, one
or more than one move on a given input symbol. On the other hand, in DFA, when a specific input is given to the
current state, the machine goes to only one state. DFA has only one move on a given input symbol.
Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the language L(M). There should be equivalent DFA denoted by M' =
(Q', ∑', q0', δ', F') such that L(M) = L(M').
Steps for converting NFA to DFA:
Step 1: Initially Q' = ϕ
Step 2: Add q0 of NFA to Q'. Then find the transitions from this start state.
Step 3: In Q', find the possible set of states for each input symbol. If this set of states is not in Q', then add it to
Q'. Step 4: In DFA, the final state will be all the states which contain F (final states of NFA)
Example 1:
Convert the given NFA to DFA.
Figure No. 2.5 Transition Graph
Solution: For the given transition diagram we will first construct the transition table.
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
Minimization of DFA
Minimization of DFA means reducing the number of states from given FA. Thus, we get the FSM(finite state machine)
with redundant states after minimizing the FSM.
We have to follow the various steps to minimize the DFA. These are as follows:
Step 1: Remove all the states that are unreachable from the initial state via any set of the transition of DFA.
Step 3: Now split the transition table into two tables T1 and T2. T1 contains all final states, and T2 contains non-final
states.
that: 1. 1. δ (q, a) = p
2. 2. δ (r, a) = p
That means, find the two states which have the same value of a and b and remove one of them.
Step 5: Repeat step 3 until we find no similar rows available in the transition table T1.
Step 7: Now combine the reduced T1 and T2 tables. The combined transition table is the transition table of minimized
DFA.
Example:
Figure 2.7: Transition Graph
Solution: Step 1: In the given DFA, q2 and q4 are the unreachable states so remove them.
Step 2: Draw the transition table for the rest of the states.
State 0 1
→q0 q1 q3
q1 q0 q3
*q3 q5 q5
*q5 q5 q5
Step 3: Now divide rows of transition table into two sets as:
1. One set contains those rows, which start from non-final states:
State 0 1
q0 q1 q3
q1 q0 q3
2. Another set contains those rows, which starts from final states.
State 0 1
q3 q5 q5
q5 q5 q5
State 0 1
q3 q3 q3
State 0 1
→q0 q1 q3
q1 q0 q3
*q3 q3 q3
Regular Expression
The language accepted by finite automata can be easily described by simple expressions called Regular
Expressions. It is the most effective way to represent any language.
The languages accepted by some regular expression are referred to as Regular languages.
A regular expression can also be described as a sequence of pattern that defines a string.
Regular expressions are used to match character combinations in strings. String searching algorithm used this
pattern to find the operations on a string.
For instance:
In a regular expression, x* means zero or more occurrence of x. It can generate {e, x, xx, xxx, xxxx,....}
In a regular expression, x+ means one or more occurrence of x. It can generate {x, xx, xxx, xxxx,....}
Proof −
Proof −
Let us take two regular expressions RE1 = a(a*) and RE2 = (aa)*
So, L1 = { a,aa, aaa, aaaa,} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,} (Strings of even length including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,} (Strings of even length excluding Null)
RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself. Property 3. The complement of a regular set is regular. Proof −
Let us take a regular expression − RE = (aa)*
So, L = {ε, aa, aaaa, aaaaaa,} (Strings of even length including Null)
Complement of L is all the strings that is not in L.
So, L1 = {a, aa, aaa, aaaa,....} (Strings of all possible lengths excluding Null)
Proof −
RE (L) = 01 + 10 + 11 + 10
RE (L) = a (aa)*
f−
E1 = (0+1)*0 and RE2 = 01(0+1)*
, L1 L2 = {001,0010,0011,0001,00010,00011,1001,10010,}
f strings containing 001 as a substring which can be represented by an RE − (0 + 1)*001(0 + 1)* Identities Related to Regular Expressions
n R, P, L, Q as regular expressions, the following identities hold −
ε
ε
RR* = R*R
R*R* = R*
(R*)* = R*
RR* = R*R
(PQ)*P =P(QP)*
R + R = R (Idempotent law)
ε + RR* = ε + R*R = R*
Note: Two regular expressions are equivalent if languages generated by them are same. For example, (a+b*) * and
(a+b) * generate same language. Every string which is generated by (a+b*) * is also generated by (a+b)* and vice
versa.
Example 1:
Write the regular expression for the language accepting all combinations of a's, over the set ∑ = {a}
Solution:
All combinations of a's mean a may be zero, single, double and so on. If a is appearing zero times, that means a null
string. That is, we expect the set of {ε, a, aa, aaa,....}. So, we give a regular expression for this as:
1. R = a*
Example 2:
Write the regular expression for the language accepting all combinations of as except the null string, over the set ∑ =
{a}
Solution:
This set indicates that there is no null string. So, we can denote regular expression as:
R = a+
Example 3:
Write the regular expression for the language accepting all the string containing any number of a's and b's.
Solution:
1. r.e. = (a + b) *
This will give the set as L = {ε, a, aa, b, bb, ab, ba, aba, bab.. .}, any combination of a and b.
The (a + b) * shows any combination with a and b even a null string.
Conversion of RE to FA
To convert the RE to FA, we are going to use a method called the subset method. This method is used to obtain FA
from the given regular expression. This method is given below:
Step 1: Design a transition diagram for given regular expression, using NFA with ε moves.
Example 1:
Design a FA from given regular expression 10 + (0 + 11)0* 1.
Solution: First we will construct the transition diagram for a given regular expression.
Step 1:
Step 2:
Step 3:
Step 4:
Figure 2.11: Transition Graph
Step 5:
Now we have got NFA without ε. Now we will convert it into required DFA for that, we will first write a transition
table for this NFA.
State 0 1
q1 qf ϕ
q2 ϕ q3
q3 q3 qf
*qf ϕ ϕ
State 0 1
→[q0] [q3] [q1, q2]
[q1] [qf] ϕ
[q2] ϕ [q3]
[q3] [q3] [qf]
[q1, q2] [qf] [qf]
*[qf] ϕ ϕ
Table 2.10: Transition Table/Matrix
Construction of an FA from a RE
Method
Step 1 Construct an NFA with Null moves from the given regular expression.
Step 2 Remove Null transition from the NFA and convert it into its equivalent DFA.
Problem
Solution
Now we will remove the ε transitions. After we remove the ε transitions from the NDFA, we get the following −
It is an NDFA corresponding to the RE − 1 (0 + 1) * 0. If you want to convert it into a DFA, simply apply the method of
converting NDFA to DFA
Applications:
Regular expressions are useful in a wide variety of text processing tasks, and more generally string processing,
where the data need not be textual. Common applications include data validation, data scraping (especially web
scraping), data wrangling, simple parsing, the production of syntax highlighting systems, and many other tasks.
While regexps would be useful on Internet search engines, processing them across the entire database could
consume excessive computer resources depending on the complexity and design of the regex.
Arden’s Theorem:
In order to find out a regular expression of a Finite Automaton, we use Arden’s Theorem along with the properties of
regular expressions.
Statement:
Let P and Q be two regular expressions.
If P does not contain null string, then R = Q + RP has a unique solution that is R = QP*
Proof:
R = Q + (Q + RP) P [After putting the value R = Q + RP]
R= Q + QP + RPP
When we put the value of R recursively again and again, we get the following equation:
R = Q + QP + QP2 + QP3….
R = Q (є + P + P2 + P3 + ….)
R = QP* [As P* represents (є + P + P2 + P3 + ….)]
Hence, proved.
Following algorithm is used to build the regular expression form given DFA.
1. Let q1 be the initial state.
2. There are q2, q3, q4........qn number of states. The final state may be some qj where j<= n.
Example:
Construct the regular expression for the given DFA
Solution:
Let us write down the equations
q1 = q1 0 + ε
Since q1 is the start state, so ε will be added, and the input 0 is coming to q1 from q1 hence we write
State = source state of input × input coming to it
Similarly,
q2 = q1 1 + q2 1
q3 = q2 0 + q3 (0+1)
Since the final states are q1 and q2, we are interested in solving q1 and q2 only. Let us see q1 first
q1 = q1 0 + ε
We can re-write it as
q1 = ε + q1 0
Which is similar to R = Q + RP, and gets reduced to R = OP*.
Assuming R = q1, Q = ε, P = 0
We get
q1 = ε. (0) *
q1 = 0* (ε.R*= R*)
Substituting the value into q2, we will get
q2 = 0* 1 + q2 1
q2 = 0* 1 (1) * (R = Q + RP → Q P*)
The finite automata discussed so far has a δ transition which indicate where to next from current state on receiving
particular input. But 2-way FA is a model in which linear direction is mentioned on receiving particular and being in
some current state. There are two direction that are allowed in 2-FA and these are left and right direction.
Input tap
States 0 1
q1
( q1, R ) ( q2, L )
(Final State)
q2 ( q0, R ) ( q2, L )
Kleene Closure : If L1 is context free, its Kleene closure L1* will also be context free. For example,
L1 = { anbn | n >= 0 }
L1* = { anbn | n >= 0 }* is also context free.
Note :So CFL are closed under Kleen Closure.
Intersection and complementation : If L1 and If L2 are two context free languages, their intersection L1 ∩ L2 need not be
context free. For example,
L1 = { anbncm | n >= 0 and m >= 0 } and L2 = (ambncn | n >= 0 and m >= 0 }
L3 = L1 ∩ L2 = { anbncn | n >= 0 } need not be context free.
L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. Their
intersection says both conditions need to be true, but push down automata can compare only two. So it cannot be
accepted by pushdown automata, hence not context free.
Similarly, complementation of context free language L1 which is ∑* – L1, need not be context free.
Note : So CFL are not closed under Intersection and Complementation.