Title: Head, Dept' of Computer Science
1A.M. Padma Reddy
Head, Dept. of Computer Science Information
Science
R.N.S Institute of Technology
2What is Finite Automata?
- Study of Abstract machines or computing devices
3ADVANTAGES OF FA
- Checking and design the behavior of the digital
- circuits using software
- Compiler Design (LEX and YACC)
- Designing a software for identifying words,
- phrases and other patterns in large bodies
- of text (such as collection of web pages)
4ADVANTAGES OF FA Theory
- Study the computers without worrying
- about the intricacies of a particular
- architecture
- Study the computers without worrying
- about the limitations imposed by a specific
- hardware
5TYPES OF FA
Deterministic Finite Automata (DFA)
Non Deterministic Finite Automata (NFA)
Non Deterministic Finite Automata with e-moves
(e-NFA)
6Mathematical Concepts
What is A x B?
What is a power set?
7Definitions
What is an alphabet?
An alphabet is a finite non-empty set of symbols
and is denoted by S
S 0,1 S a, b, c
What is a string?
A string is a sequence of symbols from S. For
example 00, 01, 10 and 11. ? - stands for an
empty string
8Definitions
What is a language?
A language over an alphabet S is a set of string
over S. A language can be finite or infinite
For example 00, 01, 10 and 11 L wwR
w ?a,b
9FINITE AUTOMATA
Q q0, q1, q2, q3
The transition table
S a, b
q0 start state
b
a
d
F q3
q0
q1
q2
q1
q0
q3
q2
q3
q0
q3
q2
q1
10Representation of a DFA
d(q0,a) q1
d(q0,b) q2
d(q1,a) q0
b
a
d
d(q1,b) q3
d(q2,a) q3
q0
q1
q2
d(q2,b) q0
q1
q0
q3
d(q3,a) q2
q2
q3
q0
d(q3,b) q1
q3
q2
q1
11What is a DFA?
, q0
)
(
Q
, S
, d
, F
M
Q- Set of finite states
S - Set of input alphabets
d transition from Q x S to Q
q0 start state
F set of final states
12DFA to accept strings of as and bs ending
with abb
a
b
b
q3
q0
q1
q2
q3
13DFA to accept strings of as and bs except
those ending with abb
a
b
b
q3
q0
q1
q2
q3
q3
q0
q1
q2
14DFA to accept strings of as and bs which has
even number of as and bs
a
q0
q0
q1
q0
q1
q1
a
b
b
b
b
a
q2
q2
q3
q2
q3
a
15Non Deterministic Automata
16Definition of NFA
Set of states, i.e.
Input aplhabet, i.e.
Transition function
Initial state
Final states
17NFA vs. DFA
- Difference is in the definition of d
- NFAs and DFAs recognize the same set of
languages - regular languages
- DFAs are faster to execute
- There are no choices to consider
- For a given language, NFA can be simple than DFA
and we can easily construct NFA - DFA can be exponentially larger than NFA
18NFA
Alphabet
19NFA
Alphabet
Two choices
20NFA
Alphabet
Two choices
No transition
No transition
21First Choice
22First Choice
23First Choice
24First Choice
accept
25Second Choice
26Second Choice
27Second Choice
No transition the automaton hangs
28Second Choice
reject
29Observation
An NFA accepts a string if there is a computation
of the NFA that accepts the string
30Example
is accepted by the NFA
31Lambda Transitions
32(No Transcript)
33(No Transcript)
34(read head doesnt move)
35(No Transcript)
36accept
String is accepted
37Language accepted
38Another NFA Example
39(No Transcript)
40(No Transcript)
41(No Transcript)
42accept
43Another String
44(No Transcript)
45(No Transcript)
46(No Transcript)
47(No Transcript)
48(No Transcript)
49(No Transcript)
50accept
51Language accepted
52Another NFA Example
53Language accepted
54Transition Function
55(No Transcript)
56(No Transcript)
57(No Transcript)
58Extended Transition Function
59(No Transcript)
60(No Transcript)
61Formally
It holds
if and only if
there is a walk from to with label
62The Language of an NFA
63 64 65 66 67Formally
- The language accepted by NFA is
- where
(final state)
68 69Equivalence of NFAs and DFAs
70Equivalence of Machines
- For DFAs or NFAs
- Machine is equivalent to machine
- if
-
71Example
NFA
DFA
72- Since
- machines and are equivalent
NFA
DFA
73Equivalence of NFAs and DFAs
Question NFAs DFAs ?
Same power? Accept the same languages?
74Equivalence of NFAs and DFAs
Question NFAs DFAs ?
YES!
Same power? Accept the same languages?
75We will prove
Languages accepted by NFAs
Languages accepted by DFAs
76We will prove
Languages accepted by NFAs
Languages accepted by DFAs
NFAs and DFAs have the same computation power
77Step 1
Languages accepted by NFAs
Languages accepted by DFAs
78Step 1
Languages accepted by NFAs
Languages accepted by DFAs
Proof
Every DFA is also an NFA
79Step 1
Languages accepted by NFAs
Languages accepted by DFAs
Proof
Every DFA is also an NFA
A language accepted by a DFA is also accepted by
an NFA
80Step 2
Languages accepted by NFAs
Languages accepted by DFAs
81Step 2
Languages accepted by NFAs
Languages accepted by DFAs
Any NFA can be converted to an equivalent DFA
Proof
82Step 2
Languages accepted by NFAs
Languages accepted by DFAs
Any NFA can be converted to an equivalent DFA
Proof
A language accepted by an NFA is also accepted by
a DFA
83NFA to DFA
NFA
DFA
84NFA to DFA
NFA
DFA
85NFA to DFA
NFA
DFA
86NFA to DFA
NFA
DFA
87NFA to DFA
NFA
DFA
88NFA to DFA
NFA
DFA
89NFA to DFA
NFA
DFA
90NFA to DFA Remarks
- We are given an NFA
- We want to convert it
- to an equivalent DFA
- With
91- If the NFA has states
- the DFA has states in the powerset
-
92Procedure NFA to DFA
-
- 1. Initial state of NFA
-
- Initial state of DFA
93Example
NFA
DFA
94Procedure NFA to DFA
- 2. For every DFAs state
- Compute in the NFA
-
- Add transition
95Exampe
NFA
DFA
96Procedure NFA to DFA
- Repeat Step 2 for all letters in alphabet,
- until
- no more transitions can be added.
97Example
NFA
DFA
98Procedure NFA to DFA
- 3. For any DFA state
- If some is a final state in the NFA
- Then,
- is a final state in the DFA
-
99Example
NFA
DFA
100Theorem
Take NFA
Apply procedure to obtain DFA
Then and are equivalent
101Finally
We have proven
Languages accepted by NFAs
Languages accepted by DFAs
102We have proven
Languages accepted by NFAs
Languages accepted by DFAs
Regular Languages
103We have proven
Languages accepted by NFAs
Languages accepted by DFAs
Regular Languages
Regular Languages
104How Does Lex Work?
Flex
RE ? NFA NFA ? DFA Optimize DFA
REs for Tokens
DFA Simulation
Character Stream
Token stream (and errors)
105Regular Expression to NFA
- Its possible to construct an NFA from a regular
expression - Thompsons construction algorithm
- Build the NFA inductively
- Define rules for each base RE
- Combine for more complex REs
s
f
E
general machine