Regular Languages and Finite Automata
Regular Languages and Finite Automata
Inst. Yoseph K.
yosefkrs@outlook.com
Introduction
Automata Theory is a branch of computer science that deals with designing
abstract self-propelled computing devices that follow a predetermined sequence
of operations automatically. An automaton with a finite number of states is
called a Finite Automaton.
The term "Automata" is derived from the Greek word "αὐτόματα" which means
"self-acting". An automaton (Automata in plural) is an abstract self-propelled
computing device which follows a predetermined sequence of operations
automatically.
An automaton with a finite number of states is called a Finite Automaton (FA)
or Finite State Machine (FSM).
The finite control unit exists in a one of a finite number of states. For each character that
is read the control unit either stays in the same state or moves to another state.
Finite automata are a useful model for many important kinds of hardware and
software.
2|Page
Finite Automaton can be classified into two types:
Example
• Q = {a, b, c},
• Σ = {0, 1},
• q0={a},
• F={c}, and
• Transition function δ as shown by the following table:
3|Page
Its graphical representation would be as follows:
2. How to present a DFA With a transition table? From the transition table design the
following transition diagram
Exercise
1. Build an automaton that accepts the words that contain 01 as a subword with Σ=
{0, 1} and L = {x01y | x, y ∈ Σ∗}. Use the following states
A: start
B: the most recent input was 1 (but not 01 yet)
C: the most recent input was 0 (so if we get a 1 next we should go
to the accepting state D)
D: we have encountered 01 (accepting state)
2. Draw the following DFA
Given: Q= {1,2,3,4}, Σ = {a,b,c}, q0 = {3}, F = {2,4}
δ a b c
1 1 3 2
2 4 1 3
3 4 3 1
4 2 1 2
4|Page
Non-deterministic Finite Automaton (NFA)
In NFA, for a particular input symbol, the machine can move to any combination of the
states in the machine. In other words, the exact state to which the machine moves cannot
be determined. Hence, it is called Nondeterministic Automaton. As it has finite number
of states, the machine is called Non-deterministic Finite Machine or Non-
deterministic Finite Automaton.
NFA has multiple start states more than one transition per input & multiple accept
states. For each state and each input symbol the NFA has 0 or more choices of next
move
Example
5|Page
Next State for Next State for
Present State
Input 0 Input 1
a a, b b
b c a, c
c b, c c
6|Page
Converting an NFA to an Equivalent DFA
Problem Statement:- Let X = (Qx, Σ, δx, q0, Fx) be an NFA which accepts the language
L(X). We have to design an equivalent DFA Y = (Qy, Σ, δy, q0, Fy) such that L(Y) = L(X).
The following procedure converts the NDFA to its equivalent DFA:
Algorithm 1
Input: An NDFA
An equivalent
Output:
DFA
Step 1 Create state table from the given NFA.
Create a blank state table under possible input
Step 2
alphabets for the equivalent DFA.
Mark the start state of the DFA by q0 (Same as
Step 3
the NFA).
Find out the combination of states {Q0, Q1,... ,
Step 4
Qn} for each possible input alphabet.
Step 5 Each time we generate a new DFA state under the
input alphabet columns, we have to apply step 4
again, otherwise go to step 6.
Step 6 The states which contain any of the final states of the
NFA are the final states of the equivalent DFA.
Example 1
let us consider the NFA shown in the figure below and convert it to its equivalent DFA.
Using Algorithm 1, we find its equivalent DFA. The transition table of the NFA is shown
below.
7|Page
δ 0 1
a {a, b, c, d, e} {d,e}
b {c} {e}
c Ø {b}
d {e} Ø
e Ø Ø
Then, after calculating the transition table for NFA we calculate the transition table of the
DFA (Reachable States).
The above transition table is a transition table of DFA which is equivalent to NFA.
Therefore, after getting the new reachable states we can simple design the converted DFA
diagram.
8|Page
Example 2
From what we have seen on class, convert the above NFA to its equivalent DFA.
9|Page
Solution:-
Step 2 – Find the reachable states from the NFA transition table
From the above steps we can simple design the new DFA state diagram.
Question – Why do we convert from one finite state machine to another state machine?
Q1 .What’s the advantage of converting an NFA state machine to its equivalent DFA state
machine?
10 | P a g e
Reading Assignment
Algorithm
Step 1: All the states Q are divided in two partitions: final states and nonfinal states
and are denoted by P0. All the states in a partition are 0th equivalent. Take a
counter k and initialize it with 0
Step 2: Increment k by 1. For each partition in Pk, divide the states in Pk into two
partitions if they are k-distinguishable. Two states within this partition X and Y are
k-distinguishable if there is an input S such that δ(X, S) and δ(Y, S) are (k-1)-
distinguishable.
Step 4: Combine kth equivalent sets and make them the new states of the reduced DFA.
Example on mDFA:
Given an NFA state machine try to convert it and minimize to its simplest form.
11 | P a g e
Using equivalence theorem, we basically construct a transition table and then classified
them in 0- equivalence, 1-equivalence and 2- equivalence.
δ a b
0 {1,2} 2
1 2 3
2 {1,2} 3
3 Ø Ø
1st Part– we should convert the transition table to its equivalent DFA.
δ a b
0 {1,2} 2
{1,2} {1,2} 3
2 {1,2} 3
3 Ø Ø
12 | P a g e
The second part will be minimizing to mDFA. So, let’s check the equivalence
theorem. The equivalence theorem is based on the number of input alphabets.
“1 equivalence” – arrange states which have only one equivalence and illuminate states
that reach to final state.
[0] [{1,2}, 2] [3] states {1,2} and {2} reaches to final state
From 2-equivalence, we can see that the states reduced from four states to three states
which are (0, {1,2}, 3). Then the final state diagram will be as given below.
Exercise
13 | P a g e
2. Minimize the following DFA
3. Minimize and check whether the following input string is accepted or rejected >(aa)
REGULAR GRAMMARS
Regular Expressions
14 | P a g e
R* is a Regular Expression corresponding to the language L(R*)
where L(R*) = (L(R))*
If we apply any of the rules several times from 1 to 5, they are Regular
Expressions. Let’s see some examples:
Regular Sets
Any set that represents the value of the Regular Expression is called a Regular
Set.
Question - Proof the above properties and check if they are true.
15 | P a g e
16 | P a g e