You are on page 1of 158

Unit - 3

Finite Automata And Regular


Languages
Content
1. Central Concepts of Automata Theory, Alphabets, Strings,
Languages
2. Finite Automata
1. Deterministic Finite Automata (DFA)
2. Non Determinism Finite Automata (NDFA)
3. NDFA with epsilon
4. Equivalence of DFA, NDFA and NDFA with epsilon
3. Chomsky Hierarchy
4. Regular Expression: Finite Automata and Regular Expression
5. Closure Properties of Regular Language
6. Pumping Lemma for Regular Languages
Theory of Computing
• To know the foundations and principles of computer science

• Branch that deals with how efficiently problems can be solved on a


model of computation, using an algorithm

• Branches:
• Automata Theory

• Computability Theory

• Computational Complexity Theory


Automata Theory
• Study of abstract computing machine as well as computational
problems solved with them
• Study of mathematical properties of automata
• Ex: FA modeling of on/off switch
Push
Start off on
Push

• Need for Automata Theory


• Essential for the study of the limits of computation
• Pattern searching in websites
• Designing and checking the behaviour of the digital circuits
Central Concepts of Automata Theory
•Alphabets (Σ)
•A finite, non-empty set of symbols
•Ex:
a) Σ = {0, 1}, the binary alphabet
b) Σ = {a, b, … , z}, the set of all lower-case letter
c) The set of all ASCII characters
Central Concepts of Automata Theory – cont..
•Strings
•A string (or word) is a finite sequence of symbols chosen
from some alphabet
• Example
• 1011 is a string from alphabet S = {0, 1}
• Empty string, ε a string with zero occurrences of symbols
• Length |w| of string w the number of positions for symbols in w
• Examples:|0111|= 4, |ε|=0, …
Central Concepts of Automata Theory – cont..
• Power of an alphabet, Σk • Concatenation of two strings x
• A set of all strings of length k and y is xy
• Examples • Example
• Given Σ = {0, 1}, we have • If x = 01101, y = 110,
● Σ0 = {ε}, Σ2 = {00, 01, 10, 11} • then xy = 01101110, and xx =
• Set of all strings over Σ denoted as Σ* x2 = 0110101101, …
Σ* = Σ0 ∪ Σ1 ∪ Σ2 ∪ …
• Set of nonempty strings from Σ Σ+ • ε is the identity for
Σ+ = Σ* − {ε} concatenation
Σ+ = Σ1 ∪ Σ2 ∪ Σ3 ∪ … since εw = wε = w
Σ* = Σ+ ∪{ε}
Central Concepts of Automata Theory – cont..
• Languages
• A language is a set of strings all chosen from some Σ*
• If Σ is an alphabet, and L⊆Σ*, then L is a language over Σ.
• Examples
• The set of all legal English words is a language {a, b, c, …., z}

• The set of all strings of n 0’ followed by n 1’s for n≥ 0 {ε, 01, 0011, 000111, …}
• The set of strings of equal no. of 0’s and 1’s {ε, 01, 10, 0011, 0101,…}
• Σ* is an infinite language for any alphabet Σ
• φ = the empty language (not the empty string ε) is a language over any alphabet
• {ε} is a language over any alphabet (consisting of only one string, the empty string ε)
φ ≠ {ε}
Central Concepts of Automata Theory – cont…
• Concatenation of languages
• The concatenation of two languages L1 and L2 is given by,
L = L1 L2 = {w∈ Σ* ; w = xy for some x ∈ L1 and y ∈ L2}

• Kleen Star
• The Kleen star of a language L is denoted by L* which is the set of all
strings obtained by concatenating zero or more strings from L
L* = {w∈ Σ* ; w = w1, …, wk for k>=0 and w1, w2, …, wk ∈ L}
Central Concepts of Automata Theory – cont…
•Grammar
• A grammar of a language, G is defined as G = (V, T, S, P)
• Where,
V Finite set of objects called variables/ Non-terminals
T Finite set of objects called terminals
S∈V Start Symbol
P Finite set of productions

Ex: G = {(S, T), (a, b), S, P}


Example problems on grammar
1. Given Σ = {a, b} obtain Σ*
• Give an example of a finite language in Σ
• Given L = {anbn : n>=0}, check if strings aabb, abb are in language, L
• Soln:
• Σ* = {ε, a, b, ab, ba, ….}
• {a, aa, aab} Some example of a language in Σ
• String: ‘aabb’
L = {ε, ab, aabb, aaabbb, …}
When n = 2, L = a2 b2 therefore, it is a string in L
• String: ‘abb’
This is not a string in L. Since, there is no equal number of a’s and b’s
Problem 2
• Given u = a2ba3b2; v = ba. Find (i) uv (ii) uv2 (iii)|uv|
• Soln:
(i) uv = (a2ba3b2).(ba) = a2ba3b3a

(ii) uv2 = (a2ba3b2).(ba).(ba) = a2ba3b3aba

(iii) |uv| = |a2ba3b3a| = |aabaaabbba| = 10


Problem3
• Given a grammar, G = [{S}, {a, b}, S, P] where Production, P is given by S a S b, S
ε. Obtain language L(G).
Soln:
S ==> a S b
==> a a S b b
==> a a a S b b b
==>….
==> an S bn
==> an bn

L (G) = {an bn |where n≥0} or


L(G) = {set of strings with same number of a’s and b’s}
Problem 4
• Given a grammar, G = [{A, S}, {a, b}, A, P] where Production, P is given
by A a S b, S S b |ε. Obtain language L(G).
Soln:
A ==> a S b
==> a S b b
==> a S b b b
==> ….
==> a S bn
==> a bn

L(G) = { a bn | where n≥0} or


L(G) = { All strings with exactly one ‘a’ and ‘n’ b’s}
Problem 5 and Problem 6
• Find the grammar for Σ = {a, b} • Find the grammar for Σ = {0, 1}
that generate the set of all strings that generate the set of all strings
with at least one ‘a’. containing more 0’s than 1’s.
• Soln: • Soln:
A aSb A 0S
S aSb|ε S 0S1|ε
Finite Automata (FA)
• An automaton is an abstract model of a digital computer
• Mathematical model of a system with discrete inputs and outputs
• Example:
Working Principle of FA
•Input Tape:
• Inputs are written on a tape, Input Tape
read by automaton but cannot
change it String
• Input tape is divided into
cells, each of which can hold Output
one symbol Finite “Accept”
•Finite Automaton Automaton or
• Finite number of states [Control Unit]
• Control state transitions / “Reject”
changes
Representation of FA
• A Finite Automaton (FA) is represented by a 5-tuple (Quintuple)
M = (Q, Σ, δ, S, F)
Where,
Q is the set of states (finite)
Σ is the alphabet (finite)
δ : Q × Σ → Q is the transition function
S ∈ Q is the start state
F ⊆ Q is the set of accept states
Transition Diagram
• A directed graph associated with the vertices of the graph corresponds
to the states of Finite Automata

• If there is a transition from state A to state B on input symbol ‘0’, then


there is an arc with label ‘0’ is drawn from state A to state B

• FA accepts a string, ‘x’, if the sequence of transitions corresponding to


the symbols of ‘x’ leads from the start state to an accepting state
Example

q0 0,1

0 0
L(M) = {0,
1}*
1
q0 q1
1

L(M) = { w | w has an even number of 1s}


Checking acceptance of string using FA
11 1
0
0,1
1
0111 11 1
1 0
0

Read string left to right 1

The machine accepts a string if the process ends in a


double circle
To accept a string:
all the input string is scanned
and the last state is accepting

To reject a string:
all the input string is scanned
and the last state is non-accepting
head Initial Configuration
Input Tape

Input String

Initial state
Scanning the Input
Input finished

accept
A Rejection Case

Input String
Input finished

reject
Another Rejection Case
Tape is empty

Input Finished

reject
Language Accepted:
Another Example

Accept Accept Accept


state state state
Empty Tape

Input Finished

accept
Another Example

Accept trap state


state
Input String
Input finished

accept
A rejection case

Input String
Input finished

reject
Language Accepted:
Example 1 – String acceptance
1. Given a finite automata, M = ({q0, q1}, {0, 1}, δ, q0, {q1}) and
transition diagram as given below:
0 1
q0 q1 1

a) Check whether the input string 10101 is accepted by M or not.


b) Check whether the input string 101100 is accepted by M or not.
Example 1 – cont…
a) 1 0 1 0 1 The string 10101 is accepted because it ends
q0 q1 q0 q1 q0 q1 in the final / acceptance state
Start Accepted

b) 1 0 1 1 0 0
q0 q1 q0 q1 q1 q0 q0
Start
Not accepted

The string 101100 is not accepted because it does not ends in


the final / acceptance state
Example 2
2. Given a finite automata, M = ({a, b, c, d}, {0, 1}, δ, a, {a}) and
transition table as given below:
0 1
a c b
b d a
c a d
d b c
a) Check whether the input string 110101 is accepted by M or not.
b) Check whether the string 110011 is accepted by M or not.
Types of Finite Automata
1. Deterministic Finite Automata (DFA)

2. Non-deterministic Finite Automata (NFA / NDFA)


1. Deterministic Finite Automaton (DFA)
• On each input symbol, there is one and only one state to which the
automaton can have transition from its current state

: Set of states

: Input alphabet

: Transition function

: Initial state

: Set of accepting states


Set of States
Example
Input Alphabet
:the input alphabet never contains

Example
Initial State
Example
Set of Accepting States
Example
Transition Function

Describes the result of a transition


from state with symbol
Example:
Transition Table for

symbols
states
Extended Transition Function
To read zero / more symbols of input string at a time

Describes the resulting state


after scanning string from state
Example:
Special case: No transition,

for any state


In general:

implies that there is a walk of transitions

states may be repeated


Language Accepted by DFA
Language of DFA:

It is denoted as and contains all the strings accepted


by

We say that a language is accepted (or recognized)


by DFA

if
• For a DFA

• Language accepted by :
• Language rejected by :
Problems – Construction of DFA
1. Construct a DFA that accepts all and only the string of 0’s and 1’s
that have the sequence 01 somewhere in the string.
Soln:
Language, L = {x 01 y | x and y any strings of 0’s and 1’s}
Alphabet, Σ = {0, 1}
Transition diagram:
1 0 0, 1
start 0 1
q0 q1 q2
Problem 1 – cont…
• Transition States Transition table
δ (q0, 0) = q1 0 1
δ (q0, 1) = q0
δ (q1, 0) = q1 q0 q1 q0
δ (q1, 1) = q2 q1 q1 q2
δ (q2, 0) = q2 q2 q2 q2
δ (q2, 1) = q2

Therefore, the Automaton that accepts language L,


A = {(q0, q1, q2), (0, 1), δ, q0, q2}
Problem 2
Construct the DFA’s accepting the following language over the alphabet
{0, 1}
a) The set of all strings ending with ‘00’
b) The set of strings with three consecutive 0’s

Soln:
1
a) 1
0
start 0 0
q0 q1 q2

1
Problem 2 – cont…
Soln:
1
b) 1 0, 1

start 0 0 0
q0 q1 q2 q3

1
Problems
3. Construct DFA that accepts input string of 0’s and 1’s that end with
11
0
0
1
start 1 1
q0 q1 q2

4. Construct DFA that accepts all strings with three consecutive 1’s at
its end
0
0 1

start 1 1 1
q0 q1 q2 q3

0
0
Problems – cont…
5. Construct DFA for all strings with {0, 1} that has even number of
0’s and 1’s. 1

start A B
1
0 0 0 0
1
C D
1
6. Construct DFA for the language L = {0n | n mod 3 = 2, n ≥ 0}

start 0 0
q0 q1 q2

0
Problems – cont..
7. Draw a DFA that accepts a language L over input alphabets ∑ = {0,
1} such that L is the set of all strings starting with ’00’.
Problems – DFA to Language
1. Consider DFA with the following transition table. Find the language accepted by
DFA δ 0 1
a a b
* b a
b
Soln: The language, L = { w | w is the string with odd number of 1’s}

δ 0 1
2. Consider the following DFA and find language accepted by DFA.
a a b
*b - c
c c b

Soln: The language, L = { w | w set of strings ends with 1 and has odd number of
1’s}
Non-Deterministic Finite Automata (NFA)
•The transition function that takes a state and input symbol as
arguments then returns zero or more states.

•Example
0, 1 0, 1
start 1
q1 q2
Representation of NFA
• A NFA can be represented as,

: Finite set of states

: Finite set of Input symbols

: Transition function, Q X {Σ ∪ {ε}} 2Q

: Initial / Start state

: Set of accepting states


Example: Moves on a Chessboard
• States = squares. r b
1 2 3
1 2,4 5
2 4,6 1,3,5
4 5 6
• Inputs = r (move to an 3 2,6 5
adjacent red square) and 4 2,8 1,5,7
7 8 9
b (move to an adjacent 5 2,4,6,8 1,3,7,9
black square). 6 2,8 3,5,9
r b b 7 4,8 5
1 2 1 5 8 4,6 5,7,9
• Start state, final state are 4 3 1 * 9 6,8 5
in opposite corners. 5 3
7 7
9 Accept, since final state reached
Problems – Construction of NFA
1. Construct NFA for set of all strings {0, 1} that end with string 00.
Soln:
Step 1: Language, L = {w | w is set of all strings that end with string 00}
Step 2: Alphabet, Σ = {0, 1}
Step 3: Transition Diagram
0, 1
0
start 0 0
q0 q1 q2
1
1

Step 4: NFA, N = [{q0, q1, q2}, {0, 1}, δ, q0, {q2}]


Problems – Construction of NFA
2. Construct NFA with abb as substring.
Soln:
Step 1: Language, L = {x | x is set of all strings with abb as substring}
Step 2: Alphabet, Σ = {a, b}
Step 3: Transition Diagram

a, b
a, b
start a b b
q0 q1 q2 q3

Step 4: NFA, N = [{q0, q1, q2 , q3}, {a, b}, δ, q0, {q3}]


Problems – Cont…
3. Construct NFA with 101 as substring.
1, 0
1, 0
start 1 0 1
q0 q1 q2 q3

4. Construct NFA for set of all strings that ends with three consecutive
1’s at its end.
1, 0
1
start 1 1 1
q0 q1 q2 q3
Problem 1 – Checking acceptance of string
Construct an NFA for the set of strings with {0, 1} ending with 01 and
draw the transition table for the same and check whether the input string
00101 is accepted by NFA.
Soln:
Step 1: Language, L = {x | x is set of all strings ending with 01}
Step 2: Alphabet, Σ = {0, 1}
Step 3: Transition Diagram
0, 1 0
start 0 1
q0 q1 q2

0, 1

Step 4: NFA, N = [{q0, q1, q2}, {a, b}, δ, q0, {q2}]


0, 1 0
Cont… start 0 1
Step 5: Input String = 00101 q0 q1 q2

δ’(q0, ε) = q0
δ’(q0, 0) = δ(q0, 0) = {q0, q1} 0, 1

δ’(q0, 00) = δ(δ’(q0, 0), 0) = δ({q0, q1}, 0)


= δ(q0, 0) ∪ δ(q1, 0) = {q0, q1} ∪ {q1} = {q0, q1}

δ’(q0, 001) = δ(δ’(q0, 00), 1) = δ({q0, q1}, 1)


= δ(q0, 1) ∪ δ(q1, 1) = {q0, q2}

δ’(q0, 0010) = δ(δ’(q0, 001), 0) = δ({q0, q2}, 0)


= δ(q0, 0) ∪ δ(q2, 0) = {q0, q1}

δ’(q0, 00101) = δ(δ’(q0, 0010), 1) = δ({q0, q1}, 1)


= δ(q0, 1) ∪ δ(q1, 1) = {q0, q2}
Cont..
Step 6:
To check the acceptance of the string
δ’(q0, 00101) ∩ F = {q0, q2} ∩ {q2} = {q2}

Therefore, the string 00101 is accepted.


Problem 2
• Consider the given NFA and check whether the input ‘abaab’ is
accepted or not.
δ a b
q0 {q0, q1} {q0, q3}
q1 {q2} φ
*q2 {q2} {q2}
q3 φ {q4}
*q4 {q4} {q4}
NFA with ε - transition
• NFA can be extended to NFA-ε transition for an empty string

• NFA-ε has 5-tuples, M=(Q, Σ, δ, S, F) [Identical to NFA]

• In NFA-ε, there will be a state transition on an input symbol ε

start ε
q1 q2
Problems – Construction of NFA-ε
• Construct NFA-ε that end with string 11 for the set of all strings {0, 1}
Soln:
Step 1: Language, L = {w | w is set of all strings that end with string 11}
Step 2: Alphabet, Σ = {0, 1}
Step 3: Transition Diagram
0, 1
start 1 1
q0 q1 q2

Step 4: NFA-ε, NE = [{q0, q1, q2}, {0, 1}, δ, q0, {q2}]


Problems – cont…
2. Construct NFA-ε with 011 as substring for set of all strings {0, 1}.
Soln:
Step 1: Language, L = {x | x is set of all strings with 011 as substring}
Step 2: Alphabet, Σ = {a, b}
Step 3: Transition Diagram
1, 0
1, 0
start 0 1 1
q0 q1 q2 q3

Step 4: NFA-ε, NE = [{q0, q1, q2, q3, q4}, {0, 1}, δ, q0, {q3}]
Problems – Acceptance of strings
• ε-closure: the ε-closure of q0 [ε-closure(q0)] denotes the set of all states
‘P’ such that there is a path or transitions from q0 to P on ε.
• Path from current state to set of states that has ‘ε’ transitions
1. Consider the following NFA-ε and find the ε-closure for each state
and check whether the string ‘abb’ is accepted or not.
a b c
start ε ε
q0 q1 q2

a b
• Soln:
ε-closure(q0) = {q0, q1, q2} [Path from current state to set of states that has ‘ε’ transitions]
ε-closure(q1) = {q1, q2}
ε-closure(q2) = {q2}
Cont (1) start
a
ε
b
ε
c

q0 q1 q2
• Input string: ‘aab’
a b
δ’(q0, ε) = ε-closure(q0) = {q0, q1, q2}
δ’(q0, a) = ε-closure(δ’(δ(q0, ε), a))
= ε-closure(δ({q0, q1, q2}, a))
= ε-closure(δ(q0,a) ∪ δ(q1,a) ∪ δ(q2,a))
= ε-closure({q0, q1} ∪ φ ∪ φ)
= ε-closure({q0, q1})
= ε-closure(q0) ∪ ε-closure(q1)
= {q0, q1, q2} ∪ {q1, q2}
= {q0, q1, q2}
Cont (2) start
a
ε
b
ε
c

q0 q1 q2

a b
δ’(q0, ab) = ε-closure(δ’(δ(q0, a), b))
= ε-closure(δ({q0, q1, q2}, b))
= ε-closure(δ(q0,b) ∪ δ(q1,b) ∪ δ(q2,b))
= ε-closure(φ ∪ {q1, q2} ∪ φ)
= ε-closure({q1, q2})
= ε-closure(q1) ∪ ε-closure(q2)
= {q1, q2} ∪ {q2}
= {q1, q2}
a b c
Cont (3) start
q0
ε
q1
ε
q2
δ’(q0, abb) = ε-closure(δ’(δ(q0, ab), b)) a b
= ε-closure(δ({q1, q2}, b))
= ε-closure(δ(q1,b) ∪ δ(q2,b))
= ε-closure({q1, q2} ∪ φ)
= ε-closure({q1, q2})
= ε-closure(q1) ∪ ε-closure(q2)
= {q1, q2} ∪ {q2}
= {q1, q2}

Final State, F = {q2}


Therefore {q1, q2} ∩ F = {q1, q2} ∩ {q2} = {q2} ==> member in final state

So, the string ‘abb’ is accepted by NFA-ε


Problem 2
• Consider the following NFA-ε and find the ε-closure for each state and
check whether the string ‘abcc’ is accepted or not.
a b c
start ε ε
q0 q1 q2

a b

The string ‘abcc’ is accepted by NFA-ε


Equivalence of NFA and DFA
• If a regular language ‘L’ is accepted by a NFA then there exist a DFA that accepts,
‘L’.
OR
• A regular language, ‘L’ is accepted by some DFA iff ‘L’ is accepted by some NFA.
OR
• As every DFA is an NFA, the classes of language accepted by NFA’s includes the
classes of language accepted by DFA.
OR
• If D = (QD, Σ, δ, {q0}, FD) is DFA constructed from NFA, N = (QN, Σ, δ, {q0}, FN) is
the subset construction, then L(D) = L(N).
Equivalence – (2)
• For any NFA there is a DFA that accepts the same language.

• Proof is the subset construction.

• The number of states of the DFA can be exponential in the

number of states of the NFA. [Q states in NFA can be 2Q states


NFA
in DFA]

DFA
Equivalence proof

NFA
Proof – cont…
Proof – cont…
Proof – cont…
Proof – cont…

∴ L (MD) = L(MN)
Subset Construction
• Given an NFA with states Q, inputs Σ, transition function δN, start
state q0, and final states F, construct equivalent DFA with:
• States 2Q (Set of subsets of Q).

• Inputs Σ.

• Start state {q0}.

• Final states = all those with a member of F.


Subset Construction – (2)
• The transition function δD is defined by:
δD({q1,…,qk}, a) is the union over all i = 1,…,k of δN(qi, a).
• Critical Point
• The DFA states have States (names) that are sets of NFA states.
• But as a DFA state, an expression like {p,q} must be read as a single state, not
as a set.

• Example:
• Construct the DFA equivalent of our “chessboard” NFA.
Example: Subset Construction
r b r b

1 2,4 5 {1} {2,4} {5}


2 4,6 1,3,5 {2,4}
3 2,6 5 {5}
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
* 9 6,8 5
Alert: What we’re doing here is the lazy form of DFA
construction, where we only construct a state if we are
forced to.
Cont…
r b r b

1 2,4 5 {1} {2,4} {5}


2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5}
4 2,8 1,5,7 {2,4,6,8}
5 2,4,6,8 1,3,7,9 {1,3,5,7}
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
* 9 6,8 5
Cont…
r b r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8}
5 2,4,6,8 1,3,7,9 {1,3,5,7}
6 2,8 3,5,9 * {1,3,7,9}
7 4,8 5
8 4,6 5,7,9
* 9 6,8 5
Cont…
r b r b

1 2,4 5 {1} {2,4} {5}


2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7}
6 2,8 3,5,9 * {1,3,7,9}
7 4,8 5 * {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
Cont…
r b r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7} {2,4,6,8} {1,3,5,7,9}
6 2,8 3,5,9 * {1,3,7,9}
7 4,8 5 * {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
Cont…
r b r b

1 2,4 5 {1} {2,4} {5}


2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7} {2,4,6,8} {1,3,5,7,9}
6 2,8 3,5,9 * {1,3,7,9} {2,4,6,8} {5}
7 4,8 5 * {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
Cont…
r b r b
1 2,4 5
{1} {2,4} {5}
2 4,6 1,3,5
{2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5
{5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7
{2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9
{1,3,5,7} {2,4,6,8} {1,3,5,7,9}
6 2,8 3,5,9
* {1,3,7,9} {2,4,6,8} {5}
7 4,8 5
8 4,6 5,7,9 * {1,3,5,7,9} {2,4,6,8} {1,3,5,7,9}
* 9 6,8 5
Proof of Equivalence: Subset Construction
• Show by induction on |w| that δN(q0, w) = δD({q0}, w)
• Basis: w = ε: δN(q0, ε) = δD({q0}, ε) = {q0}.
• Induction:
• Let δN(q0, x) = δD({q0}, x) = S.

• Let T = the union over all states p in S of δN(p, a).

• Then δN(q0, w) = δD({q0}, w) = T.


• For NFA: the extension of δN.

• For DFA: definition of δD plus extension of δD.


• That is, δD(S, a) = T; then extend δD to w = xa.
Example – NFA to DFA
• Convert the following NFA to
DFA
1, 0
start 0 1
q0 q1 q2
Cont…
Cont…
Example 2
• Convert to a DFA, the following NFA:
1, 0
1, 0
start 0 0 0
p q r s

1
Equivalence of NFA and NFA-ε
• A language, ‘L’ is accepted by some NFA-ε iff ‘L’ is accepted by
NFA without ε transition, i.e., L(M) = L(M’)

NFA- ε

Example: NFA

Convert the following NFA- ε to NFA without ε


0 1 2
start ε ε
q0 q1 q2
Solution – cont…
• Transition table
δ 0 1 2 ε

q0 {q0} φ φ {q1}

q1 φ {q1} φ {q2}

*q2 φ φ {q2} φ

ε-closure(q0) = {q0,q1,q2}
ε-closure(q1) = {q1,q2}
ε-closure(q2) = {q2}
Cont…
Cont…
Problem 2:
• Convert the following NFA- ε to NFA without ε
a b
start ε
q0 q2

• Solution:
NFA-ε to DFA [directly]
1. Convert the following NFA- ε to

DFA
Problem 2
• Convert the following NFA- ε to DFA
δ 0 1 2 ε

q0 {q0} φ φ {q1}

q1 φ {q1} φ {q2}

*q2 φ φ {q2} φ

• Soln:
Regular Expressions (REs)
• Used to describe about the structure of data
• Method to describe languages
• Regular Language - Languages defined by the regular expression
• REs gives the declarative ways to express / represent the strings
• REs serve as the input language for many systems that process strings
• Example:
• Search Commands – UNIX grep
• Lexical Analyzer generators – breaks the source program in to logical units
called tokens
Operations on REs
1. Union (U):
• The union of two languages L and M, denoted L U M is the set of strings that
are in either L or M or both
• Ex: L = {001, 10, 11} and M = {ε, 001} and L U M = {ε, 10, 11, 001}

2. Concatenation (.):
• The concatenation of languages L and M is the set of strings that can be
formed by taking in any string in L and concatenating it with any string in M
• Ex: L = {001, 10, 11} and M = {ε, 001} and L . M = {001, 10, 11, 001001,
10001, 11001}
Operations on Res – cont…
3. Closure (*):
• Represents the set of those strings that can be formed by taking any number of
strings from L, (possibly with repetitions) and concatenating all of them.
• Ex1: L = {0, 1}, the L* is all strings of 0’s and 1’s
• Ex2: L = {0, 11}, the L* consists of those strings of 0’s and 1’s such that the
1’s come in pairs {011, 11110, …} but not {01011, 1010}
L = {0, 11}
L0 = {ε}
L1 = {0, 11}
L2 = L . L = {00, 011, 110, 1111}
L3 = L. L2 or L2 . L = {000, 0011, 0110, 01111, 1100, 11011, 11110, 111111}
L* = L0 U L1 U L2 U …….
Building Regular Expressions
• The language L(E) is described by Regular Expression, E

• REs can be described recursively as follows:

• Basis: The basis consists of three parts:


• A variable, usually capitalized, such as L, represents any language

• The constant ‘ε’ and ‘φ’ are REs, denoting the languages L(ε) and L(φ)
respectively. L(ε) = ε & L(φ)= φ

• If ‘a’ is any symbol, then ‘a’ is a regular expression, L(a) = {a}


Building Regular Expressions – cont…
• Induction: Four parts one for each of the operators and one for the parenthesis
• If E and F are regular expressions then, E + F is denoting the union of L(E) and L(F),
L(E+F) = L(E) U L(F)
• If E and F are regular expressions then, E . F is denoting the concatenating of L(E) and
L(F), L(E.F) = L(E) . L(F)
• If E is a regular expression then, E* is a RE denoting the closure of L(E), L(E*) =
(L(E))*
• If E is a regular expression then, (E) is also denoting the same language as E, L((E)) =
L(E)
Precedence of Regular Expression Operators
• Closure operator (*)
• Dot Operator (.)
• Union operator (+)
• Note:
• Operator are grouped from left to right
• Ex: 012 can be grouped as (01) 2 by default
• Use parenthesis to override 0(12)
• Ex: The expression 01*+1 is grouped as:

2 1 3
Regular Expression to Language
Regular Expression Language
1* or 0* Any number of 1s or any number of 0s
1 or 0 One occurrence of 1 (or) 0
01 No other 0’s and 1’s except the string 01 [i.e., 01 appears only once]
(01)* All strings that repeat 01 zero or more time
01* String consists of 0 followed by any number of 1’s
0+1 String consisting of one 0 or string consisting of one 1 or sting
[Ex: 01, 0 , 1] consisting of 01
(a + b)* Set of strings of a’s and b’s of any length including the null string
[Ex: { ε, a, b, aa, ab, bb, ba,
aaa…….}
0 + 1* String consisting of 0 or any number of 1’s [String may or may not
have Zero]
Regular Expression to Language – cont…
Language to Regular Expression
Regular
Language
Expression
Set of all strings of Zero or more a’s a*
Set of all strings of a’s and b’s of length two (a+b) (a+b)
Set of all strings over {a, b} ending with ‘aba’ (a+b)* aba
Set of all strings over {0, 1} starting and ending with 0 0 (0+1)* 0
Set of all strings over {a, b, c} with any number of a’s a* b* c*
followed by any number of b’s followed any number of c’s
Language to Regular Expression – cont…
Language Regular Expression
Set of all strings over {a, b, c} with at least one ‘a’ a+ b+ c+
followed by at least one ‘b’ followed at least one ‘c’
Set of all strings with zero or more instances of a or b (a + b)* or (a* b*)*
Set containing the string 0 and all strings consisting of zero 0 + 0* 1
or more 0’s followed by single 1
Set of string over {1} having odd length of 1 1 (11)*
Set of strings of 0’s and 1’s with at most one pair of 3 (0+1)* 111 (0+1)*
consecutive 1’s
Finite Automata and Regular Expression
• Theorem
• Every regular language defined by a regular expression is also defined by the
finite automata

• Every regular language defined by the finite automata is also defined by the
regular expression

• To Prove
L(M) = L(R)

Where L(R) => Language for the regular expression ‘R’

L(M) => Language for some NFA-ε


ng rules
& r2
r2
Converting Regular Expression to Finite
Automata
• Construct the FA for the regular expression, R = 01

• Construct the FA for the regular expression, R = 0+1


RE to FA – cont…
• Construct the FA for the regular expression, R = 0*

• Construct the FA for the regular expression, R = (0+1)*


RE to FA – cont…
• Construct the FA for the regular expression, R = (01)* + 1
DFA to RE
• States Elimination method
1. For each accepting state q, apply the reduction process to produce equivalent
automata with regular expression labels on the arcs by eliminating all states
except final and start state.

start
A
Rij
B
R = Rij + Qi S* Pj

Rij Path from start state to accepting state


Qi Pj Qi Path from start state to eliminating state
S Path from eliminating state to itself
C
Pj Path from eliminating state to accepting state

S
DFA to RE – cont…
2. If accepting state and start state are distinct, then we have two state
automata
start S U
A B
T
R = ( R + S U* T) S U*
R

3. If start and accepting state are same [Apply rule1 and perform R*]
R
A R=
R*
4. Derived Regular expression, RE = Sum (Union) of all expressions, derived from
reduced automata for each accepting state by rules 2 and 3
Problems – FA to RE
• Find the RE for the following FA using state elimination method:
1
start 0
q1 q3
1 0

0 1
q2
• Soln:
Step 1: Consider the path q1 q3 to eliminate q2
Step 2: Consider the path q1 q2 q1 to eliminate q2
Step 3: Consider the path q3 q1 to eliminate q2
Step 4: Consider the path q3 q2 q3 to eliminate q2
Step 5: RE = Sum (Union) of all expressions, derived from reduced automata
[Rule 2: because start and final state are different]
Cont…
Step 1: Consider the path q1 q2 q3 to eliminate q2
1 1
start 0 start 00
q1 q3 0
q1 q3
0 After
0 eliminating q2
q2

R = Rij + Qi S* Pj
Rij = φ
Rij Path from start state to accepting state
Qi = 0 Qi Path from start state to eliminating state
S =ε S Path from eliminating state to itself

Pj = 0 R1 = φ + 0. ε*. 0 Pj Path from eliminating state to accepting state

==>R1 = 0. 0
Cont…
Step 2: Consider the path q1 q2 q1 to eliminate q2
1 1 + 01
start After start
q1 eliminating q2 q1
1

0 q2

R = Rij + Qi S* Pj
Rij = 1 R2 = 1 + 0. ε*. 1
Qi = 0
S =ε ==>R2 = 1 + 0 1
Pj = 1
Cont…
Step 3: Consider the path q3 q2 q1 to eliminate q2
1 1
start 0 start 1, 1
q1 q3 0
q1 q3
1 After
1 eliminating q2
q2

R = Rij + Qi S* Pj
Rij = φ R3 = φ + 1. ε*. 1
Qi = 1
S =ε ==>R3 = 1 1
Pj = 1
Cont…
Step 4: Consider the path q3 q2 q3 to eliminate q2
0 0+10
After
q13 eliminating q2 q13
0

1 q2

R = Rij + Qi S* Pj
Rij = 0 R4 = 0 + 1. ε*. 0
Qi = 1
S =ε ==>R4 = 0 + 1 0
Pj = 0
Cont…
Step 5: RE = Combine all Regular expressions, derived from reduced
automata [Rule 2: because start and final state are different]

1+01
start 00 0+10
q1 q3
Rule 2:
11
R = (R + S U* T)* S U*
R=1+01
S = 00
U=0+10
T = 11
R = ((1 + 0 1) + 0 0 (0 + 1 0)* 1 1)* 0 0 (0 + 1 0)*
Problem 2
• Find the Regular Expression for finite automata by eliminating states method.
0
0 1
start 1 0
q0 q1 q2

1
• Soln:
Cont…
Cont…
Cont…
Cont…
Cont…
Proving Languages not to be regular
• The properties of the Regular language are,

1. Pumping Lemma [To prove languages are not regular]

2. Closure Properties [To prove languages are regular]

Self Study - Refer PDF file

[Pumping Lemma and Closure Properties of Regular languages]

You might also like