Unit 1 Combined
Unit 1 Combined
➢ The term “Automata” comes from the Greek word “αὐτόματα” which implies
“self-acting”. An automaton (Automata in plural) is an abstract self-propelled
machine which follows a predetermined sequence of operations automatically.
➢ The FSM can change from one state to another in response to sequence of inputs;
the change from one state to another is called a transition.
➢ An FSM is defined by a list of its states, its initial state, its final state(s) and the
➢ Example 4: Controller used for an automatic sliding door (simple example of a FSM)
Automata Formal Languages & Logic
Introduction
Finite automata can naturally model microprocessors and even software programs working on
variables with bounded domain – capture so-called regular sets of sequences that occur in many
different fields (logic, algebra, regEx).
Applications in digital circuit/protocol verification, compilers, pattern recognition/matching, etc.
Automata Formal Languages & Logic
Introduction – Formal Languages
Formal Languages:
➢Words that belong to a particular formal language are sometimes called well-
formed words or well-formed formulas. A formal language is often defined by
means of a formal grammar such as a regular grammar or context-free
grammar, which consists of its formation rules.
Automata Formal Languages & Logic
Introduction – Formal Languages
Formal Languages:
➢Automata theory is closely related to formal language theory. In this context,
automata are used as finite representations of formal languages that may be infinite.
➢Automata(or FSMs) are often classified by the class of formal languages they can
recognize, as in the Chomsky hierarchy, which describes a nesting relationship
between major classes of automata.
➢ Formal languages are languages which only consider about the well-formedness nothing
else. That means the sufficient and necessary condition is to adhere to its rules.
❑ L = {a}* = {an}, where n ranges over the natural numbers and "an" means "a" repeated n times (this
is the set of words consisting only of the symbol "a");
❑ The set of syntactically correct programs in a given programming language (the syntax of which is
usually defined by a context-free grammar);
❑ The set of maximal strings of alphanumeric ASCII characters on this line, i.e.,
the set {the, set, of, maximal, strings, alphanumeric, ASCII, characters, on, this, line, i, e}.
Automata Formal Languages & Logic
Introduction – Formal Languages
➢ Formal languages are normally defined in one of three ways, all of which
can be described by automata theory:
➢ Formal languages are normally defined in one of three ways, all of which
can be described by automata theory:
Automata
5. Natural Language Processing: Finite automata are used in natural language processing
for tasks such as text tokenization, morphological analysis, and part-of-speech tagging.
They help in parsing and understanding the structure of natural language sentences.
Automata Formal Languages & Logic
Applications
• 6. Digital Circuit Design: Finite automata can model the behavior of digital circuits and
aid in their design and testing. Sequential circuits, such as counters and state machines,
can be represented and analyzed using finite automata.
• 7. Network Protocol Design and Analysis: Network Protocol Design and Analysis: FSMs
are employed to model and analyze communication protocols (e.g., TCP/IP, HTTP, …),
They help to ensure correct message sequencing and behaviour.
9. ….
Automata Formal Languages & Logic
Introduction - Course Textbook
Automata Formal Languages & Logic
Introduction - Course Evaluation Policy
Automata Formal Languages & Logic
Introduction - Additional Info
Tree Automata:
➢ Most machine models like Turing machines and finite automata, work on inputs that are
strings over some finite alphabet. However, often problem descriptions have inputs
that more structured than strings. For example, the input could be a graph, or a tree,
or a partial order, etc.
Automata Formal Languages & Logic
Introduction – Additional Info
➢ Mathematical logic and automata theory are two scientific disciplines with a
fundamentally close relationship.
Automata Formal Languages & Logic
Introduction – Additional Info
Prakash C O
Department of Science & Engineering
Automata Formal Languages & Logic
Unit 1 – Basic Notations
▪ Alphabet (𝜮 )
▪ String or word (w)
▪ Empty String [ (“epsilon”) or λ (“lambda”)]
▪ Length of a String ( |w| )
▪ Powers of an Alphabet (𝜮k )
▪ Kleene Closure or Kleene Star or Kleene operator(*)
▪ Kleene Plus (+)
▪ Zero or one occurrence (?)
▪ Language ( L )
Automata Formal Languages & Logic
Unit 1 – Basic Notations
Alphabet (𝜮):
➢ Examples:
▪ Binary: ∑ = {0,1}
▪ All lower case letters: ∑ = {a,b,c,..z}
▪ Alphanumeric: ∑ = {a-z, A-Z, 0-9}
▪ DNA molecule letters: ∑ = {a,c,g,t}
…
Automata Formal Languages & Logic
Unit 1 – Basic Notations
Powers of an alphabet:
• Let ∑ be an alphabet.
• ∑k = the set of all strings of length k
…..
Automata Formal Languages & Logic
Unit 1 – Basic Notations
Kleene star (or Kleene closure): Kleene star is a unary operation, either
on sets of strings or on sets of symbols or characters.
The application of the Kleene star to an alphabet ∑ is written as ∑*
If ∑ is an alphabet, then ∑* is the set of all strings over symbols in ∑,
including the empty string ε.
The definition of Kleene star on ∑ is
∑* = ∑0 U ∑1 U ∑2 U …
Kleene plus: The Kleene plus omits the ∑0 term in the above union.
In other words, the Kleene plus on ∑ is
∑+ = ∑1 U ∑2 U ∑3 U … i.e., the set of strings of length > 0
Automata Formal Languages & Logic
Unit 1 – Basic Notations
▪ q0 is the initial state from where any input is processed (q0 ∈ Q).
DFA:
Let’s draw the state diagram of the following automaton (Q, ∑, δ, q0, F)
Q = {q1, q2, q3}
∑ = {0,1},
δ is given in a tabular form below (i.e., transition table):
2. For every state, a transition is required for all the input symbols in ∑.
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
A run of M on w is
a a b a b b
q0 → q1 → q1 → q 2 → q1 → q2 → q 2 Accepted run/Computation because q2 ∈ F
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
A run of M on w is
a a b b b a
q0 → q1 → q1 → q 2 → q2 → q2 → q 1 Rejected run/Computation because q1 ∉ F
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 1:
Construct DFA for the Language of strings of length 2 , over Σ ={a,b} .
Solution :
Example 1:
Construct DFA for the Language of strings of length 2 , over Σ ={a,b} .
Trap/Dead state
Note1: strings of length 1 are rejected in q1 and strings of length>2 are rejected in q3
Note2: For every state, transition is required for all the input symbols in ∑
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 1a:
Construct DFA for the Language of strings of even length, over Σ ={a,b} .
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 1a:
Construct DFA for the Language of strings of even length, over Σ ={a,b} .
Example 1b:
Construct DFA for the Language of strings having even number of a’s, over Σ ={a, b} .
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 1b:
Construct DFA for the Language of strings having even number of a’s, over Σ ={a, b} .
Solution :
L = {, aa, aaaa, aaaaaa, aaaaaaaa, … , b, bb, bbb, bbbb, bbbbb, …
aab, baa, aba, … … }
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Exercise:
Construct DFA for the Language of strings having odd number of a’s, over Σ ={a, b} .
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 2:
Construct DFA for the language L = { w | w ∈ {a, b}* and |w| ≤ 2 }
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 2:
Construct DFA for the language L = { w | w ∈ {a, b}* and |w| ≤ 2 }
Trap/Dead state
Trap state is one from which we cannot escape, that is, it has either no transitions defined or
transitions for all symbols goes to itself.
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 3:
Construct DFA for the language L = { w | w ∈ {a, b}* and |w| ≥ 2 }
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 3:
Construct DFA for the language L = { w | w ∈ {a, b}* and |w| ≥ 2 }
Example 4:
Construct DFA for the language of strings starts with a, over Σ={a,b}.
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 4:
Construct DFA for the language of strings starts with a, over Σ={a,b}.
Trap/Dead state
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 5:
Construct DFA for the language of strings starts with a and ends with b, over
Σ ={a, b}.
Solution:
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 5:
Construct DFA for the language of strings starts with a and ends with b, over
Σ ={a, b}.
Trap/Dead state
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 6:
The language with strings over Σ ={a,b} where every string starts with ab
and ends with ab, over Σ ={a,b}.
Example 6:
The language with strings over Σ ={a,b} where every string starts with ab
and ends with ab, over Σ ={a,b}.
Trap/Dead state
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 6a:
The language with strings over Σ ={a,b} where every string starts with ab
and ends with ab, over Σ ={a,b}.
Example 7:
The language of strings over Σ ={a,b}, where every a in the string is followed
by bb.
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 7:
The language of strings over Σ ={a,b}, where every a in the string is followed
by bb.
or
Example 7a:
The language of strings over Σ ={a,b}, where every a in the string is never
followed by bb.
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 8:
The language of strings over Σ ={a,b} where every string must contain
“aa” as the substring.
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 8:
The language of strings over Σ ={a,b} where every string must contain
“aa” as the substring.
Example 9:
Construct DFA for the language of strings over Σ = {a,b} of the form anbm
where n, m ≥ 1.
Solution:
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 9:
Construct DFA for the language of strings over Σ = {a,b} of the form anbm
where n, m ≥ 1.
Trap/Dead state
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 10:
Construct DFA for the language of strings over Σ = {a,b} of the form anbm
where n, m ≥ 0.
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 10:
Construct DFA for the language of strings over Σ = {a,b} of the form anbm
where n, m ≥ 0.
Solution : L = {, a, aa, aaa, …, b, bb, bbb, …, ab, abb, aab, aabb, abbb, aaab,
aaabbb, … }
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 11:
Construct DFA for the language of strings over Σ={a,b} where na(w) mod 2 = 0.
Solution : L = {, aa, aaaa, aaaaaa, …, b, bb, bbb, …, aab, aba, baa, … }
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 11:
Construct DFA for the language of strings over Σ={a,b} where na(w) mod 2 = 0.
Solution : L = {, aa, aaaa, aaaaaa, …, b, bb, bbb, …, aab, aba, baa, … }
Explanation:
➢ In the DFA the states should represent the information
about the string processed so far.
➢ In this example, states have to represent only the number
of a's seen so far is even or odd, so only need two states q0
and q1. One state to represent “even” and another state to
represent “odd”.
➢ Before reading any symbol, the number of a's processed so
far is 0, which is even. Hence, the initial state q0 should
represent even. We want the DFA to accept the strings in L
(strings with even number of a’s). Hence, we should choose
q0 to also represent our accepting state.
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 12:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 2=0
and nb(w)mod 2=0
Solution:
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 12:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 2=0
and nb(w)mod 2=0
Solution:
This state represents, seen so far odd
number of a’s and even number of b’s.
Note:
➢ State 00 is final state for strings having Even number of a’s and Even number of b’s. (i.e., na(w)mod 2=0 and
nb(w)mod 2=0)
L = { ε, aa, aaaa, aaaaaa, …,
bb, bbbb, bbbbbb, …,
aabb, bbaa, abab, baba, abba, baab, … }
➢ State 10 is final state for strings having 0dd number of a’s and Even number of b’s. (i.e., na(w)mod 2=1 and
nb(w)mod 2=0)
L = { a, aaa, aaaaa, aaaaaaa, …,
abb, bab, bba, abbbb, babbb, …,
aaabb, bbaaa, … }
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Note:
➢ State 01 is final state for strings having Even number of a’s and 0dd number of b’s. (i.e., na(w)mod 2=0 and
nb(w)mod 2=1)
L = { b, bbb, bbbbb, bbbbbbb, …,
baa, aba, aab, baaaa, abaaa, …, bbbaa, aabbb, … }
➢ State 11 is final state for strings having Odd number of a’s and 0dd number of b’s. (i.e., na(w)mod 2=1 and
nb(w)mod 2=1)
L = { ab, aaabbb, aaaaabbbbb, aaaaaaabbbbbbb, …,
ba, bbbaaa, bbbbbaaaaa, bbbbbbbaaaaaaa, …,
ababab, ababababab, …, bababa, bababababa, …, aabbba, abbbaa, …,}
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Note:
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 13:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 3=0 and
nb(w)mod 2=0.
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 13:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 3=0 and
nb(w)mod 2=0.
Example 14:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 3=0 and
nb(w)mod 3=0
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 14:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 3=0 and
nb(w)mod 3=0
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 15:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 3 = 2
and nb(w)mod 3 = 1
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 15:
Construct DFA for the language of strings over Σ={a,b} where, na(w)mod 3 = 2
and nb(w)mod 3 = 1
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 16:
Construct DFA for a binary number divisible by 2 and Σ ={0,1}. i.e., w mod 2 = 0)
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 16:
Construct DFA for a binary number divisible by 2 and Σ ={0,1}. (i.e., w mod 2 = 0)
or
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 16a:
Construct DFA for a binary number where w mod 2 = 1
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 16a:
Construct DFA for a binary number where w mod 2 = 1
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 17:
Construct a DFA for binary number divisible by 3. (i.e., w mod 3 = 0).
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 17:
Construct a DFA for binary number divisible by 3. (i.e., w mod 3 = 0).
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Example 18:
Construct a DFA for binary number divisible by 4. (i.e., w mod 4 = 0).
Solution :
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Exercise:
1. Construct DFAs to recognize C-language
▪ Identifiers,
▪ Integers
▪ Floating point numbers.
2. Construct DFAs to recognize C-language keywords
▪ for
▪ while
▪ switch
3. Construct a DFA to recognize all the relational operators in C-language.
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Exercise:
4. Construct DFAs for the validation of
▪ PAN number
▪ Aadhar number
▪ Email-id
▪ Phone number
5. …
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Non-regular languages are those for which no DFA exists. These languages
have patterns or structures that cannot be recognized by a finite
automaton.
Note:
➢ Every NFA has an equivalent DFA (accepting the same language).
➢ The languages accepted by Finite State Machines (DFA, NFA, ε-NFA …) are
referred to as Regular languages (can be described by regular expressions).
➢ Regular Expression is a concise way to describe a set of strings.
➢ For any DFA, there exists a regular expression to describe the same set of strings; for
any regular expression, there exists a DFA that recognizes the same set.
➢ DFA that accepts nothing has no final states.
➢ There is a unique minimal DFA for every regular language.
Automata Formal Languages and Logic
Unit 1 - Deterministic Finite Acceptor/Automata
Prakash C O
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
▪ q0 is the initial state from where any input is processed (q0 ∈ Q).
Why NFA?
➢ NFAs were introduced in 1959 by Michael O. Rabin and Dana Scott, who also
showed their equivalence to DFAs.
➢ Here the power set (i.e., P(Q)=2Q) has been taken because in case of an NFA,
from a state, transition can occur to any combination of Q states.
{q0 , q1 ,q2}
}
δ(q2,a) = {}
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
▪ each of its transitions is uniquely determined by its source state and input symbol, and
▪ reading an input symbol is required for each state transition.
➢ A nondeterministic finite automaton (NFA), does not need to obey the above
restrictions of DFA. In particular, every DFA is also an NFA. NFA may have several arrows
of the same label starting from a state.
Computation in NFA
➢ For an input string, NFA will create a ‘computation tree’ rather than a
‘computation sequence’ in case of DFA.
An NFA accepts a string if any one of the paths in the tree leads to some accept
state.
➢ Nondeterminism in NFA causes multiple runs. There can be several or no runs for
a given input word.
If there is at least one run that leads to an accepting state, the machine will
accept the input string.
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
NFA Construction:
Example 1: Construct NFA for the language of binary strings having at least
a pair of ‘00’ or a pair of ‘11’
Solution:
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
NFA Construction:
Example 1: Construct NFA for the language of binary strings having at least
a pair of ‘00’ or a pair of ‘11’
Solution:
or
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 2: Construct NFA for the language of strings ends with a, over ∑ ={a, b}
Solution:
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 2: Construct NFA for the language of strings ends with a, over ∑ ={a, b}
Solution: L={ a, aa, ba, bba, baa, aaa, aba, aaaa, aaba, abba, baba, bbba, … }
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 3: Construct NFA for the language of strings, where the second symbol
from the RHS of a string is ‘a’ and ∑ = {a, b}
Solution:
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 3: Construct NFA for the language of strings, where the second symbol
from the RHS of a string is ‘a’ and ∑ = {a, b}
Solution: L={ aa, ab, aab, baa, bab, aaa, aaaa, aaab, abab, baab, bbab, … }
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 4: Design an NFA in which all the string contain a substring 1110
and ∑ = {0, 1}
Solution:
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 5: Design an NFA with ∑ = {0, 1} accepts all string in which the
third symbol from the right end is always 0.
Solution:
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
➢ It is important because NFAs can be used to reduce the complexity of the mathematical
work required to establish many important properties in automata theory.
➢ For example, it is much easier to prove closure properties of regular languages using
NFAs than DFAs.
Automata Formal Languages and Logic
Unit 1: -Non-deterministic Finite Automata (-NFA)
▪ q0 is the initial state from where any input is processed (q0 ∈ Q).
or
Automata Formal Languages and Logic
Unit 1: -Non-deterministic Finite Automata (-NFA)
λ-closure(q1) = { q1 }
λ-closure(q2) = { q2 }
Automata Formal Languages and Logic
Unit 1: -Non-deterministic Finite Automata (-NFA)
-closure(0) =
-closure(6) =
Automata Formal Languages and Logic
Unit 1: -Non-deterministic Finite Automata (-NFA)
-closure(0) = { 0 1 2 4 7}
-closure(6) = { 6 7 1 2 4 }
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
Example 1: Construct -NFA for a language of strings that begins and ends with
the same symbol, and ∑ = {a, b}
Solution:
Automata Formal Languages and Logic
Unit 1: -Non-deterministic Finite Automata (-NFA)
Example 1: Construct -NFA for a language of strings that begins and ends with
the same symbol, and ∑ = {a, b}
Solution: L={, a, aa, aaa, aaaa, … ,b, bb, bbb, bbbb, … , c, cc, ccc, cccc, …
ab, bc, ac, … , abc, …}
Automata Formal Languages and Logic
Unit 1: -Non-deterministic Finite Automata (-NFA)
Solution: L={, a, aa, aaa, aaaa, … ,b, bb, bbb, bbbb, … , c, cc, ccc, cccc, …
ab, bc, ac, … , abc, …}
Automata Formal Languages and Logic
Unit 1 – DFAs & NFAs
➢ DFA may be cumbersome to specify for complex systems and may even be
unknown, but NFA provides a nice way of ‘abstraction of information’.
➢ Any language that can be accepted by a DFA can also be accepted by an NFA,
i.e., Every NFA has an equivalent DFA (accepting the same language).
➢ DFA’s, NFA’s, and ε–NFA’s all accept exactly the same set of languages: the
regular languages.
➢ NFA are often more convenient to design than DFA and may have fewer states
compared to DFA.
➢ In real-time, only Deterministic Finite Automata (DFAs) can be implemented.
Automata Formal Languages and Logic
Unit 1 - Non-Deterministic Finite Automata (NFA)
➢ Using subset construction method, every NFA can be translated to a DFA that
recognizes the same language. DFAs, and NFAs as well, recognize exactly the set
of regular languages.
Note:
➢ "Deterministic" means "if you put the system in the same situation twice, it is guaranteed to make the same choice both
times".
➢ "Non-deterministic" means "not deterministic", or in other words, "if you put the system in the same situation twice, it might
or might not make the same choice both times".
➢ A non-deterministic finite automaton (NFA) can have multiple transitions out of a state. This means there are multiple
options for what it could do in that situation. It is not forced to always choose the same one; on one input, it might choose the
first transition, and on another input it might choose the same transition.
➢ Here you can think of "situation" as "what state the NFA is in, together with what symbol is being read next from the input".
Even when both of those are the same, a NFA still might have multiple matching transitions that can be taken out of that
state, and it can choose arbitrarily which one to take. In contrast, a DFA only has one matching transition that can be taken in
that situation, so it has no choice -- it will always follow the same transition whenever it is in that.
Automata Formal Languages & Logic
Unit 1
Conversion of NFA to DFA
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 1 - Conversion of NFA to DFA
● The initial state is the start state, plus all states reachable from the start state
via 𝜆-transitions (Called 𝜆-closure).
● Accepting states are any set of states where some state in the set is an
accepting state.
Automata Formal Languages and Logic
Unit 1 - Conversion of NFA to DFA
● In converting an NFA to a DFA, the DFA's states correspond to set of NFA states.
● Minimization of a DFA ensures that the resulting DFA (after minimization) has
the least possible states. The advantages of having a minimal DFA are: Faster
Execution: The more the number of states the more time the DFA will take to
process a string, hence minimization ensures faster execution.
Automata Formal Languages and Logic
Unit 1 - Conversion of NFA to DFA
Given an NFA with states Q, inputs Σ, transition function δN, state 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.
• The DFA states have names that are sets of NFA states.
• But as a DFA state, an expression like {p,q} must be read as a single symbol,
not as a set.
Automata Formal Languages and Logic
Unit 1 - Conversion of NFA to DFA
Solution:
Solution:
States: [{q0},{q0q1q2},{q0q1q4},Φ}
Rename the states as q0=q0,q0q1q2=q1, q0q1q4=q2, Φ= q3
Automata Formal Languages and Logic
Unit 1 - Conversion of NFA to DFA
Solution:
Solution:
Transition Table DFA
Automata Formal Languages and Logic
Unit 1 - Conversion of NFA to DFA
Solution:
Transition Table DFA
Automata Formal Languages & Logic
Unit 1
Minimization of DFA
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 1 - Minimization of DFA
Step IV : Combine all the unmarked pairs and make them a single state in the
minimized DFA.
Automata Formal Languages and Logic
Unit 1 - Minimization of DFA
Solution:
States merged :
● {q1, q2}
● {q3, q4}
Automata Formal Languages and Logic
Unit 1 - Minimization of DFA
Solution:
States merged :
● {q0,q4}, {q0, q2} and {q2, q4}
● {q1,q5}, {q1,q3} and {q3,q5}
Automata Formal Languages and Logic
Unit 1 - Minimization of DFA
Solution:
Minimized DFA
Final Table
States merged :
● {q0, q2}
● {q3, q5}
Automata Formal Languages & Logic
Unit 1*
Regular Expression
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 2 - Regular Expression
● A
Character/symbol
Atoms ● 𝜙 (L = { })
Regular Expression
● 𝝀 (L = {𝝀})
● (R)
Operators
● R*
● R1.R2 or R1R2
● R1 + R2 or R1 | R2
Automata Formal Languages and Logic
Unit 2 - Example of Regular Expressions
Example
a b* c + d
Automata Formal Languages and Logic
Unit 2 - Example of Regular Expressions
Example
(a b* c)+ d
R1 R2
or
Automata Formal Languages and Logic
Unit 2 - Example of Regular Expressions
Example
(a b* c) + d
Starting with Ending with
an ‘a’ a ‘c’
Followed by 0 or
more no. of b’s
Automata Formal Languages and Logic
Unit 2 - Example of Regular Expressions
Example
Example
(a b* c)+ d
L = { ac,
abc,
abbb….c,
d}
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜙
Union
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜙
R+𝜙=𝜙+R=R
Union
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜙
R+𝜙=𝜙+R=R
Union Commutative
R1 + R 2 = R 2 + R 1
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜙
R+𝜙=𝜙+R=R
Union Commutative
R1 + R 2 = R 2 + R 1
Associative
(R1 + R2)+R3 =
R1 + (R2+R3)
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜖 or 𝝀
Concatenation
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜖 or 𝝀
R.𝜖=𝜖.R=R
Concatenation
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
R.𝜙=𝜙.R=𝜙
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜖 or 𝝀
R.𝜖=𝜖.R=R
Non-Commutative
Concatenation R1 . R 2 ≠ R 2 . R 1
Example :
R1 = a
R2 = b
then,
ab = ba
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
Identity = 𝜖 or 𝝀
R.𝜖=𝜖.R=R
Non-Commutative
Concatenation R1 . R 2 ≠ R 2 . R 1
Associative
(R1 . R2) . R3 =
R1 . (R2. R3)
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
𝜖* = 𝜖
𝜙* = 𝜖
(R*)* = R*
Closure (R + 𝜖)* = R*
+
R = RR* = R*R
+
(R + 𝜖) = R*
𝜖 + RR* = 𝜖 + R* = R*
Automata Formal Languages and Logic
Unit 2 - Algebraic Laws of Regular Expressions
(a + b)*
= (a* + b*)*
= (a* b*)*
Closure = (a + b*)*
= (a* + b)*
= a*(ba*)*
= b*(ab*)*
Automata Formal Languages and Logic
Unit 2 - Construction of Regular Expressions
Unit 1*
Regular Expression in Practice
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
(dot)
matches any single character except newline
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
(Star)
0 or more repetitions of preceding regex
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
Example :
a*
Strings matched :
0 or more no. of a’s
Example : 𝝺,a,aa,aaa,aaaa,aaaaa….
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
Example :
a+
Strings matched :
1 or more no. of a’s
Example : a,aa,aaa,aaaa,aaaaa….
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
4. ?
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
4. ?
Example:
ab?c
matches abc or ac
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
4. ?
5. [ ]
Character Class
Matches any single character
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
4. ?
5. [ ]
Example
[cat]
String matched :
c
or a
or t
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
4. ?
5. [ ]
6. ^
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
^ (caret) :
Example:
Special characters
1. .
2. *
3. +
4. ?
5. [ ]
6. ^
7. $
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
$ (dollar) :
Example :
-> abc$" matches "c" at the end of a line.
-> ^$ matches the empty string.
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Special characters
1. .
2. *
3. +
4. ?
5. [ ]
6. ^
7. $
8. { } (Syntax - R{m,n})
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Example of { }
a{0, } - same as a*
a{1, } - same as a+
Special characters
1. .
2. *
3. +
4. ?
5. [ ]
6. ^
7. $
8. { } (Syntax - R{m,n})
9. \d - matches any digit between [0-9]
a. \d{9} matches any 9 digits
b. \d{2,3} matches 2 or 3 digits
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
● PAN CARD:
The valid PAN Card number must satisfy the following conditions:
1. It should be 10 characters long.
2. The first five characters should be any upper case alphabets.
3. The next four-characters should be any number from 0 to 9.
4. The last(tenth) character should be any upper case alphabet.
5. It should not contain any white spaces.
https://www.geeksforgeeks.org/how-to-validate-pan-card-number-using-regular-expression/
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
https://www.geeksforgeeks.org/how-to-validate-pan-card-number-using-regular-expression/
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
● AADHAR NUMBER:
https://www.geeksforgeeks.org/how-to-check-aadhar-number-is-valid-or-not-using-regular-expression/#:~:text=Create%20a%20regular%20expression%20to,%2D9%5D%7B4%7
D%24%E2%80%9D%3B&text=%5B0%2D9%5D%7B4%7D,be%20any%20from%200%2D9.
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
https://www.geeksforgeeks.org/how-to-check-aadhar-number-is-valid-or-not-using-regular-expression/#:~:text=Create%20a%20regular%20expression%20to,%2D9%5D%7B4%7
D%24%E2%80%9D%3B&text=%5B0%2D9%5D%7B4%7D,be%20any%20from%200%2D9.
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
https://www.geeksforgeeks.org/how-to-check-aadhar-number-is-valid-or-not-using-regular-expression/#:~:text=Create%20a%20regular%20expression%20to,%2D9%5D%7B4%7
D%24%E2%80%9D%3B&text=%5B0%2D9%5D%7B4%7D,be%20any%20from%200%2D9.
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
https://www.geeksforgeeks.org/how-to-check-aadhar-number-is-valid-or-not-using-regular-expression/#:~:text=Create%20a%20regular%20expression%20to,%2D9%5D%7B4%7
D%24%E2%80%9D%3B&text=%5B0%2D9%5D%7B4%7D,be%20any%20from%200%2D9.
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
● It is a leap year
Months with 31 days are : Jan, Mar, May, July, Aug, Oct, Dec
: [1, 3, 5, 7, 8, 10, 12]
Months with 30 days are : Apr, June, Sep, Nov
: [4, 6, 9, 11]
Month with 29 days : Feb
: [2]
● Year : 2020
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Regex:
(
(0[0-9])|[10-31]”-”(0[13578]|1[0|2])
|
(0[0-9])|[10-30]”-”(0[469]|11)
|
(0[0-9])|[10-29]”-””02”
)”-””2020”
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
Email Address:
An email is a string (a subset of ASCII characters) separated into two parts by @ symbol.
a "personal_info" and a domain, that is personal_info@domain.
The length of the personal_info part may be up to 64 characters long and domain name
may be up to 253 characters.
Email Address:
^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.
(([0-9]{1,3})|([a-zA-Z]{2,3})|(com|edu|info|museum|name))$
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
^((ht|f)tp(s?))\://([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(/\S*)?$
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.
(([0-9]{1,3})|([a-zA-Z]{2,3})|(com|edu|info|museum|name))$
Automata Formal Languages and Logic
Unit 2 - Regular Expression in Practice
^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-
5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2
[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4]
[0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$
Automata Formal Languages & Logic
Unit 1*
Regular Expression to Finite
Automata
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
Regular Finite
Expression Kleene’s Automata
R Theorem M
Regular Finite
Expression Automata
R M
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
https://en.wikipedia.org/wiki/Thompson%27s_construction#:~:text=In%20computer%20science%2C%20Thompson's%20co
nstruction,strings%20against%20the%20regular%20expression.
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
Union : s|t
https://en.wikipedia.org/wiki/Thompson%27s_construction#:~:text=In%20computer%20science%2C%20Thompson's%20co
nstruction,strings%20against%20the%20regular%20expression.
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
Concatenation : s.t
https://en.wikipedia.org/wiki/Thompson%27s_construction#:~:text=In%20computer%20science%2C%20Thompson's%20co
nstruction,strings%20against%20the%20regular%20expression.
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
Kleene Star : s*
https://en.wikipedia.org/wiki/Thompson%27s_construction#:~:text=In%20computer%20science%2C%20Thompson's%20co
nstruction,strings%20against%20the%20regular%20expression.
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
a
q0 q1
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
a
q0 q1
b
q2 q3
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
a b
q0 q2 q3
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
a b
q0 q2 q3
c
q4 q5
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
𝜖 a b
q0 q2 q3
qs
c
q4 q5
𝜖
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
𝜖 a b
𝜖
q0 q2 q3
qs
qf
c
q4 q5
𝜖 𝜖
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
𝜖 a b 𝜖
q q
𝜖 q3
0 2
q
S
s qf
c
q q5
𝜖 4 𝜖
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
𝜖 a b 𝜖
q q
𝜖 q3
0 2
q 𝜖
S
s qf F
c
q q5
𝜖 4 𝜖
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)*
𝜖 a b 𝜖
q q
𝜖 q3
0 2
q 𝜖
S
s qf F
c
q q5
𝜖 4 𝜖
𝜖
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages and Logic
Unit 2 - Regular Expression to Finite Automata
(ab+c)* 𝜖
𝜖 a b 𝜖
q q
𝜖 q3
0 2
q 𝜖
S
s qf F
c
q q5
𝜖 4 𝜖
𝜖
https://www.cs.york.ac.uk/fp/lsa/lectures/REToC.pdf
Automata Formal Languages & Logic
Unit 1*
Finite Automata to Regular
Expression
Preet Kanwal
Department of Mechanical Engineering
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Regular Finite
Expression Automata
R M
Example 1 :
b
A B
c
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 1 : a
b
A B a+b
A B
c
c
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 1 :
b a+b+c
A B A B
c
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 2 :
b
a c
A B C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 2 :
b
A
a
xB
c
C
Eliminate B a b* c
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 2 :
b
a c
A B C
A
a b* c C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 3 :
b c
A d
B C
a
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 3 : b
x
ab b
𝜖 d
S A B C
1. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 3 :
b
(c + ab )
S
x B
d
C
b (c + ab)* d
1. Eliminate A
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 3 :
b c
A d
B C
S C
b (c + ab)* d
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c d
a
A B
b
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c d
a
𝜖
S A B
b
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c d
a
𝜖 𝜖
S A C
B F
Example 4 :
c d
x
a
𝜖 𝜖
S A C
B F
1. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 : c*a
c d
x
a
𝜖
S A C
B F
1. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 : c*a
d + bc*a
𝜖
S C
B F
1. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 : c*a
d + bc*a
S x B
𝜖
F
1. Eliminate A
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c*a (d + b c* a)*
S F
1. Eliminate A
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c d
a
A B
c*a (d + b c* a)*
S F
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c d
a
𝜖 𝜖
S A C
B F
b
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
c d
x
a
𝜖 𝜖
S A C
B F
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
ad*
Example 4 :
c d
x
a
𝜖
S A C
B F
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
ad*
Example 4 :
c + ad*b
𝜖
S A F
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
ad*
Example 4 :
c + ad*b
S
𝜖
x A F
1. Eliminate B
2. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 :
(c+ad*b)* ad*
S F
1. Eliminate B
2. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 4 : c d
a
A B
1. Eliminate A 1. Eliminate B
2. Eliminate B 2. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0 1 0,1
1 0
A B C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0 1 0,1
λ 1 0
S A B C
A new start state (S) is introduced as there is an incoming edge to the existing
start state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0 1 0,1
λ 1 0
S A B C
λ λ
F
A new final state (F) is introduced as there is an outgoing edge from the existing
final state and we must have a single accepting state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0 1 0,1
λ 1 0
S A B C
λ λ
F
Example 5 :
0 1 0,1
X
λ 1 0
S A B C
λ λ
F
1. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0 1
λ 1
S A B
λ λ
F
1. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0 1
X
λ 1
S A
B
λ λ
F
1. Eliminate C
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0
λ
S A
11*
λ
F
1. Eliminate C
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0
λ 11*+λ
S A F
1. Eliminate C
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
S
λ
X A
11*+λ
F
1. Eliminate C
2. Eliminate B
3. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 5 :
0*(11*+λ)
S F
= 0(11*+λ)
+
=0*(1 +λ)
RE =0*1*
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
0
A B
1
1 0 0
0,1
C D
1
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
0
A B
1
1 0 0
C X D
0,1
1
1. Eliminate D
(Dead state)
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
0
A B
1
1 0
C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
0
λ
S A B
1
1 0
A new start state (S) is introduced as there is an incoming edge to the existing
start state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
F
λ 0
λ
S A B
1
1 0
A new final state (F) is introduced as there is an outgoing edge from the existing
final state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
F
λ 0
S
λ
A X B
1
1 0
1. Eliminate D
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
01 λ
λ
S A F
1 0
1. Eliminate D
2. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
01
λ λ
S A F
1 0
X
C
1. Eliminate D
2. Eliminate B
3. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
01+10
λ λ
S A F
1. Eliminate D
2. Eliminate B
3. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
01+10
S
λ
XA
λ
F
1. Eliminate D
2. Eliminate B
3. Eliminate C
4. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 6 :
(01+10)*
S F
RE=(01+10)*
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1 1 1,0
0
1
A B C
0
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1 1 1,0
0
1
S A B C
A new start state (S) is introduced as there is an incoming edge to the existing
start state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1 1 1,0
0
λ 1 λ
S A B C F
A new final state (F) is introduced as there is an outgoing edge from the
existing
final state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1 1 1,0
0
X
λ 1 λ
S A B C F
1. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1 1
0
λ 1(0+1)*
S A B F
1. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1 1
0
X
λ 1(0+1)*
S A B F
1. Eliminate C
2. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
(1+01*0)
1*0 1(0+1)*
S B F
1. Eliminate C
2. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
(1+01*0)
X
1*0 1(0+1)*
S B F
1. Eliminate C
2. Eliminate A
3. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 7 :
1*0(1+01*0)*1(0+1)*
S F
RE=1*0(1+01*0)*1(0+1)*
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
0
1
A B
0
1 1
0
C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
0
1
λ
S A B
0
1 1
0
C
A new start state (S) is introduced as there is an incoming edge to the existing
start state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
0 1
λ
S A B
0
1 λ
1
0
C F
λ
A new final state (F) is introduced as there is an outgoing edge from the existing
final state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
0 1
S
λ
A X
B
0
1 λ
1
0
C F
λ
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
01*0
λ
S A 01*
01*0+1 1
C F
01*+λ
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
01*0
λ
S A
01*
01*0+1 1
X C F
01*+λ
1. Eliminate B
2. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
01*0+1(1+01*0)
λ 01*
S A F
1(01*+λ)
1. Eliminate B
2. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
01*0+1(1+01*0)
S
λ
X A
01*
F
1(01*+λ)
1. Eliminate B
2. Eliminate C
3. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
(01*0+1(1+01*0))*(01*+1(01*+λ))
S F
RE=(01*0+1(1+01*0))*(01*+1(01*+λ))
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
RE=(01*0+1(1+01*0))*(01*+1(01*+λ))
=(01*0+11+101*0)*(01*+(101*+1))
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 8 :
RE=(01*0+1(1+01*0))*(01*+1(01*+λ))
=(01*0+11+101*0)* (01*+(101*+1))
Example 8 :
RE=(01*0+1(1+01*0))*(01*+1(01*+λ))
=(01*0+11+101*0)* (01*+(101*+1))
Example 8 :
RE=(01*0+1(1+01*0))*(01*+1(01*+λ))
=(01*0+11+101*0)* (01*+(101*+1))
Example 8 :
RE=(01*0+1(1+01*0))*(01*+1(01*+λ))
=(01*0+11+101*0)* (01*+(101*+1))
a
A B
b b b b
a
D C
a
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
a
λ
S A B
b b b b
a
D C
a
A new start state (S) is introduced as there is an incoming edge to the existing
start state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 : F
λ a
λ
S A B
b b b b
a
D C
A new final state (F) is introduced as there is an outgoing edge from the existing
final state
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
F
X
λ a
λ
S A B
b b b b
a
D C
a
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
F
λ aa
λ
S A ab
ba
b b
a bb
D C
a
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
F
aa
λ λ
S A ab
ba
b b
X
a bb
D C
a
1. Eliminate B
2. Eliminate D
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
aa+bb
λ λ
S A F
ab+ba ab+ba
bb+aa
1. Eliminate B
2. Eliminate D
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
aa+bb
λ λ
S A F
ab+ba ab+ba
X C
bb+aa
1. Eliminate B
2. Eliminate D
3. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
(aa+bb )+
(ab+ba)(aa+bb)*(ab+ba)
λ λ
S A F
1. Eliminate B
2. Eliminate D
3. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
(aa+bb) +
(ab+ba)(aa+bb)*(ab+ba)
X
λ λ
S A F
1. Eliminate B
2. Eliminate D
3. Eliminate C
4. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
(aa+bb) + (ab+ba)(aa+bb)*(ab+ba))*
S F
Example 9 :
Consider the same example: Order of elimination: B,C, D ,A (Adding new start state and
b b b b
a
D C
a
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
F
X
λ a
λ
S A B
b b b b
a
D C
a
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
F
λ λ aa
S A ab
ba
b b
a bb
D C
a
1. Eliminate B
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
F
λ aa
λ
S A ab
ba
b b
a
X
bb
D C
a
1. Eliminate B
2. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
aa+ab(bb)*ba
λ λ
S A F
b+ab(bb)*a a(bb)*ba+b
1. Eliminate B
a(bb)*a
2. Eliminate C
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
aa+ab(bb)*ba
λ λ
S A F
b+ab(bb)*a a(bb)*ba+b
1. Eliminate B
X D
a(bb)*a
2. Eliminate C
3. Eliminate D
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
aa+ab(bb)*ba + (b+ab(bb)*a)(a(bb)*a)*(a(bb)*ba+b
λ λ
S A F
1. Eliminate B
2. Eliminate C
3. Eliminate D
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
(aa+ab(bb)*ba + (b+ab(bb)*a)(a(bb)*a)*(a(bb)*ba+b)
S
λ
X A
λ
F
1. Eliminate B
2. Eliminate C
3. Eliminate D
4. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
(aa+ab(bb)*ba + (b+ab(bb)*a)(a(bb)*a)*(a(bb)*ba+b)*
S F
1. Eliminate B
2. Eliminate C
3. Eliminate D
4. Eliminate A
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
((aa+ab(bb)*ba)* + (b+ab(bb)*a)(a(bb)*a)*(a(bb)*ba+b)*
S F
RE = ((aa+ab(bb)*ba) + (b+ab(bb)*a)(a(bb)*a)*(a(bb)*ba+b))*
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Expression
Example 9 :
a
A B
a
b b b b
a
D C
Unit 1*
Equivalence of two regular
expression
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
L(R1) = L(R2)
1) A Formal method
2) An Informal method:
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
NFA1 NFA2
DFA1 DFA2
Equal
Minimal DFA1 Minimal DFA2
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Informal Method -
We try proving R1 ≠ R2
● Find a string that can be matched with only one of the regex
hence proving that the two regex are not equivalent.
● Faster
Let us look at examples and find out whether two regex are
equivalent or not??
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 1:
(0+1)*(0+λ) (1+λ)(1+0)*
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 1: Formal
Method
(0+1)*(0+λ) (1+λ)(1+0)*
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 1: Formal
Method
(0+1)*(0+λ) (1+λ)(1+0)*
0,1 0,1
0,λ 1,λ
NFA A B A B
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 1: Formal
Method
(0+1)*(0+λ) (1+λ)(1+0)*
0,1 0,1
0,λ 1,λ
NFA A B A B
0,1
0,1 0,1
DFA A B
A
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 1: Formal
Method
(0+1)*(0+λ) (1+λ)(1+0)*
0,1 0,1
0,λ 1,λ
NFA A B A B
0,1
0,1 0,1
DFA A B
A
0,1 0,1
Minimal
A A
DFA
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 1: Formal
Method
(0+1)*(0+λ) (1+λ)(1+0)*
0,1 0,1
0,λ 1,λ
NFA A B A B
0,1
0,1 0,1
DFA A B
A
0,1 0,1
Minimal Equal
A A
DFA
Automata Formal Languages and Logic
Unit 2 - Equivalence
Example 1: of two regular expression Formal
Method
Equivalent
(0+1)*(0+λ) (1+λ)(1+0)*
0,1 0,1
0,λ 1,λ
NFA A B A B
0,1
0,1 0,1
DFA A B
A
0,1 0,1
Minimal Equal
A A
DFA
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 2:
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 2: Informal
Method
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 2: Informal
Method
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
Example 2: Informal
Method
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
(1+λ)(011*)(0+λ)
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 2: Informal
Method
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
(1+λ)(011*)(0+λ)
011
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 2: Informal
Method
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
011
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Example 2: Informal
Method
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
011 cannot be
011
generated
Automata Formal Languages and Logic
Example 2:
Unit 2 - Equivalence Informal
of two regular expression
Method
(0+λ)(11*0)*(1+λ)
≠ (1+λ)(011*)(0+λ)
(0+λ)(11*0)*(1+λ) (1+λ)(011*)(0+λ)
011 cannot be
011
generated
Automata Formal Languages and Logic
Unit 2 - Equivalence of two regular expression
Unit 1*
Regular Grammar
Preet Kanwal
Department of Computer Science & Engineering
Automata Formal Languages and Logic
Unit 2 - Regular Grammar (outline)
𝜶 or 𝞫 = (V U T)*
P - Production Rules 𝜶→𝞫
L(G) =
S - Start Symbol
{w | S ⇒ w, where w ∈ Σ*}
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Example:
For the Grammar S->aS | a |𝜆
Sentence (or string) is { a or 𝜆 or aa or aaaa)
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Sentential Form
Example:
For the Grammar S->aS | a |𝜆
Sentential form is { a or 𝜆 or aS or aa or or aaS aaaa)
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Noam Chomsky
Chomsky Hierarchy
https://www.javatpoint.com/automata-chomsky-hierarchy
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Linear Non
Grammar linear
s grammar
S -> aSa | aS | Sa | 𝜖
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Linear
Grammar
Linear Non
Grammar linear
s
Regular grammar
Grammar
S -> aSa | aS | Sa | 𝜖 S -> SS | aSS | a | 𝜖
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Regular
Grammar
S -> Sa | 𝜖 S -> aS | 𝜖
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
Language RE RG
L = {a} a S -> a
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
Language RE RG
L = {ab} ab S -> ab
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L = {𝛌,a,aa,aaa,...} a* S -> aS|𝛌
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L = {a,aa,aaa,...} a+ S -> aS | a
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L= (a+b)*
S -> aS | bS | 𝛌
{𝛌,a,b,abb,baaaab,.
.....}
L={any number of
‘as and b’s}
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L= (a+b)+
S -> aS | bS | a | b
{𝛌,a,b,abb,baaaab,.
.....}
L={any number of
‘as and b’s}
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L= (ab)*
S -> abS | 𝛌
{𝛌,a,b,ab,ababab,...
...}
L={any number of
ab’s}
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L={𝛌,a,b,bb,abb,..... a*b* S -> A|B
.} A:any number of a’s
L={any number of B:any number of b’s
A->aA|𝛌
a’s followed by any
B->bB|𝛌
number of b’s}
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L={𝛌, (aa)* S -> aaS | 𝛌
aa,
aaaa,
aaaaaa ….
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L={a, (aa)*a S -> aaS | a
aaa,
aaaaa,
aaaaaaa ….
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L={𝛌, (aaaa)* S -> aaaaS | 𝛌
aaaa,
aaaaaaaa,
aaaaaaaaaaaa, ….
Automata Formal Languages and Logic
Unit 2 - Construct a regular grammar for the given language
Language RE RG
L={a, b* a (a+b)* S -> bS | aA
bb... a, A -> aA | bA | 𝛌
ba any # of a’s &
b’s
Automata Formal Languages and Logic
Unit 2 - Equivalence of regular grammar and Finite automata
Regular Finite
Grammar Automata
Automata Formal Languages and Logic
Unit 2 - Equivalence of regular grammar and Finite automata
b b
a
S A
S → bS |aA|𝛌
𝛌 on RHS indicates S
A → bA|𝛌 and A are final states
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Grammar
b b b
a a
S A B
S → bS |aA|𝛌
𝛌 on RHS indicates S,A
A → bA|aB |𝛌 and B are final states
B →bB |aC|𝛌
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Grammar
b b b b
a a a
S A B C
S → bS |aA|𝛌
C →bC|aD|𝛌
A → bA|aB |𝛌
B →bB |aC|𝛌
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Grammar
S → bS |aA|𝛌
C →bC |𝛌
A → bA|aB |𝛌
B →bB |aC|𝛌
Automata Formal Languages and Logic
Unit 2 - Finite Automata to Regular Grammar
Grammar is,
S→ aA
A→ bB
B→ aB|bB|𝜆
Automata Formal Languages and Logic
Unit 2 - Equivalence of regular grammar and Finite automata
S→ aA
A→ aA|bA|aB
B→ 𝜆
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 1 :
A→aB|bA|b
B→aC|bB
C→aA|bC|a
Variables->state
terminal symbols ->symbols of finite
automata
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 1 :
A→aB|bA|b
B→aC|bB
C→aA|bC|a
b
a
A B
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 1 :
A→aB|bA|b
B→aC|bB
C→aA|bC|a
Example 1 :
A→aB|bA|b
B→aC|bB
C→aA|bC|a
b b
a a
A B C
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 1 :
A→aB|bA|b
B→aC|bB
C→aA|bC|a
● Transition C→aA to C→a when when A→𝜆
indicates A is a final state.
b b b
a a
A B C
a
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 2 :
S→01A
A→10B
B→0A|11
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 2 :
S→01A
A→10B
B→0A|11
0 1
S A
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 2 :
S→01A
A→10B
B→0A|11
0 1 1 0
S A B
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 2 :
S→01A
A→10B B→11 indicates on state B on
B→0A|11 consuming the input 11 we reach final
state
0 1 1 0 1 1
S A B
0
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 3 :
S→bS|aA
A→aA|bA
A→aB
B→bbB
B→𝜆
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Example 3 :
S→bS|aA
A→aA|bA
A→aB
B→bbB
B→𝜆
b
a
S A
Automata Formal Languages and Logic
Unit 2 - Regular Grammar to Finite Automata
Grammar Automata
S→bS|aA
A→aA|bA|aB
B→bbB|𝜆
Automata Formal Languages and Logic
Unit 2 - Aspects of Grammar
Aspects of grammar
Generative Analytical
(Derivative) Aspect
Parse Tree
Automata Formal Languages and Logic
Unit 2 - Parse Tree
What is a Tree?
Leaves
Branches
Root
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Root-
Branches
Leaves
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Root
Branches
Leaves
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Trees
Edge Node
S Root Node
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Parsing
Top-Down Bottom-up
Parsing Parsing
Automata Formal Languages and Logic
Unit 2 - Parser
Parse Tree
S Root node
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Parse Tree
S Root node
S→aS
a S
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Parse Tree
S Root node
S→aS
a S
b A S→bA
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Parse Tree
S Root node
S→aS
a S
b A S→bA
b A A→bA
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Parse Tree
S Root node
S→aS
a S
b A S→bA
b A A→bA
𝜆 A→𝜆
Automata Formal Languages and Logic
Unit 2 - Parse Tree
Parse Tree
Root node
S
S→aS
* a S
A S→bA
*b
A A→bA
*b
* 𝜆 A→𝜆
2. Analytical aspect
Parsing
2. Analytical aspect
S→aS
Parsing S→bA
A→bA
A→𝝺
��
Automata Formal Languages and Logic
Unit 2 - Regular Grammar
2. Analytical aspect
S→aS
Parsing S→bA
A→bA
A→𝝺
�� ab ��
Automata Formal Languages and Logic
Unit 2 - Converting Right Linear Grammar to Left Linear Grammar
Right Linear
Left Linear
A→aB
B→aB|bB|𝜆 ??
L={starting with ‘a’}
https://www.youtube.com/watch?v=8a2jBm5Syjs
Automata Formal Languages and Logic
Unit 2 - Constructing a Left Linear Grammar
https://www.youtube.com/watch?v=8a2jBm5Syjs
Automata Formal Languages and Logic
Unit 2 - Constructing a Left Linear Grammar
https://www.youtube.com/watch?v=8a2jBm5Syjs
Automata Formal Languages and Logic
Unit 2 - Converting Finite automata to Left Linear Grammar
https://www.youtube.com/watch?v=8a2jBm5Syjs
Automata Formal Languages and Logic
Unit 2 - Constructing a Left Linear Grammar
a,b
a,b
R a
FA for L = {wa, w 𝛜 {a,b}*} A B
a,b
R a
FA for L = {wa, w 𝛜 {a,b}*} A B
a,b
FA for ( LR )R =L = {aw, w 𝛜 a
A B
{a,b}*}
Automata Formal Languages and Logic
Unit 2 - LLG or RLG?
S
Right Linear
S→abA
A→cB|aC a b A
B→ab
C→b c B
a b
Construct Parse tree for the
String “abcab”
https://www.slideserve.com/kaloni/how-to-convert-a-left-linear-grammar-to-a-right-linear-grammar
Automata Formal Languages and Logic
Unit 2 - Which one is easier,Left or Right Linear Grammar?
S
Left Linear
S→Aabc
A a b c
A→Bb|C
B→a
B b
C→b
a
Construct Parse tree for the
String “ababc”
https://www.slideserve.com/kaloni/how-to-convert-a-left-linear-grammar-to-a-right-linear-grammar
THANK YOU
Preet Kanwal
Department of Computer Science & Engineering
[email protected]
+91 80 6666 3333 Extn 724