Automata Learning
Automata Learning
• Languages:
– Important aspect of any language is symbol.
– Symbols are building block of any language.
– Symbols are : {a,b,c,d,e,0,1,2,3,4,5……}
– Alphabets = Finite set of Symbols
• Example:
• Sigma (a,b)
– String : Sequence of Alphabets
• If length of string is 2, then
• {a,b,aa,ab,bb,ba}
• If length of string is 3 or 4?
Theory of Computation (TOC)
– What is language?
• Collection of all string is called as language.
• Language can be finite or Infinite
• Example:
1)L1 : Collection of all strings of length 3, Sigma
(a,b)
{aaa,aab,aba,abb,baa,bab,bba,bbb}
2)L2: All the string should start with a and end
with a, Sigma (a,b)
{aa,aaa,aaaa……...,aba,abbba,……}
3) L3: Length should be 0
Sigma 0 = epsilon
Theory of Computation (TOC)
– Power of Sigma
– If Sigma {a,b},
• Sigma power 0: Set of all strings with the length “0”
– Answer: Epsilon OR Lambda (i.e. Null String)
• Sigma power 1: Set of all strings with the length “1”
– Answer: {a,b}
• Sigma power 2: Set of all strings with the length “2”
– Answer:{aa,ab,ba,bb}
.
.
.
• Sigma power n: Set of all strings with the length “n”
• Sigma * : Kleene Clouser (i.e. Infinite String)
Theory of Computation (TOC)
Input
String
Output
“Accept”
Finite or
Automaton “Reject”
Transition Graph
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
initial accepting
state state
transition
state
Initial Configuration
Input String
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Reading the Input
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
accept
Rejection
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished
a b a
a, b
reject
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Another Rejection
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
reject
Another Example
a a b
a a, b
b a, b
q0 q1 q2
a a b
a a, b
b a, b
q0 q1 q2
a a b
a a, b
b a, b
q0 q1 q2
a a b
a a, b
b a, b
q0 q1 q2
Input finished
a a b
a a, b
accept
b a, b
q0 q1 q2
Rejection Example
b a b
a a, b
b a, b
q0 q1 q2
b a b
a a, b
b a, b
q0 q1 q2
b a b
a a, b
b a, b
q0 q1 q2
b a b
a a, b
b a, b
q0 q1 q2
Input finished
b a b
a a, b
b a, b
q0 q1 q2
reject
Definition
a, b
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Set of States
States
Q q0 , q1, q2 , q3 , q4 , q5
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Initial State
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Accepting State F
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Formal Definition
• Finite Automaton (FA)
M Q, , , q0 , F
Q : set of states
: input alphabet
: transition function
q0 : initial state
F: set of accepting states
DESCRIPTION OF A FINITE AUTOMATON
MCQ
• There are ________ tuples in finite state
machine.
a) 4
b) 5
c) 6
d) unlimited
Types of Automaton
• An automaton in which the output depends only
on the input is called an automaton without a
memory.
• An automaton in which the output depends
on the states as well. is called automaton with a
finite memory.
• An automaton in which the output depends only
on the states of the machine is called a Moore
machine.
• An automaton in. which the output depends on
the state as well as on the input at any instant
of time is called a Mealy machine
An Automaton
• Basics
Block Diagram of Finite
Automaton
Diagram
Transition System
Example
Class work
• 110011
• 110110
Example Table Form
Cont.
Class Work
• Check for the 101101
• 11111
• 000000
Input alphabet (Diagram
Based)
a, b
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Cont.
Set of States
Q q0 , q1, q2 , q3 , q4 , q5
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Initial State
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Accepting State F
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Example
Input String
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Reading the Input
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
accept
Rejection
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished
a b a
a, b
reject
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Class Work
• abbbaaab
• bababaa
• abbaaba
MCQ
• Which of the following is not a part of 5-
tuple finite automata?
a) Input alphabet
b) Transition function
c) Initial State
d) Output Alphabet
DFA
Deterministic Finite Automata (DFA)
•It's finite automata with deterministic
behavior. In DFA, there is exactly one
transition from any state of finite
automata for each input symbol. It
accepts the string by halting at a final
state, and it rejects it by halting at a non-
final state.
NFA
Non-deterministic Finite Automata
(NFA)
•It's a finite automata that isn't
deterministic. In NFA, there are zero or
more transitions from any state of finite
automata for each input symbol. It
accepts the string by halting in a final
state, and it rejects the string by halting
in a non-final state or in a dead
configuration.
DFA and NFA
• Deterministic Finite Automata (DFA) and
Non-deterministic Finite Automata (NFA)
are used in fields like machine learning,
pattern matching, and formal language
recognition and verification.
• They are fundamental concepts that
help design software that can interpret
languages and patterns, and even build
compilers.
DFA VS NFA
Sr. No. DFA NFA
1 DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.
5 Time needed for executing an input Time needed for executing an input
string is less. string is more.
8 DFA allows only one move for single There can be choice (more than one
input alphabet. move) for single input alphabet.
DFA
EXAMPLES
Example
• DFA Description:
• States: Q = {q0, q1}
• Alphabet: Σ = {0, 1}
• Transitions:
– δ(q0, 0) = q0
– δ(q0, 1) = q1
– δ(q1, 0) = q1
– δ(q1, 1) = q0
• Start State: q0
• Accept States: {q1}
• Question: Does the DFA accept the string "010"?
Answer
• The DFA processes "010" as follows:
• Start at q0.
• Read '0', transition to q0.
• Read '1', transition to q1.
• Read '0', transition to q1. The DFA ends
in state q1, which is not an accept state,
so it does accept "010".
Diagram
0 1 0
0 0
1
q0 q1
1
Diagram
0 1 0
0 0
1
q0 q1
1
Diagram
0 1 0
0 0
1
q0 q1
1
Diagram
0 1 0
0 0
1
q0 q1
1 Accepted
Example
• DFA Description:
• States: Q = {q0, q1}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = q1
– δ(q0, b) = q0
– δ(q1, a) = q1
– δ(q1, b) = q0
• Start State: q0
• Accept States: {q1}
• Question: Does the DFA accept the string "ab"?
Answer
The DFA processes "ab" as follows:
•Start at q0.
•Read 'a', transition to q1.
•Read 'b', transition to q0. The DFA ends
in state q0, which is not an accept state,
so it does not accept "ab".
Example
• DFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {0, 1}
• Transitions:
– δ(q0, 0) = q1
– δ(q0, 1) = q0
– δ(q1, 0) = q2
– δ(q1, 1) = q0
– δ(q2, 0) = q2
– δ(q2, 1) = q2
• Start State: q0
• Accept States: {q2}
• Question: Does the DFA accept the string "0010"?
Answer
• Yes. The DFA processes "0010" as
follows:
• Start at q0.
• Read '0', transition to q1.
• Read '0', transition to q2.
• Read '1', transition to q2.
• Read '0', transition to q2. The DFA ends
in state q2, which is an accept state, so
it accepts "0010".
Example
• DFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = q1
– δ(q0, b) = q0
– δ(q1, a) = q0
– δ(q1, b) = q2
– δ(q2, a) = q2
– δ(q2, b) = q2
• Start State: q0
• Accept States: {q2}
• Question: Does the DFA accept the string "abab"?
Answer
• Yes. The DFA processes "abab" as
follows:
• Start at q0.
• Read 'a', transition to q1.
• Read 'b', transition to q2.
• Read 'a', transition to q2.
• Read 'b', transition to q2. The DFA ends
in state q2, which is an accept state, so
it accepts "abab".
Example
• DFA Description:
• States: Q = {q0, q1, q2, q3}
• Alphabet: Σ = {0, 1}
• Transitions:
– δ(q0, 0) = q1
– δ(q0, 1) = q2
– δ(q1, 0) = q3
– δ(q1, 1) = q0
– δ(q2, 0) = q0
– δ(q2, 1) = q3
– δ(q3, 0) = q2
– δ(q3, 1) = q1
• Answer: No. The DFA processes "1100" as follows:
• Start at q0.
• Read '1', transition to q2.
• Read '1', transition to q3.
• Read '0', transition to q2.
• Read '0', transition to q0. The DFA ends in state q0, which is an accept state, so
it accepts "1100".
Cont.
• Start State: q0
• Accept States: {q0}
• Question: Does the DFA accept the
string "1100"?
Answer
• No. The DFA processes "1100" as
follows:
• Start at q0.
• Read '1', transition to q2.
• Read '1', transition to q3.
• Read '0', transition to q2.
• Read '0', transition to q0. The DFA ends
in state q0, which is an accept state, so
it accepts "1100".
NFA/NDFA
EXAMPLES
Nondeterministic Finite Automaton
Alphabet ={a}
q1 a q2
a
q0
a
q3
Alphabet ={a}
Two choices q1 a q2
a
q0
a
q3
Alphabet ={a}
a a
q1 a q2
a
q0
a
q3
First Choice
a a
q1 a q2
a
q0
a
q3
First Choice
a a
q1 a q2
a
q0
a
q3
First Choice
a a
All input is consumed
q1 a q2 “accept”
a
q0
a
q3
Second Choice
a a
q1 a q2
a
q0
a
q3
Second Choice
a a
q1 a q2
a
q0
a
q3
Second Choice
a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice
a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
Example
“accept”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”
because this
computation
accepts aa
Rejection example
q1 a q2
a
q0
a
q3
First Choice
q1 a q2
a
q0
a
q3
First Choice
a
“reject”
q1 a q2
a
q0
a
q3
Second Choice
q1 a q2
a
q0
a
q3
Second Choice
q1 a q2
a
q0
a
q3
Second Choice
q1 a q2
a
q0
a
q3 “reject”
Example
“reject”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3
“reject”
a a a
q1 a q2
a
q0
a
q3
First Choice
a a a
q1 a q2
a
q0
a
q3
First Choice
a a a
q1 a q2
a
q0 No transition:
a
the automaton hangs
q3
First Choice
a a a
Input cannot be consumed
q1 a q2 “reject”
a
q0
a
q3
Second Choice
a a a
q1 a q2
a
q0
a
q3
Second Choice
a a a
q1 a q2
a
q0
a
q3
Second Choice
a a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice
a a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
aaais rejected by the NFA:
“reject”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”
q1 a q2
a
q0
a
q3
Lambda Transitions
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
(read head does not move)
a a
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
all input is consumed
a a
“accept”
q0 a q1 q2 a q3
String aa is accepted
Rejection Example
a a a
q0 a q1 q2 a q3
a a a
q0 a q1 q2 a q3
(read head doesn’t move)
a a a
q0 a q1 q2 a q3
a a a
q0 a q1 q2 a q3
No transition:
the automaton hangs
Input cannot be consumed
a a a
“reject”
q0 a q1 q2 a q3
q0 a q1 q2 a q3
Another NFA Example
q0 a q1 b q2 q3
a b
q0 a q1 b q2 q3
a b
q0 a q1 b q2 q3
a b
q0 a q1 b q2 q3
a b
“accept”
q0 a q1 b q2 q3
Another String
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
“accept”
q0 a q1 b q2 q3
Language accepted
q0 a q1 b q2 q3
Example
• NFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q1, q2}
– δ(q0, b) = {q0}
– δ(q1, a) = {q1}
– δ(q1, b) = {q0, q2}
– δ(q2, a) = ∅
– δ(q2, b) = {q2}
• Start State: q0
• Accept States: {q2}
• Question: Does the NFA accept the string "aab"?
Example
• NFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q0, q1}
– δ(q0, b) = {q2}
– δ(q1, a) = {q2}
– δ(q1, b) = ∅
– δ(q2, a) = {q2}
– δ(q2, b) = {q1}
• Start State: q0
• Accept States: {q2}
• Question: Does the NFA accept the string "baa"?
Example
• NFA Description:
• States: Q = {q0, q1, q2, q3}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q1}
– δ(q0, b) = {q0, q2}
– δ(q1, a) = {q3}
– δ(q1, b) = {q1}
– δ(q2, a) = ∅
– δ(q2, b) = {q3}
– δ(q3, a) = {q3}
– δ(q3, b) = ∅
• Start State: q0
• Accept States: {q3}
• Question: Does the NFA accept the string "abbb"?
Example
• NFA Description:
• States: Q = {q0, q1, q2, q3}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q0, q1}
– δ(q0, b) = {q2}
– δ(q1, a) = {q3}
– δ(q1, b) = {q1, q2}
– δ(q2, a) = {q1}
– δ(q2, b) = {q3}
– δ(q3, a) = {q0}
– δ(q3, b) = ∅
• Start State: q0
• Accept States: {q3}
• Question: Does the NFA accept the string "abb"?
Example
• NFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q1}
– δ(q0, b) = {q2}
– δ(q1, a) = {q0, q1}
– δ(q1, b) = {q2}
– δ(q2, a) = ∅
– δ(q2, b) = {q1, q2}
• Start State: q0
• Accept States: {q1}
• Question: Does the NFA accept the string "aab"?
Moore and Mealy Machine
• Basics:
• DFA and NFA are the finite automata
without Output, where Moore and Mealy
are the finite automata with output.
• Moore machine always give output in
+1 form, if length of string is n then
output will be n+1.
• Example: Input String = 11010 Then
• Output will be Length of String + 1 =
5+1 =6
Cont.
• Mealy machine always give output in +0
form, if length of string is n then output
will be n.
• Example: Input String = 11010 Then
• Output will be Length of String = 5
Moore Machines
• Moore Machines are finite state machines
with output value and its output depends
only on the present state. It can be
defined as (Q, q0, ∑, , δ, λ) where:
• Q is a finite set of states.
• q0 is the initial state.
• ∑ is the input symbol.
• is the output symbol.
• δ is the
transition function which maps Q×∑ → Q.
• λ is the output function which maps Q → .
Cont.
Moore
Machine
0 0
1 0 q2/b
q0/a q1/b
1 1
Cont.
•λ:Q= (What will be Output
Corresponding to states?)
Cont.
• If Input string 101101
• Then Output will be 101101= 6 + 1 =7
0 0
1 0 q2/b
q0/a q1/b
1 1
• Output = abbbaab
Cont.
• Class Work:
Input String are as mentioned below,
what will be output?
1.11101000
2.1101
3.0000110101
4.0001101010
5.1010101010
6.101011110011
Mealy Machines
b/1
q0 q1
b/0
Cont.
• λ : Q x ∑ -> (What will be Output
Corresponding to states?)
Cont.
• If Input string abbab
• Then Output will be abbab = 5
• Output = 01001
Cont.
• Class Work:
Input String are as mentioned below,
what will be output?
1.aaababababa
2.bbbbaaaa
3.bababaaab
4.babababbbaa
5.babaababaaa
6.ababababaabb
Regular Language
• A regular language is a language that can
be expressed with a regular expression or a
deterministic or non-deterministic finite
automata or state machine.
• A language is a set of strings which are
made up of characters from a specified
alphabet, or set of symbols.
• Example:
• L1 =
{a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa…..}
• L2 = {ab,abab,ababab,abababab…….}
Regular Expression
• We use regular expression to represent
regular languages.
• Let, R be the regular expression over
alphabet Σ, if R is,
– ε is regular expression, denoting a set {ε}
R = ε and L(R) = {ε}
– Φ is regular expression, denoting a set {Φ}
R = Φ and L(R) = { }
– For each symbol a ∈ Σ, here a is regular
expression, denoting a set {a}
R = a and L(R) = {a}
Cont.
• R1 ∪ R2 = Regular Expression (Union), this
can also represent as R1 + R2
• R1 x R2 = Regular Expression (Concatenation)
• a* is regular expression
– a*is kleene closer, it contains all strings.
– a* = {ε,a,aa,aaa,aaaa,aaaaa,aaaaaa……}
NFA to DFA
CONVERSIONS
Example
• Create an NFA, in which 2nd last bits of
binary string will be 1.
1 0,1
q0 q1 q2
0,1 State 0 1
q0 q0 q0.q1
q1 q2 q2
q2 - -
Cont.
State 0 1
q0 q0 q0q1
q0q1 q0q2 q0q1q2
q0q2 q0 q0q1
q0q1q2 q0q2 q0q1q2
Cont.
0
1
q0 q0q1
1
0 1
0
q0q2 q0q1q2 1
0
Example
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
*q2 q2 {q1, q2}
Cont.
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
*q2 q2 {q1, q2}
State 0 1
State 0 1
State 0 1
State a b
q0 q1 q2
q1 q3 q4
q2 q3 q5
q3 q3 q1
q4 q4 q5
q5 q5 q4
q6 q2 q6
Cont.
Transition Table
Minimization
• Remove unreachable
state from initial state.
• q6 is unreachable state
from initial state qo.
• Therefor, q6 eliminated
from the DFA.
Cont.
Transition Table
Minimization
• Now convert all state in equivalent group.
• One group will be final states and another
one will be non-final states.
q0 q3
a
a,b b
a,b
b
q1q2 q4q5
REGULAR LANGUAGE &
EXPRESSION
Regular Language
• A regular language is a language that can be
expressed with a regular expression.
– ε is regular expression, denoting a set {ε}
R = ε and L(R) = {ε}
– Φ is regular expression, denoting a set {Φ}
R = Φ and L(R) = { }
• A language is a set of strings which are made up
of characters from a specified alphabet, or set of
symbols.
• Example:
• L1 = {a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa…..}
• L2 = {ab,abab,ababab,abababab…….}
Cont.
• R1 ∪ R2 = Regular Expression (Union), this
can also represent as R1 + R2
• R1 x R2 = Regular Expression (Concatenation)
• a* is regular expression
– a*is kleene closer, it contains all strings
including null.
– a* = {ε,a,aa,aaa,aaaa,aaaaa,aaaaaa……}
– a+ = a*- ε = aa* is positive closer, it
contains all strings excluding null.
– a+ =
{a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa……}
Cont.
• If Σ (a,b) then Regular expression for
Finite regular language can be…
Language Expression
No string: { } Φ
Length 0: {ε} ε
Length 1: {a,b} (a+b)
Length 2: {aa,ab,ba,bb} Either aa+ab+ba+bb OR
(a+b)(a+b)
Length 3: {aaa,aab,aba……} (a+b)(a+b)(a+b)
At most 1: {ε,a,b} (ε+a+b)
At most 2:{εε, εa, (ε+a+b)
εb,aε,aa,ab,bε,ba,bb} (ε+a+b)
Not more than 2 b’s and 1 a’s: {ε, a,b, ε + a + b + b (a+b)
ab, ba, bb, abb, bab……}
Cont.
• If Σ (a,b) then Regular expression for
Infinite regular language can be…
Language Expression
All string having single “b” a* b a*
All string having at least one “b” (a+b)* b (a+b)*
All string having at least “bbbb” as (a+b)* bbbb (a+b)*
substring
All string having at least “ab” (a+b)* ab (a+b)*
All string starting with “ba” ba (a+b)*
All string beginning and ending with a (a+b)* a
“a”
All string containing “a” (a+b)* a (a+b)*
All string starting and ending with (a (a+b)* b + b (a+b)* a)
different symbol
Pumping Lemma
• Pumping Lemma is used as proof of the
irregularity of a language. It means, that if
a language is regular, it always satisfies
the pumping lemma. If at least one string
is made from pumping, not in language A,
then A is not regular.
• Why we use pumping lemma?
– To check weather language is regular or not.
• Language can finite or infinite, if language
is finite then its always regular.
Cont.
• If L is an infinite language, then there
exists some positive integer “n”
9pumping length) such that any string w
belongs to L has a length greater than
equal to “n” is |w| >= n, then w can be
divided in to three parts: w = xyz
satisfied following condition.
• 1) for each i >= 0, xy’z belongs to L
• 2) |y| > 0
• 3) |xy| < = n
Cont.
• Pumping lemma is negative test to
check, that weather language is regular
or not.
Pass
PL Undecided
Fail
Definitely not regular
Cont..
• Need to take any string from language,
then need to divide it in to 3 parts (i.e.
xyz)
• After we need to pump y, that means
need to increase y=yy or yyy or yyyy
• Therefore, xyz can be xyyz or xyyyz or
xyyyyz, then need to check weather this
string pass the test or not.
• Note: Y length, always > 0, that means
y can not be epsilon.
Example
• Suppose, we have a language a power n,
b power 2n, where n >= 0.
• Now we take one string from given
language, w= aabbbb
• Now we divide it in to 3 parts,
• x=aa, y=bb and z=bb
• Now pump value of y, that means
increase value of y.
– Therefore, now x=aa, y=bbbb and z=bb
– Now need to check, weather this string
belongs to language?
Cont.
• No, its not belongs to language so its fail in
test, that means language is not regular.
• Because, a power n and b power 2n gven
in language but after pumping b increased
and its not satisfied language given.
• Check for,
1)Language a power n and b power n
2) Language a power 2n and b power n
Arden’s Theorem
• P and Q are two regular expression over Σ
and, if P does not contain ε then the
following equation in R given by;
• R = Q+RP has unique solution, that is
R=QP*
– Lets prove same,
– R = Q+RP
– = Q+(Q+RP)P
– = Q+QP+RPP
– = Q+QP+RP^2
– =Q+QP+(Q+RP) P^2
– =Q+QP+QP^2+RP^3
– =Q(P^0+P+P^2+P^3+……
– =QP*
Example
Example-1 a,b
a
A B
a
NFA (With null Move) to DFA
• Σ (a,b)
b a,b
a
ε a
q0 q1 q
2
q0q1
Cont.
• Further, we will check transition for new
generated state.
• Here, we need to check transition for q0 and q1
state, because new generated state is
combination of these two states.
• We check transition for all input alphabet; here we
have a and b as input alphabet so,
– For input alphabet a, we have four transition for
new state,
• One for q0, it self in self-loop
• Second from qo to q1 (As null move given in NFA)
• Third from q0 to q2 (As null move and next path
have a itself)
• Fourth from q1 to q2
Cont.
• Now we take union of q0 and q1
• Therefore, q0 U q1 = q0q1q2 U q2
= q0q1q2
a
q0q1 q0q1q2
q1
b b
q1 q1q2
q0q1 a q0q1q2 a
b b
b q1 q1q2
a
q2
Cont.
• Now we check for q1q2 and q2
a
q0q1 q0q1q2 a
b b
b q1 q1q2 b
a a
q2
a,b
Class Work
• Example b a,b
a
ε a
q0 q1 q
2
a
ε
q4 q3
Class Work
• Example b a,b
a
ε a
q0 q1 q
2
ε a
q4 q3
Myhill-Nerode Theorem
• Myhill-Nerode theorem is used to
minimize the DFA.
• Important Steps:
1. Draw a table for all pairs of states (P,Q)
2.Mark all pairs, where P ∈ F and Q ∉ F.
3.If there are any unmarked pair (P,Q)
such that [δ (P,x), δ (Q,x)] is marked,
then mark [P,Q]. Here x is input symbol.
4.Combine all the unmarked pairs and
make them a single state.
Cont..
• Example
1 1
B D F 0,1
0 1
0 0 1
A C 0
E 0
1
A B C D E F
A
B
C
D
E
F
Cont.
• For Marking pair, create a Table. First,
count total number of state, then create
Table for same.
A B C D E F
A
B
C
D
E
F
Cont.
• Now, we will mark respective cell, If in any
pair single state is final and another one is
non-final, then we mark particular cell.
A B C D E F
A
B
C
D
E
F
• First Cell is AB
• Both state is non-final, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M
D
E
F
• Next Cell is CA
• C is final state and A is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D
E
F
• Next Cell is CB
• C is final state and B is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M
E
F
• Next Cell is DA
• D is final state and A is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E
F
• Next Cell is DB
• D is final state and B is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E
F
• Next Cell is DC
• D is final state and C is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M
F
• Next Cell is EA
• E is final state and A is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is EB
• E is final state and B is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is EC
• E is final state and C is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is ED
• E is final state and D is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in any
pair, single state is final and another one is
non-final, then we mark particular cell.
A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is FA
• F is not final state and A is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in any
pair, single state is final and another one is
non-final, then we mark particular cell.
A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is FB
• F is not final state and B is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F M
• Next Cell is FC
• F is not final state and B is final, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F M M
• Next Cell is FD
• F is not final state and D is final, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F M M M
• Next Cell is FE
• F is not final state and E is final, so we mark.
Cont.
(F,B) – δ (F,0) = F
- δ (B,0) = A
Here, we Check weather output Pair mark or not? Here
for input 0, FA pair come and its already marked so we
Cont.
• Now, we will combine all unmarked pairs, So
• (A,B), (D,C), (E,C) and (E,D) are unmarked
pairs.
• (A,B) is in one group and both are intermediate
state so we create one state for this
combination.
• And all other combinations are final sate, so we
combined (C,D,E) in one state.0 0,1
0
1 1
AB CDE F
b b
A B C
Cont.
• Example: (a+b) c
• First we need to generate strings from
above language, So
• ac
• bc
• So we can design below FA.
a
c
A B C
b
Cont.
• Example: a(bc)*
• First we need to generate strings from
above language, So
•a
• abc
• abcbc
• abcbcbc a
A B
b c
C
RG to RE (Grammar to Expression)
• Its Regular Grammar, Which generated
regular language, which is accepted by
finite automata.
RG
RL
FA
Cont…
Finite
Automata
Regular
Expressio
n
Regular Regular
Language Gramma
r
Cont…
• Convert the following left recursive
grammar in to Regular Expression.
• A Aa/b
A A
b A a
A a
Answer: ba*
A b
Cont..
• AAa/b1/b2
• Answer: (b1+b2)a*
• AAa/b1/b2/………bn
• Answer: (b1+b2+……+bn)a*
• AAa1/Aa2/b
• Answer: (a1+a2)*b
• AAa1/Aa2/……Aan/b
• Answer: (a1+a2+……+an)*b
• AAa1/Aa2/………Aan/b1/b2………bn
• Answer: (a1+a2+…….+an)* (b1+b2+…..
+bn)*
Examples
• S01S/01
• Answer: (01)* 01 = 01^+
• S0011S/01/10
• Answer: (0011)* (01+10)
• S01A/B11
• 01(011)*01 + (101)*1111
• A011A/01
• (011)*01
• B101B/11
• (101)*11
Cont…
• S011A/101B
• A110A/00
• B11B/S
• Answer:
• A110A/00 (110)*00
• Now, I put value of A in S,
• S0011(110)*00/101B
• Now I solve B
• B11B/S (11)*S
• Now Solve S:
• S0011(110)*00/101(11)*S
• (101(11)*)*0011(110)*00
RL to RG
• a*bc
• a*b*c*(x+y)
• (a+b+c+d)z*
• a^+
Right RG to FA
• S01S/1
Cont…
• S011S/01
Cont…
• S001S/10A
• A101A/0/1
Left RG to FA
• Reverse the right hand side of every
production
• Construct FA
• Interchange initial state and final state
• Change the direction of edges
Cont…
• SS10/01
• S01S/10
Example
• S0101S/10
• SS110/01
Regular Expressions
• 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.
Regular Expression
Phi- Empty Set; Epsilon- Null String: String is there but its null
• 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, .....}
Regular Expressions
We give a formal recursive definition of regular expressions over
∑ as follows:
1. Any terminal symbol (i.e. an element of ∑), Λ and ∅ are
regular
expressions. When we view a in ∑ as a regular expression, we
denote it by a.
2. The union of two regular expressions R1and R2 , written as R 1 +
R2, is also a regular expression.
3. The concatenation of two regular expressions R1and R2, written
as
R1 R2, is also a regular expression.
4. The iteration (or closure) of a regular expression R written as R*,
is
also a regular expression.
5.If R is a regular expression, then (R) is also a regular expression.
6. The regular expressions over∑ are precisely those obtained
recursively by the application of the rules 1-5 once or several times
Definitions
Any set represented by a regular
expression is called a regular set.
If for example, a, b ε ∑. Then
(i) a denotes the set {a},
(c) As {01, 10} is the union of {01} and {10}, we have {01, 10}
represented by 01 + 10
Solution:
The regular expression will be:
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.
Example 4
• Write the regular expression for the language
accepting all the string which are starting with
1 and ending with 0, over ∑ = {0, 1}.
Example 4
• Write the regular expression for the language
accepting all the string which are starting with
1 and ending with 0, over ∑ = {0, 1}.
Solution:
In a regular expression, the first symbol should be 1, and the
last symbol should be 0. The r.e. is as follows:
R = 1 (0+1)* 0
Example 5
• Write the regular expression for the language
starting and ending with a and having any
having any combination of b's in between.
Example 5
• Write the regular expression for the language
starting and ending with a and having any
having any combination of b's in between.
• Solution:
The regular expression will be:
R = a b* b
Example
• Write the regular 6
expression for the
language starting with a but not having
consecutive b's.
Example
• Write the regular 6
expression for the
language starting with a but not having
consecutive b's.
Solution:
The regular expression has to be built for the
language:
L = {a, aba, aab, aba, aaa, abab, .....}
The regular expression for the above
language is:
R = {a + ab}*
Example 7
Write the regular expression for the language accepting
all the string in which any number of a's is followed
by any number of b's is followed by any number of
c's.
Example 7
Write the regular expression for the language accepting
all the string in which any number of a's is followed
by any number of b's is followed by any number of
c's.
• Solution:
As we know, any number of a's means a* any number of b's means
b*, any number of c's means c*. Since as given in problem
statement, b's appear after a's and c's appear after b's. So the
regular expression could be:
R = a* b* c*
Example 8
• Write the regular expression for the language
over ∑ = {0} having even length of the string.
Example 8
• Write the regular expression for the language
over ∑ = {0} having even length of the string.
Solution:
The regular expression has to be built for the
language:
L = {ε, 00, 0000, 000000, ......}
The regular expression for the above language
is:
R = (00)*
Example 9
• Write the regular expression for the
language having a string which should
have atleast one 0 and alteast one 1.
Example 9
• Write the regular expression for the
language having a string which should
have atleast one 0 and alteast one 1.
Solution:
The regular expression will be:
R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*] + [(0
+ 1)* 1 (0 + 1)* 0 (0 + 1)*]
• Describe the language denoted by
following regular expression
RE. = (b* (aaa)* b*)*
• Describe the language denoted by
following regular expression
RE. = (b* (aaa)* b*)*
The language can be predicted from the regular
expression by finding the meaning of it. We will first
split the regular expression as:
r.e. = (any combination of b's) (aaa)* (any combination
of b's)
L = {The language consists of the string in which a's
appear triples, there is no restriction on the number
of b's}
Problem
Solution
IDENTITIES FOR
REGULAR
`
EXPRESSIONS
Which among the following are incorrect
regular identities?
a) εR=R
b) ε*=ε
c) Ф*=ε
d) RФ=R
Answer: d
Explanation: I2: There are few identities
over Regular Expressions which include:
RФ=ФR=Ф
(0+ε) (1+ε) represents
a) {0, 1, 01, ε}
b) {0, 1, ε}
c) {0, 1, 01 ,11, 00, 10, ε}
d) {0, 1}
Answer: a
Explanation: The regular expression is
fragmented and the set of the strings
eligible is formed. ‘+’ represents union
while ‘.’ Represents concatenation.
Which of the following is correct?
Statement 1: ε represents a single string in the set.
Theorem :
(Arden' s theorem) Let P and Q be two regular
expressions over ∑. If P does not contain Λ, then
the following equation in R, namely
R = Q + RP
has a unique solution (i.e. one and only one
solution) given by R = QP*.
Ardens Theorem
Example 1: Constructing RE for
NDFA
Example 2: Constructing RE for
DFA
Example 3
Example 4
P, O, R be regular expression over ∑, P is
not ε, then
R=Q + RP has a unique solution:
a) Q*P
b) QP*
c) Q*P*
d) (P*O*) *
Arden’s theorem is true for:
a) More than one initial states
b) Null transitions
c) Non-null transitions
d) None of the mentioned
Answer: c
Explanation: Arden’s theorem strictly
assumes the following;
a) No null transitions in the transition
diagrams
b) True for only single initial state
Closure Properties of Regular
Language
THEORM
Proof
Q + (QP*)P = Q(Λ+ P*P) = QP* by I9
Important justification
PROBLEM
SOLUTION
PROBLEM & SOLUTION
Difference between Null and Ø
TRANSITION SYSTEM CONTAINING Λ -
MOVES
Suppose we want to replace a Λ -move from vertex V1 to vertex
V2' Then
we proceed as follows:
• Input:
•a*b+c
Cont…
Step 1 Step 2
Step 3
Step 4
Step 5
POLLING QUESTIONS
1. Which of the following statement is
false?
• P: S = aSb | SS |∈
• For the string aabb, the above
grammar generates two parse trees:
Practice Questions
1. Check whether the given grammar is ambiguous
or not-
S → SS| a| b
• Context-free languages
are closed under −
– Union
– Concatenation
– Kleene Star operation
Context-free languages
are not closed under
•Intersection − If L1 and L2 are context free
languages, then L1 ∩ L2 is not necessarily
context free.
• Reduction of CFG
– Removal of Unit Productions
– Removal of Null Productions
Remove Unit Production
• SAB
• Aa
SAB
• BC/b Aa
• CD Ba/b
• DE
• Ea
• Rules to remove unit production:
– Left and right side if have single variable then its
known as unit production.
– Apply Dependency graph, if possible.
– Remove unreachable Variable.
Cont…
• SaA/B
• Aba/bb
• BA/bba
• Solution:
• SaA/bba/ba/bb
• Aba/bb
Remove Null Production
• SaS/A
• A ε
• Solution:
• Here A produce null so remove A.
• Also, S produce A but A is null so value
of S will be null. Apply same over
grammar S.
• Therefore SaS/ε/a (Here, ε still
available because, its part of language)
Example
• SABC
• AaA/ε
• BbB/ε
• Cc
• Solution:
– A and B both Produce null. So we replace same
from grammar.
– SABC/BC/AC/C
– AaA/a
– BbB/b
– Cc
Chomskey Normal Form
• CNF stands for Chomsky normal form. A
CFG(context free grammar) is in
CNF(Chomsky normal form) if all
production rules satisfy one of the
following conditions:
– A non-terminal generating two non-
terminals. For example, S → AB.
– A non-terminal generating a terminal. For
example, S → a.
• ABC
• Aa
Cont…
• Convert CFG to CNF
• SaB/bA/R
• Aa/aS/aBA
• Bb/bS/aAAB
• Db/bc
• Step-1: Simplified CFG
• SaB/bA/R
SaB/bA
• Aa/aS/aBA Aa/aS/aBA
• Bb/bS/aAAB Bb/bS/aAAB
• Db/bc
Cont…
• Step-2:
Production Solution
Aa Aa
AaS AC1S, C1a
AaBA AC1C2, C2BA
Bb Bb
BbS BC3S, C3b
BaAAB BC4C5, C4C1A,
C5AB
SaB SC1B
SbA SC3A
Cont…
• Final Answer in form of CNF:
• Aa/C1S/C1C2
• Bb/C3S/C4C5
• SC1B/C3A
• C1a
• C2BA
• C3b
• C4C1A
• C5AB
Problem
• Solution:
• SaAB/bB
• Aa/b
• Bb
Problem
1. Convert the following CFG into GNF
S → XY | Xn | p, X → mX | m, Y → Xn |
o
w = uvxyz, where
vy ≠ ε,
|vxy| ≤ p,
and for all i ≥ 0, uvixyiz ∈ L
Cont.
• Pumping lemma is negative test to
check, that weather language is not
CFL.
Pass
PL Undecided
Fail
Definitely not CFL
Example
• Find out whether the language L =
{xnynzn | n ≥ 1} is context free or not.
• Solution:
• Let assume L is context free.
Then, L must satisfy pumping lemma.
• Pick string from given language L (i.e.
W=x power ^3, Y power^3 and z
power^3) so it will looks like,
• xxxyyyzzz
Cont…
• Now divide given string in five parts (i.e.
u,v,x,y,z), So
• xx x yy y zzz
•u v x y z
• a) S → aSB, B →bB I λ
• b) S → aSB, B →bB I b
• c) S → aSB I b, B→b
• d) S → aSB I b
Cont…
The Greibach normal form grammar for
the language L = {an bn+1 | n ≥ 0 } is
• a) S → aSB, B →bB I λ
• b) S → aSB, B →bB I b
• c) S → aSB I b, B→b
• d) S → aSB I b
Cont..
1. In pumping lemma for
context free language
a) We start by assuming the given
language is context free and then we
get contradict
b) We first convert the given language
into regular language and then apply
steps on
c) Both (a) and (b)
d) None of these
Cont..
1. In pumping lemma for
context free language
a) We start by assuming the given
language is context free and then
we get contradict
b) We first convert the given language
into regular language and then apply
steps on
c) Both (a) and (b)
d) None of these
Cont…
The format: A->aB refers to which of the
following?
Γ Z0
Stack
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0
q0
• We have input 0, so tau at Z0 (i.e. 0,Z0).
• Now in PDA, Machine first POP Z0, then it 0
• will reinsert Zo and 0 in Stack. Z0 Γ
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0
0,0/00
q0
• We have input 0, so tau at 0 (i.e. 0,0).
0
• Now in PDA, Machine first POP 0, then it
• will reinsert 0 and 0 in Stack.
0 Γ
Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0 ,0/00
q0 1,0/0
q1
• We have input 1, so tau at 0 (i.e. 1,0). 0 Γ
• Now in PDA, Machine first POP 0 and reinsert
0
• 0 again, then move towards new state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input 1, so tau at 0 (i.e. 1,0).
• Now in PDA, Machine first POP 0 and reinsert
0 Γ
• ε, then move towards new state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z 1,0/0
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input 1, so tao at 0 (i.e. 1,0).
• Now in PDA, Machine first POP 0 and reinsert
0 Γ
• 0 again, then move towards previous state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z 1,0/0
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input 1, so tau at 0 (i.e. 1,0).
• Now in PDA, Machine first POP 0 and then
Γ
• reinsert ε and move towards next state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language: q3
0 0 1 1 1 1 ε
Z0
/
Z0
0,Z0/0Z 1,0/0
ε,
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input ε, so tau at Z0 (i.e. ε,Z0).
• Now in PDA, Machine first POP Z0 and then
• move towards final state Z0 Γ
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language: q3
0 0 1 1 1 1
Z0
/
Z0
0,Z0/0Z 1,0/0
ε,
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have not input, and tau at ε (i.e. Stack
• empty) So process done.
Γ
DPDA and NPDA
• We can create NPDA for all CFL, but
cant create DPDA for all CFL.
• As we know, PDA is nothing but Finite
automata + Stack.