0% found this document useful (0 votes)
43 views16 pages

Regular Languages and Finite Automata

Uploaded by

cherkos welday
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views16 pages

Regular Languages and Finite Automata

Uploaded by

cherkos welday
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Microlink Information Technology College

Regular Languages and


Finite Automata

Lecture Note – Chapter Two

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).

Formal definition of a Finite Automaton

An automaton can be represented by a 5-tuple (Q, Σ, δ, q0, F), where:

 Q is a finite set of states.


 Σ is a finite set of symbols, called the alphabet of the automaton.
 δ is the transition function.
 q0 is the initial state from where any input is processed (q0 ∈ Q).
 F is a set of final state/states of Q (F ⊆ Q).

Deterministic and Nondeterministic Finite Automaton


The finite automaton is basically a very simple computer: an input tape, a tape reading
device, and a finite control unit. The input tape provides the string of symbols to be
computed. The tape reading device linearly reads the tape telling the control unit which
symbol is currently being read.

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.

 Software for designing and checking the behavior of digital circuits.


 The “lexical analyzer” of a typical compiler i.e. the compiler component that breaks the
input text into logical units such as identifiers, keywords, and punctuation.
 Software for scanning large bodies of text such as collection of web pages, to find
occurrences of words, phrases or other patterns.
 Software for verifying systems of all types that have a finite number of distinct states, such
as communications protocols or protocols for secure exchange of information.

2|Page
Finite Automaton can be classified into two types:

 Deterministic Finite Automaton (DFA)


 Non-deterministic Finite Automaton (NDFA / NFA)

Deterministic Finite Automaton (DFA)


In DFA, for each input symbol, one can determine the state to which the
machine will move. 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.

Formal Definition of a DFA

A DFA can be represented by a 5-tuple (Q, Σ, δ, q0, F) where:

• Q is a finite set of states.


• Σ is a finite set of symbols called the alphabet.
• δ is the transition function where δ: Q × Σ → Q
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).

Graphical Representation of a DFA

A DFA is represented by digraphs called state diagram.

• The vertices represent the states.


• The arcs labeled with an input alphabet show the transitions.
• The initial state is denoted by an empty single incoming arc.
• The final state is indicated by double circles.

Example

1. Let a deterministic finite automaton be →

• Q = {a, b, c},
• Σ = {0, 1},
• q0={a},
• F={c}, and
• Transition function δ as shown by the following table:

Next State for Next State for


Present State
Input 0 Input 1
A a b
B c a
C b c

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.

Formal Definition of an NFA

An NDFA can be represented by a 5-tuple (Q, Σ, δ, q0, F) where:

• Q is a finite set of states.


• Σ is a finite set of symbols called the alphabets.
• δ is the transition function where δ: Q × {Σ U ε} → 2Q
(Here the power set of Q (2Q) has been taken because in case of NDFA,
from a state, transition can occur to any combination of Q states)
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).

Graphical Representation of an NFA: (same as DFA)

An NFA is represented by digraphs called state diagram.

• The vertices represent the states.


• The arcs labeled with an input alphabet show the transitions.
• The initial state is denoted by an empty single incoming arc & the final state is
indicated by double circles

 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

Let a non-deterministic finite automaton be →


• Q = {a, b, c}
• Σ = {0, 1}
• q0 = {a}
• F={c}
• The transition function δ as shown below:

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

Its graphical representation would be as follows:

Question- Differentiate between DFA and NFA?

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

Convert the following NFA machine to its equivalent DFA.

From what we have seen on class, convert the above NFA to its equivalent DFA.

9|Page
Solution:-

Step 1 – Construct a transition table for the above NFA

Step 2 – Find the reachable states from the NFA transition table

Step 3 – Search NEW reachable states till no reachable state

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?

Deterministic Finite Automata Minimization

Q1 .What’s the advantage of converting an NFA state machine to its equivalent DFA state
machine?

10 | P a g e
Reading Assignment

“Equivalence theorem Vs Myhill-Nerode Theorem” – read on how equivalence theorem


and Myhill theorem works.

DFA Minimization using Equivalence Theorem


If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they
are not distinguishable. Two states are distinguishable, if there is at least one string S,
such that one of δ (X, S) and δ (Y, S) is accepting and another is not accepting. Hence, a
DFA is minimal if and only if all the states are distinguishable.

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 3: If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.

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 Ø Ø

From the above transition table,

1st Part– we should convert the transition table to its equivalent DFA.

2nd Part– then we can minimize them to their lowest form

Therefore, let’s convert the first part (Reachable States).

δ 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.

“0 equivalence “ – differentiate the normal states and the final states.

[0, {1,2}, 2] [3]

“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

“2 equivalence” – arrange states which have two equivalence

[0] [{1,2}, 2] [3] State {1,2} and {2} have 2 equivalence

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

1. Given a deterministic finite state machine, try to minimize it to its simplified


version.

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

A Regular Expression can be recursively defined as follows:

 ε is a Regular Expression indicates the language containing an empty


string. (L (ε) = {ε})
 φ is a Regular Expression denoting an empty language. (L (φ) = { })
 x is a Regular Expression where L={x}
 If X is a Regular Expression denoting the language L(X) and Y is a Regular
Expression denoting the language L(Y), then
 X + Y is a Regular Expression corresponding to the language
L(X) U L(Y) where L(X+Y) = L(X) U L(Y).
 X . Y is a Regular Expression corresponding to the language
L(X) . L(Y) where L(X.Y)= L(X) . L(Y)

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 Expression Regular Set

(0+10*) L= { 0, 1, 10, 100, 1000, 10000, … }

(0*10*) L={1, 01, 10, 010, 0010, …}

(0+ε)(1+ ε) L= {ε, 0, 1, 01}


Set of strings of a’s and b’s ending with the string abb,
(a+b)*abb So L = {abb, aabb, babb, aaabb, ababb, …………..}

(11)* Set consisting of even number of 1’s including empty string,


So L= {ε, 11, 1111, 111111, ……….}

Regular Sets

Any set that represents the value of the Regular Expression is called a Regular
Set.

Properties of Regular Sets

 Property 1. The union of two regular set is regular


 Property 2. The intersection of two regular set is regular.
 Property 3. The complement of a regular set is regular.
 Property 4. The difference of two regular set is regular.
 Property 5. The reversal of a regular set is regular.
 Property 6. The closure of a regular set is regular.
 Property 7. The concatenation of two regular sets is regular

Question - Proof the above properties and check if they are true.

15 | P a g e
16 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy