Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 40

Introduction to Finite Automata:

DFAs and NFAs

Rahul Banerjee
Computer Science and Information Systems Group,
Birla Institute of Technology & Science, Pilani (India)
Home: http://www.bits-pilani.ac.in/~rahul/
E-mail: rahul@bits-pilani.ac.in

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 1


Finite Automata
A ‘Finite Automaton’ has a set of ‘States’, a set of
‘State Variables’ (sometimes called ‘Control
Variables’ or merely ‘Controls’), one or more
‘External Stimulus’ (sometimes called ‘Inputs’).
A Finite Automaton may be ‘Deterministic’ or ‘Non-
Deterministic’:
• Deterministic Automaton means that the machine
cannot be in more state than one at any point of time.
• Non-Deterministic Automaton means that the machine
can be in two or more states at any point of time.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 2


Importance of Non-Deterministic
Finite Automata
Substantial improvement in efficiency (in terms of
Description of an application if an NDFA automaton is
used) becomes possible.
Consequently, it becomes possible to represent
program-based solutions to the application-problems
using any High Level Language.
Once such a situation so warrants, it becomes
possible to subsequently ‘Compile’ this ‘Non-
Deterministic Finite Automaton’ by an appropriate
‘algorithm’ such that subsequently it could be
executed on a Deterministic Finite Automaton that
could finally be mapped onto an actual ‘Physical
Computing System’ (i.e. a conventional Computer).
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 3
Next Logical Step: Adding Spontaneous State
Transition Capability
Naturally, the next logical step would be to
making the Non-Deterministic Finite
Automaton such that the system provides a
choice of :
Making transition from one state to another
effortlessly spontaneous by even an “Empty or
Null String” as its ‘Input’.
Accepting only one or more ‘Regular Languages’.
IT is important to recollect that Regular
Expressions have their equivalent Automata.
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 4
Summary of the Characteristics of the
Non-Deterministic Finite Automata
The term ‘Non-Deterministic’ refers to the fact that the
automaton may be in one or more (several) ‘State(s)’ at any
point point of time.
Non-Determinism has a problem associated with it: “It does
not allow defining any ‘Language’ that cannot be defined by
its ‘Deterministic’ counterpart.”
If there is still anything that makes it preferable, it is the
substantial efficiency that it makes possible in describing an
application.
Thus, it permits the evolution of a ‘programmed solution’ to
appropriate problems using High-Level Languages.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 5


Examples of Situations and Defining the
Ground Rules for Them…
The Digital Signature Example
The SET Example
The E-Cash Example
The All-E-Examination Example
The E-Recruitment Example
The E-Management Example

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 6


Deriving Protocols from the Ground
Rules
Derivation of Protocols
Evaluating their Correctness
Evaluating their Efficiency
Evaluating their Implementability
Evaluating their Robustness
Evaluating their Extensibility

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 7


The Digital-Certificate-based E-
Transaction DFA
Consider a simple case wherein there are
four elements; each one of these being
possible to be represented as an individual
Automaton:
1. Customer
2. E-retail Chain
3. E-Bank
4. Certificate Authority Chain

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 8


The Digital-Certificate-based E-
Transaction
Notations used:
DFA …
Sr.No. Entity Symbol
1 A Finite Set of States Q (initial state: qo)

2 An Initial State qo

3 A Finite Set of Input Symbols ∑ (a is a member)

4 A Transition Function δ (has q and a as parameters)

5
A DFA may be therefore A Set ofas
represented Final States
a five-tuple: F (F is a subset of Q)
A = (Q, ∑ , δ, qo ,F)

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 9


Steps Involved in Evolution of the Finite
Automata
Step-1: Identification of States
Step-2: Identification of Initial State
Step-3: Identification of State Descriptors
Step-4: Description of States
Step-5: Identification of Relevant Actions
Step-6: Identification of Input-Set
Step-7: Identification of Reachable Final States
Step-8: Evolving the Individual Automaton
Step-9: Evolving the Integrated Automata

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 10


Step-1: Identification of States
States for Customer
initial,post-selection,post-review,post-pay,post-
cancel_payment,post-receipt,post-delay
States for E-Retail Chain
initial,post-order_receipt,post-verify,post-redeem,post-
transfer,post-cancel,post-ship
States for E-Bank
initial,post-verify,post-pay,post-redeem,post-transfer,post-ship
States for CA Chain
initial,post-request,post-handshake,post-verification,post-
encryption,post-issue,post-query,post-response,post-
revocation,post-cancellation,post-reinstatement

All these states are based on assumptions and may therefore


vary from one solution to the other. Items in blue represent
states that may be removed in case of requirement of further
simplification of assumptions!
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 11
Step-2: Identification of Initial State
Initial State for Customer q c0

Initial State for E-Retail Chain (e-Store) qs0


Initial State for E-Bank q b0

Initial State for CA Chain q ca0

Each state, can be, in turn described by using an appropriate set of State
descriptors.

State-Identifier symbols like qo represent states whereas State-Descriptors


are used to describe them.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 12


Step-3: Identification of State Descriptors
Every State may be described in terms of a set of State-Descriptors.
States Descriptors for Customer
current-objective-set,current-preference-set,satisfaction-status,available-
funds,Pending-action-status
States Descriptors for E-Retail Chain
Current-objective-set,Inventory,Customer-history,Redeem-queue,Transfer-
verification-queue,Delivery-queue,Banker-data-set,Cash-Flow-status,Claim-
settlement-queue,Pending-action-status
States Descriptors for E-Bank
Customer-data-set,Pay-request-queue,Redeem-request-queue,Transfer-
queue,Pending-transaction-queue,Investment-and-Liquidity-status,Exchange-Index-
set,Claim-settlement-queue,Pending-action-status
States Descriptors for CA Chain
Certificate-Issue-status,Verification-request-queue,Pending-action-status
In cases, wherein simplicity is the major concern, identification of State Descriptors may be skipped since the basic
Automaton can be evolved even without this step.

However, this step adds to the clarity of the problem-definition and later helps to map the Automaton into a
programmed solution as well.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 13


Step-4: Description of States
Description of States for Customer
Description of States for E-Retail Chain
Description of States for E-Bank
Description of States for CA Chain

Details: As discussed in the class!

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 14


Step-5: Identification of Relevant Actions
Relevant Actions for Customer
start,selection,review,pay,cancel,receipt,delay,redeem,tran
sfer
Relevant Actions for E-Retail Chain
Start,order_receipt,pay,verify,redeem,transfer,cancel,ship
Relevant Actions for E-Bank
Start, verify,pay,redeem,transfer,ship,cancel
Relevant Actions for CA Chain
Start,issue,revoke,respond,cancel,pay,redeem

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 15


Step-6: Identification of Input-Set
Input-set for Customer
Input-set for E-Retail Chain
Input-set for E-Bank
Input-set for CA Chain

Details: As discussed in the class!

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 16


Step-7: Identification of Reachable Final
States
Reachable Final State for Customer
Reachable Final State for E-Retail Chain
Reachable Final State for E-Bank
Reachable Final State for CA Chain

Details: As discussed in the class!

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 17


Step-8: Evolving the Individual Automaton
Individual Automaton for Customer
Individual Automaton for E-Retail Chain
Individual Automaton for E-Bank
Individual Automaton for CA Chain

Details: As discussed in the class!

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 18


Step-9: Evolving the Integrated Automata

As discussed in the class!


Too big a diagram to fit into a single
slide!

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 19


δ (qn-1 ,an)

Exactly how does a DFA process and


accept / reject strings?
Just remember a few basics for understanding
this:
The ‘Language’ of a DFA comprises of the set of
‘acceptable’ strings.
A ‘string’ is a sequence of ‘input symbols’.
If a DFA does ‘remember’ a set of ‘observed’ facts
or inferences about its ‘previous input string(s)’
each of which may be represented in terms of a
‘state’, it shall be able to ‘accept’ or ‘reject’ a given
‘string’ accordingly.
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 20
δ (qn-1 ,an)

Alternative ways of DFA representation


Apart from the ‘five-tuple‘ scheme:
(A = (Q, ∑ , δ, qo ,F)), the DFA may be
represented in certain more ways; including:
A ‘Graph-based representation scheme’ often
called the ‘Transition Diagram’; and,
A ‘Table-based transition-listing scheme’ known
as the ‘Transition Table’.
A point to remember: All DFAs are also NFAs
(with restrictions) but the converse is not
true. However, all NFAs can be converted
into DFAs. More explanation later!
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 21
δ (qn-1 ,an)

The Transition Diagram


For a DFA that may be represented in the form: A = (Q, ∑ , δ, qo ,F), the
Transition Diagram shall look like the one shown below; if in any given case,
the DFA could be described as: A = {(qo, q1, q2, q3), (0,1), δ, qo, (q1, q3)};
wherein, Q=(qo, q1, q2, q3) , ∑=((0,1), (1,0)), and F=(q1, q3) respectively:

1 0 0 0,1
1,0

1 qo q2 q1
q3
Each state is represented by a ‘node’ (represented by a circle) and each ‘pair
of concentric circles’ represents an ‘accepting state’ (i.e. a member of ‘F’).

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 22


The Transition Table
For a DFA that may be represented in the form: A = (Q, ∑ , δ, qo ,F), the
Transition Table shall look like the one shown below; if in any given case, the
DFA could be described as: A = {(qo, q1, q2, q3), (0,1), δ, qo, (q1, q3)}; wherein,
Q=(qo, q1, q2, q3) , ∑=((0,1), (1,0)), and F=(q1, q3) respectively:

δ (qn-1 ,an)
Current State | Inputs
0 1
qo q2 qo

q1 q1 q1

q2 q1 q3

q3 q3 q3
In Transition Table, ‘states’ are represented in rows and ‘inputs’ are shown in
columns. Here, arrow shows the ‘start’ state and asterisk shows the
‘accepting’ state(s).

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 23


^
The Extended Transition Function δ
The basic Transition Function δ(qn-1 ,an) needs to be
extended if we have to define a DFA more precisely.
It is a function that must take a state qn-1 and a string wn ;
and, output a state pn. Here, the resultant state is a state
that the DFA attains as a result of this transition:
^
δ (qn-1 , wn) = pn
^
The extended Transition Function δ is defined by induction
on the length of the input string wn.
It may be expressed as:
^
δ (qn, Єn) = qn where, Єn represents ‘no input’; consequently, this
expression implies that in absence of any input, the current state is
retained
^ ^
δ (qn, wn) = δ(δ (qn, xn), an) = δ(pn, an) where, wn is a string of the form
xnan and an is the last symbol of wn.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 24


The DFA Design Steps: A Summary
Following are the simple steps that lead to an simple yet
acceptable DFA-design:
1. Define the ‘Target Language’ (L(A)) in an unambiguous manner.
2. Identify the Set of Input Symbols, Sets of Input and Final States, the Transition
Function (both; basic and the extended) and its parameters, Initial State.
3. Identify the individual states attainable in the given case.
4. Build the DFA through any one of the representation schemes (most popular
being the Transition Diagram and Transition Table schemes).
5. Verify the ‘State-Reachability’ and ‘State-Description’ details.
6. Try using this design for its workability with respect to the ‘Target Language’ for
sample cases and ensure that it succeeds.
7. Eliminate redundancies, if any.
8. Continue to repeat Steps 5-8 until no further refinement becomes attainable.
Note: Steps 6 and 7 need not apply to the Transition-Table-based representation of
the DFA.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 25


Modeling A Simple DFA
A simple DFA that recognizes the strings ‘PLCC’, ‘CS’, ‘CSC362’ and
‘CSIS’ would look like:
Start C S I S

C 3 6 2

P L C C

Only two Data Structures ‘a single variable’ (for State Number / ID) and
‘a two-dimensional Array’ (for the Transition Function) are adequate for
modeling this Finite State Machine (FSM).
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 26
The Non-deterministic Finite
Automaton (NFA) and Its Use
The term NFA and its basic significance have been discussed in slides 3-5.
This slide attempts to expand with that backdrop.
Salient Features of NFA:
• Non-determinism yet finiteness of the automaton,
• Ability to ‘predict’ / ‘guess’ its ‘input’ in a certain sense,
• Ease of mapping onto the High-Level Language constructs,
• Capability to ‘accept’ the ‘Regular languages’ (just like the DFA
does so!);
• The single reason that forms the basis for all other features is the
NFA’s capability to be in several states at any given point of time.
• NFAs are easier to design than the DFAs.
• NFA-to-DFA conversion is always possible, though at times, it may
not be necessarily simple.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 27


The NFA Representation
Notations used:
Sr.No. Entity Symbol
1 A Finite Set of States Q (initial state: qo)

2 An Initial State qo

3 A Finite Set of Input Symbols ∑ (a is a member)

4 A Transition Function δ (has q and a as parameters)

5 A Set of Final States F (F is a subset of Q)

An NFA may be, therefore, represented as a five-tuple, just like the DFA:
A = (Q, ∑ , δ, qo ,F)
The primary difference between the NFA and DFA lies here in the
‘type of the value’ returned by the Transition Function δ.
δ, in case of an NFA, returns a ‘set of states’ instead of a ‘single state’.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 28


^
The Extended NFA Transition Function δ
The basic Transition Function δ(qn-1 ,an) needs to be extended if
we have to define an NFA more precisely.
It is a function that must take a state qn-1 and a string wn ; and,
output a set of states {pn}. Here, the resultant set of states is a
set of states that the NFA attains as a result of this transition:
^
δ (qn-1 , wn) = {pn}
^
The extended Transition Function δ is defined by induction on
the length of the input string wn.
It may be expressed as:
^
δ (qn, Єn) = {qn} where, Єn represents ‘no input’;
consequently, this expression implies that in absence of any input,
the current set of states is retained
^ ^
δ (qn, wn) = δ(δ (qn, xn), an) = δ({pn }, an) where, wn is a string of the
form xnan and an is the last symbol of wn.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 29


Representing the Language of an NFA
‘Target Language’ is denoted as (L(A)), exactly
as in the case of the DFA.
If, an NFA be represented by the five-tuple:
A = (Q, ∑ , δ, qo ,F)

Then, its ‘Target Language’ shall be


represented as follows:
^
L(A) = (w | δ (qo, w) ∩ F ≠ 0)
^
Here, the term δ^ (qo, w) shall always have at
the least one ‘accepting state’.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 30


Basics of NFA to DFA Conversion
The ‘Number of States’ factor: In the worst
case, an NFA having ‘n’ states may have to
be represented by a DFA having ‘2n‘ states.
The ‘Subset Construction’ principle: This
important principle is the basis of conversion
of an NFA into an equivalent DFA. This allows
representation of one automaton in term of
states and transitions of another automaton
without having knowledge of other relevant
details of the other automaton.
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 31
Basics of NFA to DFA Conversion ..
The ‘Subset Construction’ principle …
Let us assume that the given NFA is
represented as: An = (Qn, ∑ , δn, {qo}, Fn)
&
the target DFA is represented as:
Ad = (Qd, ∑ , δd, qo, Fd)
Then, the DFA components may be derived
provided that we know a condition like:
L(An) = L(Ad)

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 32


Basics of NFA to DFA Conversion ..
The ‘Subset Construction’ principle …
Now, the remaining DFA components may be derived as follows:
• Qd is the ‘power set of Qn ‘ (this is because, it is the set of all subsets of
the Qn). Therefore, as explained earlier, Qn having ‘N’ states shall have to
be represented by Qd having ‘2N‘ states (including ‘accepting’ / accessible
as well as ‘non-accepting’ / inaccessible states).
• Similarly, Fd is the set of subsets ‘S’ of Qn with the condition:
S ∩ Fn ≠ 0
• Consequently, for S Qn and every a in ∑,

δd (S,a) = U pinS δn (p,a)


This simply means that it needs to be examined that exactly which state
transition takes place upon the input ‘a’ from the current state ‘p’.

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 33


Modeling A Simple NFA and
Converting it into a DFA
A simple NFA that recognizes the strings ‘PLCC’, ‘CS’, ‘CSC362’
and ‘CSIS’ would look like (using Epsilon (ε)Transition
mechanism):0 1 2
C S 4
ε 0 1 2 3
ε
0 0 C 1 S 2 5I 6 S 7 8
ε

ε
C S C 3 6 2
0 9 12
10 11
P L C C
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 34
Modeling … into a DFA
A DFA may be seen as an NFA with two restrictions:
• No state can have an outgoing Epsilon Transition
• Only one outgoing Transition from any state carrying the same Label is
permissible

0 1 2
C S
ε 0 1 2 3 4
ε C S I S
0 ε 0 1 2 5 6 7 8

ε
C S C 3 6 2
0 9 12
10 11
P L C C
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 35
Modeling … into a DFA
Therefore, let us try generating a DFA out of this NFA now!
Step-1: Remove Epsilon Transitions and corresponding states.

1 2
1 2 3 4

0 1 2 5 6 7 8

9 9 10 11

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 36


Modeling … into a DFA
Step-2: Remove More than one instance of states carrying the
same label and Transition Arcs leading to these removed states

1 2 3 4

0 5 6 7 8

9 9 10 11

Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 37


Modeling … into a DFA
Step-3: Connect the states through the relocated Transition Arcs
such that all remaining states are reachable in keeping with the
‘strings’ that need to be recognized.

1 2 3 4

0 5 6 7 8

9 10 11 12
This is your resultant DFA. (Compare it with your Slide No. 26.)
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 38
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 39
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 40

You might also like