Professional Documents
Culture Documents
• Branches:
• Automata Theory
• Computability Theory
• 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
q0 0,1
0 0
L(M) = {0,
1}*
1
q0 q1
1
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
Input Finished
accept
Another Example
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
b) 1 0 1 1 0 0
q0 q1 q0 q1 q1 q0 q0
Start
Not accepted
: Set of states
: Input alphabet
: Transition function
: Initial state
Example
Initial State
Example
Set of Accepting States
Example
Transition Function
symbols
states
Extended Transition Function
To read zero / more symbols of input string at a time
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
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,
a, b
a, b
start a b b
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
δ’(q0, ε) = q0
δ’(q0, 0) = δ(q0, 0) = {q0, q1} 0, 1
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, 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}
a b
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 Σ.
• Example:
• Construct the DFA equivalent of our “chessboard” NFA.
Example: Subset Construction
r b r b
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
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
• The constant ‘ε’ and ‘φ’ are REs, denoting the languages L(ε) and L(φ)
respectively. L(ε) = ε & L(φ)= φ
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)
start
A
Rij
B
R = Rij + Qi S* Pj
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
==>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,