You are on page 1of 123

Finite Automata

Module 1
Session 1

1
Module 1 Syllabus
FINITE AUTOMATA:
Central concepts of automata theory,
deterministic finite automata, non-deterministic
finite automata, finite automata with epsilon
transitions, Moore and Mealy machines.

2
Contents

 Introduction
 What is AT

 Basic Concepts of AT

 Historical Perspective of ToC

 Languages, Grammars & Hierarchy

 Central Concepts of FLAT


 Alphabet, Strings & Languages

 Applications of FLAT

 Components of Automata

 Classification of Automata

3
What is Automata Theory?
 Study of abstract computing devices, or
“machines”
 Automaton = an abstract computing device
 Note: A “device” need not even be a physical
hardware!
 A fundamental question in computer science:
 Find out what different models of machines can do
and cannot do
 The theory of computation
 Computability vs. Complexity

4
Basic Concepts of
Automata Theory
 Automaton: a formal construct that accepts input,
produces output, may have some temporary storage,
and can make decisions
 Formal Language: a set of sentences formed from a set

of symbols according to formal rules


 Grammar: a set of rules for generating the sentences in a

formal language
In addition, the theory of computation is concerned with
questions of computability (the types of problems
computers can solve in principle) and complexity (the types
of problems that can solved in practice).
5
(A pioneer of automata theory)

Alan Turing (1912-1954)


 Father of Modern Computer
Science
 English mathematician
 Studied abstract machines called
Turing machines even before
computers existed
 Heard of the Turing test?

6
Theory of Computation: A
Historical Perspective
1930s • Alan Turing studies Turing machines
• Decidability
• Halting problem
1940-1950s • “Finite automata” machines studied
• Noam Chomsky proposes the
“Chomsky Hierarchy” for formal
languages
1969 Cook introduces “intractable” problems
or “NP-Hard” problems
1970-1980s Modern computer science: compilers,
computational & complexity theory evolve
7
Languages & Grammars
 Languages: “A language is a
Or “words” collection of sentences of
finite length all constructed
from a finite alphabet of
symbols”
 Grammars: “A grammar can
be regarded as a device that
enumerates the sentences
of a language” - nothing
more, nothing less

 N. Chomsky, Information and


Control, Vol 2, 1959

Image source: Nowak et al. Nature, vol 417, 2002


8
The Chomsky Hierachy
• A containment hierarchy of classes of formal languages

Regular Context-
(DFA) Context- Recursively-
free
sensitive enumerable
(PDA)
(LBA) (TM)

9
The Central Concepts of
Automata Theory

10
Alphabet
An alphabet is a finite, non-empty set of
symbols
 We use the symbol ∑ (sigma) to denote an

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}
 …

11
Strings
A string or word is a finite sequence of symbols
chosen from ∑
 Empty string is  (or “epsilon”)

 Length of a string w, denoted by “|w|”, is


equal to the number of (non- ) characters in the
string
 E.g., x = 010100 |x| = 6
 x = 01  0  1  00  |x| = ?

 xy = concatenation of two strings x and y


12
Alphabet and String contd..

13
Powers of an alphabet
Let ∑ be an alphabet.

 ∑k = the set of all strings of length k

 ∑* = ∑0 U ∑1 U ∑2 U …

 ∑ + = ∑ 1 U ∑ 2 U ∑3 U …

EXAMPLE: {01}2 = The set of all strings of length 2


={00,11,01,10}
14
Languages
L is a said to be a language over alphabet ∑, only if L  ∑*
 this is because ∑* is the set of all strings (of all possible
length including 0) over the given alphabet ∑
Examples:
1. Let L be the language of all strings consisting of n 0’s
followed by n 1’s:
L = {, 01, 0011, 000111,…}
2. Let L be the language of all strings of with equal number of
0’s and 1’s:
L = {, 01, 10, 0011, 1100, 0101, 1010, 1001,…}
Canonical ordering of strings in the language

Definition: Ø denotes the Empty language


 Let L = {}; Is L=Ø?
  Denotes Empty String NO 15
Strings and Languages
OPERATION DEFINITION
union of L and M L  M = {s | s is in L or s is in M}
written L  M
concatenation of L LM = {st | s is in L and t is in M}
and M written LM
Kleene closure of L L* =  Li , i=0,.., 
written L*
L* denotes “zero or more concatenations of “ L
positive closure of L +
written L + L =  L i
, i=1,.., 
L+ denotes “one or more concatenations of “ L
L + = LL *
Strings and Languages
L = {A, B, …, Z, a, b, …z} D = {1, 2, …, 9}

L  D = the set of letters and digits


LD = all strings consisting of a letter followed by a digit
L2 = the set of all two-letter strings
L4 = L2 L2 = the set of all four-letter strings
L* = { All possible strings of L plus  }, L+ = L* - 
D+ = set of strings of one or more digits
L (L  D ) = set of all strings consisting of a letter followed by a a
letter or a digit
L (L  D )* = set of all strings consisting of letters and digits
beginning with a letter
The Membership Problem
Given a string w ∑*and a language L
over ∑, decide whether or not w L.

Example:
Let w = 100011
Q) Is w  the language of strings with
equal number of 0s and 1s?

18
Finite Automata
 Some Applications
 Software for designing and checking the behavior
of digital circuits
 Lexical analyzer of a typical compiler
 Software for scanning large bodies of text (e.g.,
web pages) for pattern finding
 Software for verifying systems of all types that
have a finite number of states (e.g., stock market
transaction, communication/network protocol)

19
Finite Automata : Examples
action
 On/Off switch state

 Modeling recognition of the word “then”

Start state Transition Intermediate Final state


state
20
Components of an Automata
 An automaton is an abstract model of a
digital computer
 An automaton consists of
 An input mechanism
 A control unit
 Possibly, a storage mechanism
 Possibly, an output mechanism
 Control unit can be in any number of internal states,
as determined by a next-state or transition function.
Diagram of a General
Automaton

22
Automata Components

Input file: is divided into squares.

 Input is a string over a given alphabet.

 Each input square holds a symbol.

 The symbols are read from left to right, one at a time.

 The end of the input string can be detected.

23
Automata Components
Storage: consists of an unlimited number of cells.

 Each cell can hold a symbol from an alphabet


(which can be different from the input alphabet).

 The contents of the storage cells can be read and


changed.

24
Automata Components
Control unit: has a finite number of internal states.

 Can be in any one of the internal states.

 Can change state in some defined manner.

25
Automata Components
 Transition function:
current state  input symbol  storage info  next state

Output may be produced


Info in the storage may be changed

 Configuration: current state  input symbol  storage info

 Move: current configuration  next configuration

26
Classification of Automata
General types of automata:

 Accepter: yes/no output


Transducer: string of symbols as output

 Deterministic: single move on accepting single input.


Non-deterministic: multiple moves on accepting single
input.

27
Finite Automata
Module 1
Session 2

28
Contents

 Finite State Automata


 FSA & Types of FSA

 DFA & Representation of DFA

 String Processing of DFA

 DFA for Pattern Recognition Problems

 Examples of DFA

 Extended Transition Function of DFA

29
Finite State Automata (FSA)

30
Finite State Automaton (FSA)
 Informally, a state diagram that comprehensively
captures all possible states and transitions that a
machine can take while responding to a stream or
sequence of input symbols
 Recognizer for “Regular Languages”

 Deterministic Finite Automata (DFA)


 The machine can exist in only one state at any given time
 Non-deterministic Finite Automata (NFA)
 The machine can exist in multiple states at the same time

31
Deterministic Finite Automata
- Definition
 A Deterministic Finite Automaton (DFA)
defined by the 5-tuple: {Q, ∑ , q0,F, δ }
Where,
 Q ==> a finite set of states

 ∑ ==> a finite set of input symbols (alphabet)

 q ==> a start state


0
 F ==> set of accepting states

 δ ==> a transition function, which is a mapping

between Q x ∑ ==> Q

32
Representation of FSA
 Two ways:
 Graph Representation
 Transition Table Representation

33
Graph Representation of
DFA’s

Self Loop

34
Graph Representation of
DFA’s
 Nodes = states.
 Arcs represent transition function.
 Arc from state p to state q labelled by all
those input symbols that have
transitions from p to q.
 Arrow labelled “Start” to the start state.
 Final states indicated by double circles.

35
Transition Diagram
Representation
 FSA which accepts a binary string with
odd number of 1’s.

36
Transition Table Representation
 Tabular Representation of δ function.
 Takes two inputs and produce one output.
 Rows represent states and columns
represent the input symbols of ∑.
 Corresponding value of row & column
gives the new output state.

37
Transition Table Representation
Example
 FSA which accepts a binary string with odd
number of 1’s.

38
What does a DFA do on
reading an input string?
 Input: a word w in ∑*
 Question: Is w acceptable by the DFA?
 Steps:
 Start at the “start state” q0
 For every input symbol in the sequence w do
 Compute the next state from the current state, given the
current input symbol in w and the transition function
 If after all symbols in w are consumed, the current
state is one of the accepting states (F) then accept
w;
 Otherwise, reject w.
39
Regular Languages
 Let L(A) be a language recognized by a
DFA A.
 Then L(A) is called a “Regular Language”.

 Locate regular languages in the


Chomsky Hierarchy

40
The Chomsky Hierarchy
• A containment hierarchy of classes of formal languages

Regular Context-
(DFA) Context- Recursively-
free
sensitive enumerable
(PDA)
(LBA) (TM)

41
Pattern recognition problems
The following are the steps to be followed:
 1. Identify the alphabet.

 2. Identify the minimum string.

 3. Construct a skeleton DFA (for minimum

string)
 4. Identify other transitions not defined in

step 3.
 5. Construct a DFA using transitions in step

3 and step 4. 42
Example #1
 Build a DFA for the following language:
 L = {w | w is a binary string that contains 01 as a substring}
 Steps for building a DFA to recognize L:
 ∑ = {0,1}
 Identify minimum string “01”
 Construct skeleton DFA
 Decide on the states: Q
 Designate start state and final state(s)
 δ: Decide on the transitions:
 “Final” states == same as “accepting states”
 Other states == same as “non-accepting states”

43
DFA for strings containing 01
Solution:
• What makes this DFA deterministic? • Q = {q0,q1,q2}

1 0 0,1 • start state = q0


• ∑ = {0,1}
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
Valid strings:01,101,001,10010……
q0 q1 q0
states

q1 q1 q2
• What if the language allows
*q2 q2 q2
empty strings?
44
Example #2
 Obtain a DFA which accepts strings of a’s and b’s
starting with the string ‘ab’
 Step1: Identify the ∑, i.e., ∑={ a, b }
 Step2: Write the language (L) for the given problem
i.e., L={ ab, aba, abb, abba, abab, abaaa, abbaba,
ababbb….}
 Step3: Now, Construct the DFA for the minimal string,
i.e, ‘ab’.

45
Transition Diagram

DFA which accepts a’s and b’s starting with ‘ab’


L={ ab, aba, abb, abba, abab, abaaa, abbaba, ababbb….}

46
Transition Table

47
Example #3
 Build a DFA for the following language:
L = { w | w is a binary string that has
even number of 1s and even number of
0s}
 ?

48
Solution

 L={,0011,0101,1100,00001111,…….}
 Even number of zero’s and one’s
49
Transition Table

50
Example #4
 Build a DFA that accepts the language
over alphabet, ∑={0,1} of all that contain
neither the substring 00 nor 11.
 not contain 00 or 11
 ?

51
Solution
 Step1: Construct a DFA which contains
the sub-string either ’00’ or ‘11’.
 Step2: Complement the DFA to the
actual DFA.
 Make final states as non-final and non-final
states as final states.

52
53
54
Divisible by K problems
 For these types of problems, the transitions can be obtained using the
following relation:

 where, r is the radix of input


 i is the remainder obtained after dividing by k
 d represents digits
 k is the divisor
 The following are the steps to be followed:
 1. Identify the radix, input alphabets and the divisor k.
 2. Compute the possible remainders: These remainders represent the
states of DFA.
 3. Find the transitions using where j=(r*i+d)mod k
 4. Construct the DFA using the transitions obtained in step 3.

55
Example #1
 Obtain a DFA that accepts the decimal string which are divisible by 3.
 Solution:

 Now all the numbers with remainder value zero can be considered as
one number i.e., 0 (zero).
 All the numbers with remainder value one can be taken as one number
i.e., 1 (one).
 All the numbers with remainder value two can be taken as a single
number i.e., 2 (two).
56
57
58
Transition table

59
Transition diagram

Start state
as well as
final state

60
61
Example #2
 Build a DFA that accepts the language
over alphabet, ∑={0,1} where the
language is divisible by 3.

62
63
Modulo k counter problems
Construct a DFA for the given language
L={w: |w| mod 3 >= |w| mod 2 where
wϵ∑*and ∑={a}}

 Solution:
 |w| mod 3 means the length of the string must be completely divisible by 3.
 |w| mod 2 means the length of the string must be completely divisible by 2.
 Now, draw the automata separately to satisfy both the conditions. 64
65
 The set of states of Q1 = {0,1,2} and Q2 = {0,1}. Now, find out
the cross product: Q = Q1xQ2
 Q = {(0,0), (0,1), (1,0), (1,1), (2,0), (2,1) }
 Now find out the transitions starting from first cross product (0,0)

66
 Now draw the automata by using the
obtained transitions:

67
 Now check the condition: |w| mod 3 >= |w| mod 2
 For example: w = aaaa, |w| = 4
 |w| mod 3 >= |w| mod 2
 1 >= 0 (1>=0 is true --> so this state will become one of the final
state.)
 Likewise, check all the pair of cross product, where ever
remainder value of M1 is greater than or equal to the remainder
value of M2. All those states will become final states of DFA as
shown in below transition diagram.

68
Extended transitions (δ) to (δ)
 It is used whenever the input w is given
 δ (q,w) = destination state from state q on
input string w
 If w=‘abb’
 δ (q0,abb) = δ (δ(q0,a), bb)
= δ (q1, bb)
= δ (δ (q1, b),b) Final State

= δ (q1,b)= δ (q1,b)= q2
69
Language of a DFA
A DFA A accepts string w if there is a path
from q0 to an accepting (or final) state
that is labeled by w

 i.e., L(A) = { w | δ(q0,w)  F }

 I.e., L(A) = all strings that lead to an


accepting state from q0
70
Non-deterministic Finite
Automata (NFA)
 A Non-deterministic Finite Automaton
(NFA)
 is of course “non-deterministic”
 Implying that the machine can exist in more
than one state at the same time
 Transitions could be non-deterministic

71
Non-deterministic Finite
Automata (NFA)
 A Non-deterministic Finite Automaton (NFA)
consists of:
 Q ==> a finite set of states
 ∑ ==> a finite set of input symbols (alphabet)
 q0 ==> a start state
 F ==> set of accepting states
 δ ==> a transition function, which is a mapping
between Q x ∑ ==> 2Q
 An NFA is also defined by the 5-tuple:
 {Q, ∑ , q0,F, δ }

72
How to use an NFA?
 Input: a word w in ∑*
 Question: Is w acceptable by the NFA?
 Steps:
 Start at the “start state” q0
 For every input symbol in the sequence w do
 Determine all possible next states from all current states, given
the current input symbol in w and the transition function
 If after all symbols in w are consumed and if at least one of
the current states is a final state then accept w;
 Otherwise, reject w.

73
NFA for strings containing 01

Why is this non-deterministic?


• Q = {q0,q1,q2}

0,1 0,1 •  = {0,1}


• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Final • Transition table
state symbols
0 1
What will happen if at state q1 q0 {q0,q1} {q0}
states

an input of 0 is received? q1 Φ {q2}


*q2 {q2} {q2}

74
Note: Omitting to explicitly show error states is just a matter of design convenience
(one that is generally followed for NFAs), and
i.e., this feature should not be confused with the notion of non-determinism.

What is an “error state”?


 A DFA for recognizing the key word
“while” q
w
q
h
q
i
q
l
q
e
q5
0 1 2 3 4

Any other input symbol


qerr
Any symbol

 An NFA for the same purpose:


w h i l e
q0 q1 q2 q3 q4 q5

Transitions into a dead state are implicit 75


Example #2
 Build an NFA which accepts strings of
a’s and b’s are ending with ‘ab’ or ’ba’.
 Solution: Step1: Identify the ∑={a,b}
 Step2: Identify the language L.
L={ab,ba,aab,aba,bba,aaab,aaaba,…}
 Step3: Construct the NFA with Minimal
Strings ‘ab’ or ‘ba’.

76
Transition Diagram

77
Transition Table

78
Example #3 (Oct-2018)
 Construct an NFA that will accept those
strings of decimal digits that are
divisible by 3 Solution:
 Step1: Identify the ∑={0,1,2,…9,}
 Step2: Identify the language L.
 Step3: Draw the Transition Diagram and
Transition Table.

79
Solution

80
Example #4 (Oct-2019 &
2017)
Draw the Finite state diagram which
accepts all floating point numbers.
 Solution:

 Step1: Identify the ∑={0,1,2,…9,+,-, . , }

 Step2: Identify the language L.

 Step3: Draw the Transition Diagram and

Transition Table.

81
Solution

82
Example #5
 Build an NFA for the following language:
L = { w | w ends in 01}
 ?
 Other examples
 Keyword recognizer (e.g., if, then, else,
while, for, include, etc.)
 Strings where the first symbol is present
somewhere later on at least once

83
Transition diagram

84
Extension of δ to NFA Paths
 Basis: δ (q,) = {q}

 Induction:
 Let δ (q0,w) = {p1,p2…,pk}
 δ (pi,a) = Si for i=1,2...,k

 Then, δ (q0,wa) = S1 U S2 U … U Sk

85
Language of an NFA
 An NFA accepts w if there exists at least
one path from the start state to an
accepting (or final) state that is labeled
by w
 L(N) = { w | δ(q0,w) ∩ F ≠ Φ }

86
Advantages & Caveats for
NFA
 Great for modeling regular expressions
 String processing - e.g., grep, lexical analyzer

 Could a non-deterministic state machine be


implemented in practice?
 Probabilistic models could be viewed as extensions of non-
deterministic state machines
(e.g., toss of a coin, a roll of dice)
 They are not the same though

 A parallel computer could exist in multiple “states” at the same time

87
Technologies for NFAs
 Micron’s Automata Processor (introduced in 2013)
 2D array of MISD (multiple instruction single data) fabric
w/ thousands to millions of processing elements.
 1 input symbol = fed to all states (i.e., cores)

Non-determinism using circuits
 http://www.micronautomata.com/

88
But, DFAs and NFAs are equivalent in their power to capture langauges !!

Differences: DFA vs. NFA


 DFA  NFA
1. All transitions are 1. Some transitions could be
deterministic non-deterministic
 Each transition leads to  A transition could lead to a
exactly one state subset of states
2. For each state, transition on 2. Not all symbol transitions
all possible symbols need to be defined explicitly (if
(alphabet) should be defined undefined will go to an error
3. Accepts input if the last state state – this is just a design
visited is in F convenience, not to be
confused with “non-
4. Sometimes harder to determinism”)
construct because of the
number of states 3. Accepts input if one of the last
states is in F
5. Practical implementation is
feasible 4. Generally easier than a DFA
to construct
5. Practical implementations
limited but emerging (e.g.,
Micron automata processor)
89
Equivalence of DFA & NFA
 Theorem:
 A language L is accepted by a DFA if and only if it
Should be is accepted by an NFA.
true for
any L  Proof:
1. If part:
 Prove by showing every NFA can be converted to an
equivalent DFA (in the next few slides…)

2. Only-if part is trivial:


 Every DFA is a special case of an NFA where each state
has exactly one transition for every input symbol.
Therefore, if L is accepted by a DFA, it is accepted by a
corresponding NFA.
90
Proof for the if-part
 If-part: A language L is accepted by a DFA if it
is accepted by an NFA
 rephrasing…
 Given any NFA N, we can construct a DFA D
such that L(N)=L(D)
 How to convert an NFA into a DFA?
 Observation: In an NFA, each transition maps to a
subset of states
 Idea: Represent:
each “subset of NFA_states”  a single “DFA_state”

Subset construction 91
NFA to DFA by subset construction
 Let N = {QN,∑,δN,q0,FN}
 Goal: Build D={QD,∑,δD,{q0},FD} s.t.
L(D)=L(N)
 Construction:
1. QD= all subsets of QN (i.e., power set)
2. FD=set of subsets S of QN s.t. S∩FN≠Φ
3. δD: for each subset S of QN and for each input symbol
a in ∑:
 δD(S,a) = Up δinNs(p,a)

92
Idea: To avoid enumerating all of
power set, do
“lazy creation of states”

NFA to DFA construction: Example


 L = {w | w ends in 01} 1 0
NFA: DFA: 0 1
0,1 [q0] [q0,q1] [q0,q2]
0
0 1 1
q0 q1 q2

δD 0 1 δD 0 1
δN 0 1
Ø Ø Ø [q0] [q0,q1] [q0]
q0 {q0,q1} {q0}
[q0] {q0,q1} {q0} [q0,q1] [q0,q1] [q0,q2]
q1 Ø {q2}
[q1] Ø {q2} *[q0,q2] [q0,q1] [q0]
*q2 Ø Ø *[q2] Ø Ø
[q0,q1] {q0,q1} {q0,q2}
*[q0,q2] {q0,q1} {q0} 0. Enumerate all possible subsets
*[q1,q2] Ø {q2} 1. Determine transitions
*[q0,q1,q2] {q0,q1} {q0,q2}
2. Retain only those states
reachable from {q0}
93
NFA to DFA: Repeating the example
using LAZY CREATION
 L = {w | w ends in 01} 1 0
NFA: DFA:
0,1 0 1
[q0] [q0,q1] [q0,q2]
0
0 1 1
q0 q1 q2

δN 0 1 δD 0 1
q0 {q0,q1} {q0} [q0] [q0,q1] [q0]
q1 Ø {q2} [q0,q1] [q0,q1] [q0,q2]
*q2 Ø Ø *[q0,q2] [q0,q1] [q0]

Main Idea:
Introduce states as you go
(on a need basis) 94
Correctness of subset construction
Theorem: If D is the DFA constructed from
NFA N by subset construction, then
L(D)=L(N)
 Proof:

 Show that δD({q0},w) ≡ δN(q0,w} , for all w


 Using induction on w’s length:
 Let w = xa
 δD({q0},xa) ≡ δD( δN(q0,x}, a ) ≡ δN(q0,w}

95
Applications
 Text indexing
 inverted indexing
 For each unique word in the database, store all
locations that contain it using an NFA or a DFA
 Find pattern P in text T
 Example: Google querying
 Extensions of this idea:
 PATRICIA tree, suffix tree

96
A few subtle properties of
DFAs and NFAs
 The machine never really terminates.
 It is always waiting for the next input symbol or making

transitions.
 The machine decides when to consume the next symbol from
the input and when to ignore it.
 (but the machine can never skip a symbol)

 => A transition can happen even without really consuming an


input symbol (think of consuming  as a free token) – if this
happens, then it becomes an -NFA (see next few slides).
 A single transition cannot consume more than one (non-)
symbol.

97
FA with -Transitions
 We can allow explicit -transitions in finite
automata
 i.e., a transition from one state to another state
without consuming any additional input symbol
 Explicit -transitions between different states
introduce non-determinism.
 Makes it easier sometimes to construct NFAs
Definition:  -NFAs are those NFAs with at
least one explicit -transition defined.
  -NFAs have one more column in their

transition table
98
Example of an -NFA
L = {w | w is empty, or if non-empty will end in 01}
0,1

0 1
 -closure of a state q,
q0 q1 q2 ECLOSE(q), is the set

of all states (including
start q’0 itself) that can be
reached from q by
δE 0 1
 repeatedly making an
*q’0 Ø Ø {q’0,q0}
ECLOSE(q’0) arbitrary number of -
q0 {q0,q1} {q0} {q0} ECLOSE(q0) transitions.
ECLOSE(q1)
q1 Ø {q2} {q1}
*q2 Ø Ø {q2} ECLOSE(q2) 99
To simulate any transition:
Step 1) Go to all immediate destination states.
Step 2) From there go to all their -closure states as well.

Example of an -NFA
L = {w | w is empty, or if non-empty will end in 01}
0,1
Simulate for w=101:
0 1
q0 q1 q2
 q0’
 
start
q’0
q0’ q0
1 1
q0

δE 0 1 Ø
x 0
ECLOSE(q’0)
*q’0 Ø Ø {q’0,q0} q1
1
q0 {q0,q1} {q0} {q0} ECLOSE(q0)
q2
q1 Ø {q2} {q1}
*q2 Ø Ø {q2} 100
100
To simulate any transition:
Step 1) Go to all immediate destination states.
Step 2) From there go to all their -closure states as well.

Example of another -NFA


0,1 Simulate for w=101:
q0
0
q1
1
q2 ?
  1

start q’0 q3


δE 0 1

*q’0 Ø Ø {q’0,q0,q3}
q0 {q0,q1} {q0} {q0,q3}
q1 Ø {q2} {q1}
*q2 Ø Ø {q2}
q3 Ø {q2} {q3}

101
101
Equivalency of DFA, NFA, -
NFA
 Theorem: A language L is accepted by
some -NFA if and only if L is accepted by
some DFA

 Implication:

DFA ≡ NFA ≡ -NFA
 (all accept Regular Languages)

102
Eliminating -transitions
Let E = {QE,∑,δE,q0,FE} be an -NFA
Goal: To build DFA D={QD,∑,δD,{qD},FD} s.t. L(D)=L(E)
Construction:
1. QD= all reachable subsets of QE factoring in -closures
2. qD = ECLOSE(q0)
3. FD=subsets S in QD s.t. S∩FE≠Φ
4. δD: for each subset S of QE and for each input symbol a∑:

Let R= U δE(p,a) // go to destination states
p in s

δD(S,a) = U ECLOSE(r) // from there, take a union
r in R
of all their -closures

103
Example: -NFA  DFA

L = {w | w is empty, or if non-empty will end in 01}


0,1

0 1
q0 q1 q2

start q’0


δE 0 1 δD 0 1

*q’0 Ø Ø {q’0,q0} *{q’0,q0}

q0 {q0,q1} {q0} {q0} …

q1 Ø {q2} {q1}
*q2 Ø Ø {q2}
104
Example: -NFA  DFA

L = {w | w is empty, or if non-empty will end in 01}


0,1 0
0
0 1 {q0,q1}
q0 q1 q2 0 1 {q0,q2}
 0
1
start start {q’0, q0} 1
q’0 q0 1
ECLOSE union


δE 0 1 δD 0 1

*{q’0,q0} {q0,q1} {q0}


*q’0 Ø Ø {q’0,q0}
{q0,q1} {q0,q1} {q0,q2}
q0 {q0,q1} {q0} {q0}
{q0} {q0,q1} {q0}
q1 Ø {q2} {q1}
*{q0,q2} {q0,q1} {q0}
*q2 Ø Ø {q2}
105
Example (Oct-2017)

 Convert the following -NFA to an


equivalent -free NFA
δ a b 
q0 - - {q1}
*q1 {q1,q2} - -
q2 - {q3} -
q3 - - {q1}

106
Solution

 Steps:
 1. Draw the diagram
 2. find the -close for all the states
 3. Remove the -transitions
 Find -close(state) -> transition w.r.t. input -> -
close(state)
 4. Draw the diagram for the derived new
transitions.
107
Solution
 Draw the diagram and -close for all the states

108
Find -close(state)->transition w.r.t. input->-close(state)

109
-free NFA Transition diagram

110
Summary
 DFA
 Definition

 Transition diagrams & tables

 Regular language
 NFA
 Definition

 Transition diagrams & tables

 DFA vs. NFA


 NFA to DFA conversion using subset construction
 Equivalency of DFA & NFA
 Removal of redundant states and including dead states
 -transitions in NFA
 Pigeon hole principles
 Text searching applications 111
Mealy and Moore Machines

112
Finite Automata

Finite Automata

Finite Automata with Finite Automata without


output output

Mealy Moore DFA NFA -NFA

113
Mealy Machine

 In Mealy machine. the value of output


function is depend
 on the present state and present input.
In mealy machine every transition
 for a particular input symbol has a fixed
output.

114
115
Example

 Given the input string aaabb, the output is


01110.
 In a Mealy machine the output string has
the same number of characters as the
input string has letters.
116
Moore Machine

117
Example

 We indicate the start state by an outside arrow since there is no


room for the usual - sign.

 Given the input string abab, the output sequence is 10010.

 Note that the length of the output string is one longer than the length
of the input string.
118
Example (Oct-2017)

 Design a Moore machine and Mealy machine


that accepts strings over Σ = {0, 1} where, if
the input ends in 001, output a A; if the input
ends in 100 , output a B; else output a C.

119
Solution (Moore Machine)

120
Mealy machine

121
Mealy to Moore
Conversion
 Mealy machine for the 1’s Complement

0/0 1/0

1/1
A B
0/1
1/0
0/0
Mealy Machine
1/1
A B
0/1

0 0

1
A/0 B/1

0 1
Moore Machine

B/0
1

You might also like