0% found this document useful (0 votes)
9 views

Unit 1 4

Uploaded by

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

Unit 1 4

Uploaded by

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

Course – Theoretical

Foundations of Computations

Course Instructor
Dr. Umadevi V
Department of CSE, BMSCE
Webpage:https://sites.google.com/site/drvumadevi/

February 20, 2025 CSE, BMSCE 1


Unit-1

Introduction to Finite Automata


Introduction to Finite Automata, Central Concepts of
Automata Theory, Deterministic Finite Automata (DFA),
Nondeterministic Finite Automata (NFA), Finite Automata
with Epsilon Transition, An Application Text Search.

February 20, 2025 CSE, BMSCE 2


Theory of Computation
The field is divided into Three major Branches

February 20, 2025 CSE, BMSCE 3


What is automata theory ?
 Automata theory is the study of
abstract computational devices
 Abstract devices are (simplified)
models of real computations
 Computations happen everywhere:
On your laptop, on your cell phone, in
nature, …
 Why do we need abstract models?
Finite State machine
Abstract machine or Automata or Finite State machine

Example:
Event1/ Notations
Action1
State1 State3
Start State

Event3/
Event2/ Action3
Action2 State
State2

Final State
Nodes: State
Edges: Transition
Edge Label: Events / Actions

February 20, 2025 CSE, BMSCE 5


A simple computer

H
I TC
SW

BATTERY

input: switch
output: light bulb
actions: flip
switch
states: on, off
A simple “computer”

I TC
H Abstract machine or
SW
Automaton
f

BATTERY start off on

input: switch
output: light bulb bulb is on if and only
if there was an odd
actions: f for “flip number of flips
switch”
states: on, off
Another “computer”

BATTERY

2
Another “computer”
1
1 start off off

2
BATTERY

2
off on

inputs: switches 1 and


2 bulb is on if and only
actions: 1 for “flip if both switches were
switch 1” flipped an odd
actions: 2 for “flip number of times
switch 2”
states: on, off
Another “computer”
1
1 start off off
1

2 2 2 2
BATTERY
1
2
off on
1

inputs: switches 1 and


2 bulb is on if and only
actions: 1 for “flip if both switches were
switch 1” flipped an odd
actions: 2 for “flip number of times
switch 2”
states: on, off
A design problem

1 4

?
5
BATTERY

Can you design a circuit where the light is on


if and only if all the switches were flipped
exactly the same number of times?
A design problem
 Such devices are difficult to reason
about, because they can be designed
in an infinite number of ways
 By representing them as abstract
computational devices, or automata,
we will learn how to answer such
questions
Applications of Automata Theory

 In Compiler: Lexical analyzers and


Parser generator
 Word search and Translation of
Natural Languages
 Parity checkers, Vending machines,
Communication protocols, Video
games, Artificial Intelligence etc.
Different kinds of automata we will work on in this course

Finite Devices with a finite amount of


Automata memory.
Used to model “small” computers.
Push-down Devices with infinite memory that
Automata can be accessed in a restricted way.
Used to model Parsers, etc.

Turing Devices with infinite memory.


Machines Used to model any computer.
The Applications of these Automata are given as follows:

1. Finite Automata (FA) –


For the designing of lexical analysis of a compiler.
For recognizing the pattern using regular expressions.
For the designing of the combination and sequential circuits using Mealy and Moore
Machines.
Used in text editors.
For the implementation of spell checkers.
2. Push Down Automata (PDA) –
For designing the parsing phase of a compiler (Syntax Analysis).
For implementation of stack applications.
For evaluating the arithmetic expressions.
For solving the Tower of Hanoi Problem.
3. Turing Machine (TM) –
For solving any recursively enumerable problem.
For understanding complexity theory.
For implementation of neural networks.
For implementation of Robotics Applications.
For implementation of artificial intelligence.
Unit-1

Central Concepts of Automata Theory


- Alphabets
- Strings
- Languages

February 20, 2025 CSE, BMSCE 16


Central Concepts
 Symbol
 A symbol is a single object and
is an abstract entity that has no
meaning by itself.
 It can be alphabet, character or
special character

Dr. Abdus Salam Theory of Automata by 1.17


Central Concepts
Alphabet
 An alphabet is a finite, nonempty set
of symbols, Σ (sigma) is used for an
alphabet.
 For example
{0, 1} is an alphabet with two symbols
{a, b} is another alphabet with two
symbols, and
English alphabet is also an alphabet
 Σ = {0,1}, or Σ = the binary alphabet
 Σ = {a,b,…..z}, or Σ=the set of all lower-case
letters

Dr. Abdus Salam Theory of Automata by 1.18


Central Concepts: String
 A string is a finite sequence of symbols
chosen from some alphabet. e.g. 01101
is a string from the binary alphabet Σ =
{0,1}.
 The number of symbols in a string is
called the length of a string. e.g.
011101 has length 5 and the number of
symbols are 2. The standard notation
for the length of a string w is |w|. e.g. |
011| = 3

Dr. Abdus Salam Theory of Automata by 1.19


Central Concepts: String
 The empty string (also called null string) is
the string with length zero. That is, it has no
symbols. It is denoted with ε (epsilon), that
may be chosen from any alphabet
whatsoever. Thus | ε | = 0.

Dr. Abdus Salam Theory of Automata by 1.20


Central Concepts: String
Powers of an Alphabet: If Σ is an alphabet,
we define Σk to be the set of strings of length k,
each of whose symbols is in Σ. e.g. Σ0 = {ε}.
If Σ = {0,1}, then
Σ1 = {0,1}
Σ2 = {00,01,10,11}
Σ3 =
{000,001,010,011,100,101,110,111}

The set of all strings over an alphabet is


denoted as Σ*. For instance, {0,1}* =
{ε,0,1,00,01,10,11,000,….}. Put another
way,
Σ* = Σ0 U Σ1 U Σ2 U Σ3 ….
Σ+ = Σ1 U Σ2 U Σ3 ….
Dr. Abdus Salam Theory of Automata by 1.21
Central Concepts

Strings
 Concatenation of Strings: Let x and
y be strings. Then xy denotes the
string obtained by concatenating x
with y, that is, xy is the string obtained
by appending the sequence os symbols
of y to that of x. e.g. if x = aab and y =
bbab, then xy = aabbbab. Note that xy
≠ yx.
1.22

Dr. Abdus Salam Theory of Automata by


Central Concepts

Languages

Dr. Abdus Salam


 A language is a set of strings over an
alphabet. Thus {a, ab, baa} is a language
(over alphabet {a, b}).
 A set of strings all of which are
 chosen from

Theory of Automata by
some Σ*, where Σ is a particular alphabet, is
called a language. If Σ is an alphabet, and L
Σ* , then L is a language over Σ.
 An example is English, where the collection of
legal English words is a set of strings over the
alphabet that consists of all the letters.

1.23
Question
Consider the alphabet set as Σ ={0,1}. Write
down possible strings of the Language, L, which is
defined as follows:
L={w | w consists of equal number of 0’s and 1’s}

February 20, 2025 CSE, BMSCE 24


Question
Consider the alphabet set as Σ ={0,1}. Write
down possible strings of the Language, L, which is
defined as follows:
L={w | w consists of equal number of 0’s and 1’s}

Answer:
L={ε, 01, 10, 1100, 0011, 0101, 1010, 0011010,
……..}

February 20, 2025 CSE, BMSCE 25


Examples of Languages
 The language of all strings consisting of
n 0’s followed by n 1’s, for some n ≥ 0:
 {ε, 01, 0011, 000111,…..}
 The set of strings of 0’s and 1’s with an
equal number of each:
 {ε, 01,10,0011,0101,1001,…..}
 The set of binary numbers whose value is
a prime:
 {10, 11, 101,111,1011…..}

Note: The only important constraint on what can


be a language is that all alphabets are finite,
although they can have an infinite number of
strings.
Dr. Abdus Salam Theory of Automata by 1.26
Summarizing
Central Concepts
1. Alphabet: A set of Symbols
2. Strings: A list of symbols from an alphabet
3. Language: A set of strings from the same
alphabet.

February 20, 2025 CSE, BMSCE 27


Types of Finite Automata
Formal Definition of Deterministic Finite Automata

A Deterministic Finite Automaton


(DFA) is a 5-tuple system
M= (Q, S, d, q0, F) where
 Q is a finite set of states
 S is an alphabet set or input symbols
 d: Q × S → Q is a transition function
 q0 Î Q is the initial (or start)state q 0

 F Í Q is a set of accepting states (or


final states). q
Question

Construct a Deterministic Finite Automata


(DFA) to recognize all odd number a’s given
the alphabet set as Σ ={a}

Note: For DFA construction specific steps to be followed cannot be


generalized for all computational problems.
But to get started, we will follow some steps. This steps may not be
applicable to all DFA’. But, it helps to get started.

February 20, 2025 CSE, BMSCE 30


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step1: Write possible strings of the Language that will be


accepted for the given DFA
L={a, aaa, aaaaa,……}

February 20, 2025 CSE, BMSCE 31


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step1: Write possible strings of the Language that will be


accepted for the given DFA
L={a, aaa, aaaaa,……}
Step2: Write possible strings of the Language that should
not be accepted for the given DFA
={ε, aa, aaaa,……….}

February 20, 2025 CSE, BMSCE 32


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step1: Write possible strings of the Language that will be


accepted for the given DFA
L={a, aaa, aaaaa,……}
Step2: Write possible strings of the Language that should
not be accepted for the given DFA
={ε, aa, aaaa,……….}
Step3: Write down the minimum string that will be accepted
for the given DFA
‘a’

February 20, 2025 CSE, BMSCE 33


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step1: Write possible strings of the Language that will be


accepted for the given DFA
L={a, aaa, aaaaa,……}
Step2: Write possible strings of the Language that should
not be accepted for the given DFA
={ε, aa, aaaa,……….}
Step3: Write down the minimum string that will be accepted
for the given DFA
‘a’
Step4: Find the length of the minimum string, n=|a|=1
Step5: Find number of States required to construct this DFA
Number of States=n+1=1+1=2

February 20, 2025 CSE, BMSCE 34


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step6: Draw the transition diagram of the DFA that accepts


minimum string. Note: Make sure that there in one Start State
and atleast one final state

q0 a q1

February 20, 2025 CSE, BMSCE 35


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step6: Draw the transition diagram of the DFA that accepts


minimum string. Note: Make sure that there in one Start State
and atleast one final state

q0 a q1

Step7: For the basic DFA, defined in Step6, consider one


state at a time and obtain the various missing transitions on
each input symbol
q0 a q1

February 20, 2025 CSE, BMSCE 36


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step8: For the missing transitions identified in step7,


connect this transitions to appropriate state so that the
string stated in the problem is accepted.
a
q0 q1 Transition Diagram
a

February 20, 2025 CSE, BMSCE 37


Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step8: For the missing transitions identified in step7,


connect this transitions to appropriate state so that the
string stated in the problem is accepted.
a
q0 q1 Transition Diagram
a
Step9: Write the formal definition of DFA
M= (Q, S, d, q0, F) where
 Q ={q0,q1} Finite set of states
 S ={a} Alphabet set or input symbols
 q0 = q0 Initial (or start) state Transition Table
 F ={q1} Accepting states (or Final states).
d a
 d: Q × S → Q is a transition function
q0 q1
q1 q0
February 20, 2025 CSE, BMSCE 38
Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step10: Consider any one string which will be accepted and


one string which should not accepted by this DFA defined in
the step9. Show the transition function movements for
these strings.
d(q0, aaa)=d(q1, aa)=d(q0, a)= q1 ∈ F, Final state
Hence string aaa is accepted

Transition Table
d a
q0 q1
q1 q0
February 20, 2025 CSE, BMSCE 39
Construct a Deterministic Finite Automata (DFA) to recognize all
odd number a’s given the alphabet set as Σ ={a}

Step10: Consider any one string which will be accepted and


one string which should not accepted by this DFA defined in
the step9. Show the transition function movements for
these strings.
d(q0, aaa)=d(q1, aa)=d(q0, a)= q1 ∈ F, Final state
Hence string aaa is accepted

d(q0, aa)=d(q1, a)=q0 ∉ F, Final state


Hence string aa is not accepted
Transition Table
d a
q0 q1
q1 q0
February 20, 2025 CSE, BMSCE 40
Question
Construct a Deterministic Finite Automata (DFA)
that accepts set of all strings having aa as a
substring. Consider the alphabet set as Σ ={a,b}

February 20, 2025 CSE, BMSCE 41


Construct a Deterministic Finite Automata (DFA) that accepts set of all
strings having aa as a substring. Consider the alphabet set as Σ ={a,b}

Step1: Write possible strings of the Language that will be


accepted for the given DFA
L={aa, aaa, baa, aab, bbaa, aabb, baab, baaab, baabba,
……}
Step2: Write possible strings of the Language that should
not be accepted for the given DFA
={ε, a, ab, ba, aba, baba, abab……….}
Step3: Write down the minimum string that will be accepted
for the given DFA
‘aa’
Step4: Find the length of the minimum string, n=|aa|=2
Step5: Find number of States required to construct this DFA
Number of States=n+1=2+1=3

February 20, 2025 CSE, BMSCE 42


Construct a Deterministic Finite Automata (DFA) that accepts set of
all strings having aa as a substring. Consider the alphabet set as Σ
={a,b}

Step6: Draw the transition diagram of the DFA that accepts


minimum string. Note: Make sure that there in one Start State
and atleast one final state

q0 a q1 a q2

Step7: For the basic DFA, defined in Step6, consider one


state at a time and obtain the various missing transitions on
each input symbol

q0 a q1 a q1
b b b
a

February 20, 2025 CSE, BMSCE 43


Construct a Deterministic Finite Automata (DFA) that accepts set of
all strings having aa as a substring. Consider the alphabet set as Σ
={a,b}

Step8: For the missing transitions identified in step7, connect this transitions
to appropriate state so that the string stated in the problem is accepted.

b a

q0 a q1 a q2 Transition Diagram
b
b

Step9: Write the formal definition of DFA


M= (Q, S, d, q0, F) where Transition Table
 Q ={q0,q1,q2} Finite set of states

d a b
S ={a, b} Alphabet set or input symbols
 q0 = q0 Initial (or start) state q0 q1 q0
 F ={q2} Accepting states (or Final states).
q1 q2 q0
 d: Q × S → Q is a transition function
q2 q2 q2

February 20, 2025 CSE, BMSCE 44


Construct a Deterministic Finite Automata (DFA) that accepts set of
all strings having aa as a substring. Consider the alphabet set as Σ
={a,b}

Step10: Consider any one string which will be accepted and


one string which should not accepted by this DFA defined in
the step9. Show the transition function movements for
these strings.
d(q0, baa)=d(q0, aa)=d(q1, a)= q2 ∈ F, Final state
Hence string baa is accepted

d(q0, aba)=d(q1, ba)=d(q0, a)=q1 ∉ F, Final state


Hence string aba is not accepted
Transition Table
d a b
q0 q1 q0
q1 q2 q0
q2 q2 q2
February 20, 2025 CSE, BMSCE 45
Questions

Construct DFA’s accepting the following


strings over the alphabet set Σ ={0,1}
i. The set of all strings ending with 00
ii. The set of all strings with three
consecutive 0’s atleast once
iii. Set of all strings beginning with 00

February 20, 2025 CSE, BMSCE 46


Rough Slide to explain

Construct DFA’s accepting the following


strings over the alphabet set Σ ={0,1}
i. The set of all strings ending with 00

February 20, 2025 CSE, BMSCE 47


Construct DFA’s accepting the following strings over the
alphabet set Σ ={0,1}
i. The set of all strings ending with 00

q0

February 20, 2025 CSE, BMSCE 48


February 20, 2025 CSE, BMSCE 49
February 20, 2025 CSE, BMSCE 50
Questions
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
i. The set of all strings with exactly one ‘a’
ii. The set of all strings with at least one ‘a’
iii. Not more than three a’s in the strings
iv. The set of all strings except those which end with ‘abb’
v. Set of all strings not containing the substring ‘abb’
vi. The set of all strings either begins or ends or both with
substring ‘ab’
vii. Set of strings ending with ab or ba
viii. Set of all strings with at least one ‘a’ and exactly two b’s

February 20, 2025 CSE, BMSCE 51


Questions
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
i. The set of all strings with exactly one ‘a’
ii. The set of all strings with at least one ‘a’

February 20, 2025 CSE, BMSCE 52


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written

February 20, 2025 CSE, BMSCE 53


Questions
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
i. The set of all strings with exactly one ‘a’
ii. The set of all strings with at least one ‘a’
iii. Not more than three a’s in the strings
iv. The set of all strings except those which end with ‘abb’

February 20, 2025 CSE, BMSCE 54


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written

February 20, 2025 CSE, BMSCE 55


Questions
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
i. The set of all strings with exactly one ‘a’
ii. The set of all strings with at least one ‘a’
iii. Not more than three a’s in the strings
iv. The set of all strings except those which end with ‘abb’
v. Set of all strings not containing the substring ‘abb’
vi. The set of all strings either begins or ends or both with
substring ‘ab’

February 20, 2025 CSE, BMSCE 56


Rough slide to explain
Construct DFA’s accepting the following strings over the alphabet
set Σ ={a,b}
Set of all strings not containing the substring ‘abb’

February 20, 2025 CSE, BMSCE 57


February 20, 2025 CSE, BMSCE 58
Rough slide to explain
Construct DFA’s accepting the following strings over the alphabet
set Σ ={a,b}
The set of all strings either begins or ends or both with substring
‘ab’

February 20, 2025 CSE, BMSCE 59


February 20, 2025 CSE, BMSCE 60
Questions
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
i. The set of all strings with exactly one ‘a’
ii. The set of all strings with at least one ‘a’
iii. Not more than three a’s in the strings
iv. The set of all strings except those which end with ‘abb’
v. Set of all strings not containing the substring ‘abb’
vi. The set of all strings either begins or ends or both with
substring ‘ab’
vii. Set of strings ending with ab or ba
viii. Set of all strings with at least one ‘a’ and exactly two b’s

February 20, 2025 CSE, BMSCE 61


Rough Slide to explain
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
Set of strings ending with ab or ba

February 20, 2025 CSE, BMSCE 62


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written

February 20, 2025 CSE, BMSCE 63


Questions
Construct DFA’s accepting the following strings over the
alphabet set Σ ={a,b}
Set of all strings with at least one ‘a’ and exactly two b’s

February 20, 2025 CSE, BMSCE 64


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written

February 20, 2025 CSE, BMSCE 65


Question
The number of states in the minimal deterministic finite
automaton corresponding to the regular expression
(0 + 1)*(10) is ____________
(A) 2
(B) 3
(C) 4
(D) 5

February 20, 2025 CSE, BMSCE 66


Question
The number of states in the minimal deterministic finite
automaton corresponding to the regular expression (0 +
1)*(10) is ____________
(A) 2
(B) 3
(C) 4
(D) 5

Answer: (B)

0
February 20, 2025 CSE, BMSCE 67
Question
Draw a deterministic finite automata which accept
a string containing “the” anywhere in a string of
Σ ={a-z}, e.g., “there” but not “those”.

February 20, 2025 CSE, BMSCE 68


Question
Draw a deterministic finite automata which accept a string
containing “the” anywhere in a string of {a-z}, e.g., “there” but not
“those”.

February 20, 2025 CSE, BMSCE 69


Question
Draw a deterministic and non-deterministic finite automata which
accept a string containing “ing” at the end of a string in a string of
{a-z}, e.g., “anything” but not “anywhere”.

February 20, 2025 CSE, BMSCE 70


Questions
Construct DFA for the following languages over the alphabet
set Σ ={a, b}
i. L={awa / wÎ (a+b)* }
ii. L={w / na(w) mod 3 ==0 }
iii. L={w / |w| mod 3 ==0 }
iv. L={w / |w| mod 5 ≠ 0 }

February 20, 2025 CSE, BMSCE 71


Questions
Construct DFA for the following languages over the alphabet
set Σ ={a,b}
i. L={awa / wÎ (a+b)* }

February 20, 2025 CSE, BMSCE 72


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written

February 20, 2025 CSE, BMSCE 73


Rough Slide to explain
Construct DFA for the following languages over the alphabet
set Σ ={a, b}
L={w / na(w) mod 3 ==0 }

February 20, 2025 CSE, BMSCE 74


Questions
Construct DFA for the following languages over the alphabet
set Σ ={a, b}
i. L={awa / w Î (a+b)* }
ii. L={w / na(w) mod 3 ==0 }

February 20, 2025 CSE, BMSCE 75


Questions
Construct DFA for the following languages over the alphabet
set Σ ={a, b}
i. L={awa / wÎ (a+b)* }
ii. L={w / na(w) mod 3 ==0 }
iii. L={w / |w| mod 3 ==0 }

February 20, 2025 CSE, BMSCE 76


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written
OR

February 20, 2025 CSE, BMSCE 77


Questions
Construct DFA for the following languages over the alphabet
set Σ ={a, b}
i. L={awa / wÎ (a+b)* }
ii. L={w / na(w) mod 3 ==0 }
iii. L={w / |w| mod 3 ==0 }
iv. L={w / |w| mod 5 ≠ 0 }

February 20, 2025 CSE, BMSCE 78


Rough Slide to explain
Construct DFA for the following languages over the alphabet
set Σ ={a, b}
L={w / |w| mod 5 ≠ 0 }

L={w / |w| mod 5 == 0 }

February 20, 2025 CSE, BMSCE 79


Note: For the DFA’s,
a. Transition diagram
b. Formal definition
c. Transition Table
Should written

February 20, 2025 CSE, BMSCE 80


Question
1. Construct DFA to accept even number of a’s
over the alphabet set Σ ={a}
2. Construct DFA to accept odd number of a’s
over the alphabet set Σ ={a}

February 20, 2025 CSE, BMSCE 81


a

February 20, 2025 CSE, BMSCE 82


Questions
Construct DFA for the following language over the alphabet
set Σ ={a, b}
L={w / wÎ(a+b)* , na(w) mod 2 ==0 and nb(w) mod 2 ==0 }
OR
L={w / wÎ(a+b)* , Na(w) as well as Nb(w) is even }
OR
To accept strings of a’s and b’s with even number of a’s and b’s

February 20, 2025 CSE, BMSCE 83


Rough slide to explain
Construct DFA for the following language over the alphabet
set Σ ={a, b}
L={w / wÎ(a+b)* , na(w) mod 2 ==0 and nb(w) mod 2 ==0 }

February 20, 2025 CSE, BMSCE 84


February 20, 2025 CSE, BMSCE 85
Question
Consider the DFA with the following transition table:

Informally describe the language accepted by this DFA

February 20, 2025 CSE, BMSCE 86


Question
Consider the DFA with the following transition table:

Informally describe the language accepted by this DFA


Answer
 You should draw the transition graph before reading this
answer; it will help with your understanding.
 We claim that the language of the DFA is {w | w contains
an odd number of 1’s}

February 20, 2025 CSE, BMSCE 87


Question

February 20, 2025 CSE, BMSCE 88


Question

February 20, 2025 CSE, BMSCE 89


Question

February 20, 2025 CSE, BMSCE 90


Question

February 20, 2025 CSE, BMSCE 91


Question
Construct DFA for the following language over the alphabet
set Σ ={0, 1}
L={w / w is even length and begins with ‘01’

February 20, 2025 CSE, BMSCE 92


Question
Construct DFA for the following language over the alphabet
set Σ ={0, 1}
L={w / w is even length and begins with ‘01’

February 20, 2025 CSE, BMSCE 93


Question
Obtain DFA to accept strings of a’s and b’s such that
L={w / w Î (a+b)* such that
Na(w) mod 3 == 0 and Nb(w) mod 2==0}

February 20, 2025 CSE, BMSCE 94


Rough Slide to explain
Obtain DFA to accept strings of a’s and b’s such that
L={w / w Î (a+b)* such that
Na(w) mod 3 == 0 and Nb(w) mod 2==0}

Possible Remainders
Na(w) mod 3: { 0, 1, 2}
Nb(w) mod 2: { 0, 1}

So possible states of DFA


is given by cross product
Of {0,1,2} x {0,1}

February 20, 2025 CSE, BMSCE 95


February 20, 2025 CSE, BMSCE 96
Question
Obtain DFA to accept strings of a’s and b’s such that
L={w / w Î (a+b)* such that
Na(w) mod 5 == 0 and Nb(w) mod 3 ==0}

February 20, 2025 CSE, BMSCE 97


February 20, 2025 CSE, BMSCE 98
Question
Construct a DFA which accepts strings of 0’s and 1’s where
the values of each string is represented as a binary number
only. Only the strings representing zero modulo three should
be accepted. For example 0, 11, 011, 110, 1001, ……

OR
Design a DFA to accept the binary numbers which are
divisible by 3

February 20, 2025 CSE, BMSCE 99


Design a DFA to accept the binary numbers which are
divisible by 3

r is radix, For binary r=2


i is remainder obtained after dividing by k
d represents digits
k is divisor

r=2
i={0,1,2}
d={0,1}
k=3

We will use the relation, d(qi , a)=qj where j=(r*i+d) mod k

February 20, 2025 CSE, BMSCE 100


Design a DFA to accept the binary numbers which
are divisible by 3

Remai d j=(r*i+d) mod k d(qi , a)=qj


-nder
i=0 0 j=(2*0+0) mod 3=0 d(q0 , 0)=q0
1 j=(2*0+1) mod 3=1 d(q0 , 1)=q1
i=1 0 j=(2*1+0) mod 3=2 d(q1 , 0)=q2
1 j=(2*1+1) mod 3=0 d(q1 , 1)=q0
i=2 0 j=(2*2+0) mod 3=1 d(q2 , 0)=q1
1 j=(2*2+1) mod 3=2 d(q2 , 1)=q2

February 20, 2025 CSE, BMSCE 101


Question
Construct a DFA which accepts strings of 0’s and 1’s where
the values of each string is represented as a binary number
only. Only the strings representing zero modulo five should
be accepted. For example 0, 101, 0101, 1010, 1111, 1101,
………

OR
Design a DFA to accept the binary numbers which are
divisible by 5

February 20, 2025 CSE, BMSCE 102


Question
The password to the admins account=”administrator”. The
total number of states required to make a password-pass
system using DFA would be __________
a) 14 states
b) 13 states
c) 12 states
d) A password pass system cannot be created using DFA

February 20, 2025 CSE, BMSCE 103


Question
The password to the admins account=”administrator”. The
total number of states required to make a password-pass
system using DFA would be __________
a) 14 states
b) 13 states
c) 12 states
d) A password pass system cannot be created using DFA

Answer: a
Explanation: For a string of n characters with no repetitive
substrings, the number of states required to pass the string
is n+1.

February 20, 2025 CSE, BMSCE 104


DFA Exercises

February 20, 2025 CSE, BMSCE 105


February 20, 2025 CSE, BMSCE 106
February 20, 2025 CSE, BMSCE 107
Examples

 Construct a DFA that accepts the


language
L = {010, ( S = {0, 1}
1} )

 Answer
q0 1 q01 0 q010
0
0 1
qe 0, 1
1 0, 1
q1 qdie
0, 1
Examples
 Construct a DFA over alphabet {0, 1}
that accepts all strings that end in
101

 Hint: The DFA must “remember” the


last 3 bits of the string it is reading
Examples
 Construct a DFA over alphabet {0, 1}
that accepts all strings that end in
101
 Sketch of answer: 0
0 q000
0 q00 1
1
q0 q001
1
0 q01 …


qe
1 q101
0 q10
1
q1 …


1
q11 1
q111 1
February 20, 2025 CSE, BMSCE 111
Unit-1

Nondeterministic Finite Automata (NFA)

February 20, 2025 CSE, BMSCE 112


Rough slide to explain
Nondeterministic Finite Automata (NFA)

DFA: Set of all strings ending with ab over S ={a, b}

NFA: Set of all strings ending with ab over S ={a, b}

February 20, 2025 CSE, BMSCE 113


Nondeterministic Finite Automata
 Non determinism gives a machine
multiple options for its moves.
Nondeterministic Finite Automata

Suppose in life,
 Whenever you had a choice, you
could try both possibilities and live
your life.
 At the end, you would go back and
choose the one that worked out the
best.
Formal Definition of an NFA

February 20, 2025 CSE, BMSCE 116


Rough Slide to explain NFA formal definition

NFA: Set of all strings ending with ab over S ={a,b}

February 20, 2025 CSE, BMSCE 117


Example of NFA

February 20, 2025 CSE, BMSCE 118


NFA
Unit-1

Equivalence of NFA and DFA (or)


Converting NFA to DFA

February 20, 2025 CSE, BMSCE 120


Converting NFA to DFA using subset construction method
Subset Construction Procedure

Given an NFA MNFA= (Q nfa , S, d nfa, q0, F nfa) which accepts the language L, find an
equivalent DFA MDFA= (Q dfa, S, d dfa , q0, F dfa) such that
L(MNFA) =L(MDFA)
Step-1: Identify the start state of the DFA . Since q o is the start state of NFA,
{q0} is the start state of DFA
Step-2: Identify the alphabets of DFA. The input alphabets of NFA are the input
alphabets of DFA
Step-3: Identify the QDFA , which are the states of DFA
The set of subsets of QNFA will be the states of DFA QDFA
Example:
QNFA ={q0 , q1 , q2 }
QDFA ={∅ , {q0} , {q1} , {q2}, {q0 , q1 } , {q0 , q2 } …..}
Step-4: Identify the final states of DFA
If {qi , qj, …qk} is the state of DFA then {qi , qj, …qk} will be final state of DFA
provided one of qi , qj, …qk is the final state of NFA
Step-5: Identifying transitions of DFA
For each state {qi , qj, …qk} in QDFA and for each input symbol ‘a’ in S , the
transition can be obtained as shown below
dDFA ({qi , qj, …qk} , a) = {dNFA (qi, a) U dNFA (qj, a) ……..}
February 20, 2025 CSE, BMSCE 121
Converting NFA to DFA using subset construction method

February 20, 2025 CSE, BMSCE 122


Rough Slide to explain: Obtain the NFA to accept strings of
a’s and b’s ending with ab and convert into equivalent DFA
Converting NFA to DFA
NFA to accept strings ending with ab
a, b MDFA= (Q dfa , S, d dfa , q0, F dfa)
S ={a, b} , q0 = { q0 }
q0 a q1 b q2 dDFA ({qi , qj, …qk} , a) =
{dNFA (qi, a) U dNFA (qj, a) ……..}
MNFA= (Qnfa , S, d nfa, q0, F nfa)
QNFA ={q0,q1,q2}

S ={a, b} , q0 = q0 , FNFA={q2}

dNFA: Q × S → 2Q dDFA a b
Transition Table

dNFA a b
q0 {q0, q1} {q0}
q1 ∅ {q2}
q2 ∅ ∅

February 20, 2025 CSE, BMSCE 123


February 20, 2025 CSE, BMSCE 124
dNFA a b
q0 {q0, q1} {q0}
q1 ∅ {q2}
q2 ∅ ∅

dDFA ({qi , qj, …qk} , a)=


{dNFA (qi, a) U
dNFA (qj, a) ……..}

February 20, 2025 CSE, BMSCE 125


Question
Convert following NFA to its equivalent DFA

February 20, 2025 CSE, BMSCE 126


Answer
Convert following NFA to its equivalent DFA

February 20, 2025 CSE, BMSCE 127


Obtain NFA to accept strings of a’s and b’s ending
with ab or ba and convert into equivalent DFA

February 20, 2025 CSE, BMSCE 128


February 20, 2025 CSE, BMSCE 129
Question
Convert the following NFA to a DFA

February 20, 2025 CSE, BMSCE 130


Question
Convert the following NFA to a DFA

Answer

February 20, 2025 CSE, BMSCE 131


Question
Which of the following options is correct?
Statement 1: Initial State of NFA is Initial State of DFA.
Statement 2: The final state of DFA will be every
combination of final state of NFA.
a) Statement 1 is true and Statement 2 is true
b) Statement 1 is true and Statement 2 is false
c) Statement 1 can be true and Statement 2 is true
d) Statement 1 is false and Statement 2 is also false

February 20, 2025 CSE, BMSCE 132


Question
Which of the following options is correct?
Statement 1: Initial State of NFA is Initial State of DFA.
Statement 2: The final state of DFA will be every
combination of final state of NFA.
a) Statement 1 is true and Statement 2 is true
b) Statement 1 is true and Statement 2 is false
c) Statement 1 can be true and Statement 2 is true
d) Statement 1 is false and Statement 2 is also false

Answer: a
Explanation: Statement 1 and 2 always true for a given
Language.

February 20, 2025 CSE, BMSCE 133


Question
Subset Construction method refers to:
a) Conversion of NFA to DFA
b) DFA minimization
c) Eliminating Null references
d) e-NFA to NFA

February 20, 2025 CSE, BMSCE 134


Question
Subset Construction method refers to:
a) Conversion of NFA to DFA
b) DFA minimization
c) Eliminating Null references
d) e-NFA to NFA

Answer: a
Explanation: The conversion of a non-deterministic
automata into a deterministic one is a process we
call subset construction or power set construction.

February 20, 2025 CSE, BMSCE 135


Questions
1. Obtain NFA for the language L={w / w Î ababn or aban
n>=0}
2. Design a NFA to accept the language which consists of
string w Î {a,b}* which has aab as substring
3. Design a NFA that accepts the language L(aa*(a+b))
4. Design a NFA that accepts the language L={a3 U a2n,
n>=1}
5. Construct NFA for accepting the set of all strings whose
second last symbol is 1 over the alphabet set S ={0,1}
6. Write NFA accepting all strings of 0’s and 1’ssuch that
either second or third position from the end has 1.

February 20, 2025 CSE, BMSCE 136


Questions
1. Obtain NFA for the language L={w / w Î ababn or aban
n>=0}

February 20, 2025 CSE, BMSCE 137


Questions
1. Obtain NFA for the language L={w / w Î ababn or aban
n>=0}

February 20, 2025 CSE, BMSCE 138


Questions
2. Design a NFA to accept the language which consists of
string w Î {a,b}* which has aab as substring

February 20, 2025 CSE, BMSCE 139


Questions
3. Design a NFA that accepts the language L(aa*(a+b))

February 20, 2025 CSE, BMSCE 140


Questions
4. Design a NFA that accepts the language L={a3 U a2n,
n>=1}

February 20, 2025 CSE, BMSCE 141


Questions
5. Construct NFA for accepting the set of all strings whose
second last symbol is 1 over the alphabet set S ={0,1}
6. Write NFA accepting all strings of 0’s and 1’s such that
either second or third position from the end has 1.

February 20, 2025 CSE, BMSCE 142


Questions
5. Construct NFA for accepting the set of all strings whose second last
symbol is 1 over the alphabet set S ={0,1}
6. Write NFA accepting all strings of 0’s and 1’s such that either second or
third position from the end has 1.

February 20, 2025 CSE, BMSCE 143


Question
Answer
Question
Answer
Homework Problem
 Give an NFA over {0,1} that accepts the set of strings
that contain an even number of substrings 01.

February 20, 2025 CSE, BMSCE 148


Homework problem
Answer

NFA
Answer
Answer

DFA
Converting NFA to DFA using subset construction method
Homework Problem

February 20, 2025 CSE, BMSCE 157


Question
 The number of states in the minimal deterministic finite
automaton corresponding to the regular expression (0 +
1)*(10) is ____________
(A) 2
(B) 3
(C) 4
(D) 5

Answer: (B) NFA

1
0
February 20, 2025 CSE, BMSCE 158
Question
Draw a deterministic and non-deterministic finite automata which
accept a string containing “the” anywhere in a string of {a-z}, e.g.,
“there” but not “those”.

February 20, 2025 CSE, BMSCE 159


Question
Draw a deterministic and non-deterministic finite automata which
accept a string containing “ing” at the end of a string in a string of
{a-z}, e.g., “anything” but not “anywhere”.

February 20, 2025 CSE, BMSCE 160


February 20, 2025 CSE, BMSCE 161
Unit-1: Non-Deterministic Finite Automata
(NFA) with ε-transitions

NFA with ε-transitions is a finite automata in which there


are transitions from one state to other state even without
taking input alphabet.

February 20, 2025 CSE, BMSCE 162


NFA with ε – Transitions: Formal Definition
NFA with ε –moves is a 5-tuple system
ME= (Q, S, d, q0, F) where
 Q is a finite set of states
 S is an alphabet set or input symbols
 q0 Î Q is the initial (or start)state
 F Í Q is a set of accepting states (or final states).
 d: Q × ( S U ε ) → 2Q is a transition function
d (q , a) will consists of all states of p such that there is a transition
labelled ‘a’ from q to p where ‘a’ is either ε or a symbol in S

Note:
- Transition in ε – NFA is allowed to make a transition spontaneously without
receiving an input symbol.
- ε-NFA’s are closely related to regular expressions.
- ε-NFA’s are useful in proving the equivalence between the classes of
language accepted by finite automate and by regular expressions

February 20, 2025 CSE, BMSCE 163


Rough slide to Explain example of ε-NFA
ε z-NFA that accepts decimal number consisting of
i. An optional + or - sign
ii. A string of digits
iii. A decimal point
iv. Another string of digits. Either this string of digits or the string can be
empty, but at least one of the two strings of digits must be non empty.

February 20, 2025 CSE, BMSCE 164


Rough slide to Explain example of NFA without ε-moves

ε z-NFA that accepts decimal number consisting of


i. An optional + or - sign
ii. A string of digits
iii. A decimal point
iv. Another string of digits. Either this string of digits or the string can be
empty, but at least one of the two strings of digits must be non empty.

February 20, 2025 CSE, BMSCE 165


NFA without ε-moves

February 20, 2025 CSE, BMSCE 166


February 20, 2025 CSE, BMSCE 167
Rough slide to explain:ε-Closure or Empty closure

ε-Closure of a state: It is a set of reachable states


from a given state with ε-Transitions.
ε-Closure (q) = q U set of all states that can be
reached with ε

February 20, 2025 CSE, BMSCE 168


ε-Closure or Empty closure
ε-Closure of a state: It is a set of reachable states
from a given state with ε-Transitions.
ε-Closure (q) = q U set of all states that can be
reached with ε

February 20, 2025 CSE, BMSCE 169


Question
Considering the following ε–NFA , compute the ε-
closure of the states q0, q4 , q1
q3

February 20, 2025 CSE, BMSCE 170


February 20, 2025 CSE, BMSCE 171
Converting ε–NFA to DFA
Conversion procedure is very close to Subset construction procedure
Given an ε- NFA ME= (Qe , S, de , q0 , Fe ) which accepts the language L, find
an equivalent DFA MD= (Qd , S, dd , qd , Fd ) such that L(ME) =L(MD)

Step-1: If q0 is start state of ε–NFA then ε-Closure(q0) is the start


state of DFA i.e. , qd = ε-Closure (q0)
Step-2: Compute the transitions for DFA. Let {qi , qj, …qk} be the
state of DFA. Then, the transitions from this state on ‘a’ i.e. dd({qi ,
qj, …qk} , a) is computed as shown below
- Let de({qi , qj, …qk} , a) ={P1, P2,……Pm}
- Then, take ε-Closure({P1, P2,……Pm})
Thus, dd({qi , qj, …qk} , a) = ε-Closure(de({qi , qj, …qk} , a) )
Step-3: If {qi , qj, …qk} is a state in DFA and if this set contains at
least one final state of ε -NFA , then {qi , qj, …qk } is the final state
of DFA

February 20, 2025 CSE, BMSCE 172


Rough Slide to explain
Converting ε-NFA to DFA

de +,- . 0-9 ε
q0 {q1} ∅ ∅ {q1}
q1 ∅ {q2} {q1 ,q4} ∅
q2 ∅ ∅ {q3} ∅
q3 ∅ ∅ {q3} {q5}
q4 ∅ {q3} ∅ ∅
q5 ∅ ∅ ∅ ∅

February 20, 2025 CSE, BMSCE 173


Rough Slide to explain
Converting ε-NFA to DFA

= (Qd , S, dd , qd , Fd )
D dd +,- . 0-9
= {. , + , - , 0, 1, 2, 3 ,4,5 ,6, 7, 8, 9}
qd = ε -Closure(q0)

February 20, 2025 CSE, BMSCE 174


Converting ε-NFA to DFA

February 20, 2025 CSE, BMSCE 175


Converting ε-NFA to DFA (Contd…)

February 20, 2025 CSE, BMSCE 176


Converting ε-NFA- to DFA

February 20, 2025 CSE, BMSCE 177


February 20, 2025 CSE, BMSCE 178
February 20, 2025 CSE, BMSCE 179
February 20, 2025 CSE, BMSCE 180
Difference between DFA, NFA, ε-NFA
DFA NFA ε-NFA
M= (Q, S, d, q0, F) where MNFA= (Q, S, d, q0, F) where ME= (Q, S, d, q0, F) where
Q is a finite set of states Q is a finite set of states Q is a finite set of states
S is an alphabet set or S is an alphabet set or S is an alphabet set or
input symbols input symbols input symbols
d: Q × S → Q is a q0 Î Q is the initial (or q0 Î Q is the initial (or
transition function start)state start)state
q0 Î Q is the initial (or F Í Q is a set of F Í Q is a set of
start)state accepting states (or final accepting states (or final
F Í Q is a set of states). states).
accepting states d: Q × S → 2Q is a d: Q × ( S U ε ) → 2Q is a
transition function transition function
If a string w is accepted by DFA If a string w is accepted by NFA For ε-NFA, there may be many
from state q, there will be from state q, there will be paths labelled w along with ε
exactly one path labelled w many paths labelled w. and all must be checked to see
starting at q. Therefore, to Therefore, to determine if a whether one or more terminate
determine if a string is string is accepted, it is at final state.
accepted, it is sufficient to necessary to check all these If the final state is reached, the
check for this one path. paths to see whether on or given string w is accepted by
Following this path, if the more terminate at final state. the machine else it is rejected
machine is in final state, we say Following these path, if we by the machine.
that the string w is accepted. reach a final state, the string is
Otherwise, the string is rejected accepted else the string is
rejected.
Difficult to construct Easy to construct Easy to construct using regular
expression
Text Search using Automata

February 20, 2025 CSE, BMSCE 182


February 20, 2025 CSE, BMSCE 183
February 20, 2025 CSE, BMSCE 184
February 20, 2025 CSE, BMSCE 185
February 20, 2025 CSE, BMSCE 186
Thanks for Listening

Look for updates at Course Webpage:


https://sites.google.com/site/drvumadevi/teaching/tfc-jan-may-20
20

No need to remember the webpage URL


Do Google Search - – “Umadevi BMS”, you will find
teaching webpage

February 20, 2025 CSE, BMSCE 187


Homework Problems

1. Obtain a DFA to accept strings of 0’s , 1’s and


2’s beginning with a ‘0’ followed by odd number of
1’s and ending with ‘2’

2. Construct DFA for the following language over


the alphabet set Σ ={0, 1}
L={w / w is even length and begins with ‘01’

February 20, 2025 CSE, BMSCE 188


Question
Obtain a DFA to accept strings of 0’s , 1’s and 2’s
beginning with a ‘0’ followed by odd number of 1’s
and ending with ‘2’

February 20, 2025 CSE, BMSCE 189


Question
 What is the complement of the language accepted by the NFA
shown below? Assume ∑ = {a} and ε is the empty string

 (A) Φ
(B) ε
(C) a
(D) {a, ε}
 Answer (B)
The given alphabet ∑ contains only one symbol {a} and the
given NFA accepts all strings with any number of occurrences
of ‘a’. In other words, the NFA accepts a+. Therefore
complement of the language accepted by automata is empty
string.

February 20, 2025 CSE, BMSCE 190

You might also like