AT Module 1 -Autosaved-.ppt
AT Module 1 -Autosaved-.ppt
THEORY
FINITE AUTOMATA AND FORMAL
LANGUAGE
Textbook:
Elaine Rich, Automata, Computability and
1.
Languages.(Refer to Problems )
INTRODUCTION TO
FINITE AUTOMATA
• Automata theory: It is the study of abstract machine
or computing devices.
• Abstract machine: Machine which are not
implemented using some formal notations. It is a
conceptual or theoretical model of a computer system
which really does not exists.
• Finite automata: It is the branch of automata
theory.
INTRODUCTION TO
FINITE AUTOMATA
• Finite automata :
It is a mathematical model which is used to study
the abstract machine or computing devices with the
input chosen from Σ (set alphabet).
Finite automata are computing devices that
accept/recognize regular languages and are used to
model operations of many systems we find in
practice.
Their operations can be simulated by a very simple
computer program.
INTRODUCTION TO
FINITE AUTOMATA
• Example: Electric on/off switch
• Consider an electric switch which has only two states
“off” and “on”.
• To start, if it is in off state, then pressing the button
changes it to the on state.
• If it is in on state, then pressing the button changes it
to the off state.
Push
Start
off on
Push
INTRODUCTION TO
FINITE AUTOMATA
? Example : lexical analyzer of compiler
? Job of this automata is to recognize the keyword then.
Start t h n
e
t th the then
INTRODUCTION TO
FINITE AUTOMATA
? Symbols used in FA
Symbols Meaning
A circle is used to represent a state. Here, q0 is
q0 a state of the machine.
Symbols Meaning
An Arrow with label 0 starts and ends in q0.
Indicates the machine in state q0 on reading a
q0 0 0, it remains in same state q0 .Represented as δ
(q0,0)=q0
Symbols Meaning
A circle is used to represent a state. Here, q0 is
q0 a state of the machine.
Symbols Meaning
An Arrow with label 0 starts and ends in q0.
Indicates the machine in state q0 on reading a
q0 0 0, it remains in same state q0 .Represented as δ
(q0,0)=q0
δ(q0,0)=q0
δ(q0,0)=q0
δ(q0,1)=q1
δ(q1,1)=q2
δ(q2,0)=q2
EXTENDED TRANSITION
FUNCTION OF DFA TO STRINGS:
Definition
The Extended Transition function δ* describes
what happens to a state of machine when input is
a string (sequence of symbols).
Let M= (Q, Σ, δ, q0, F) be a FA. The extended
transition function δ*: Q X Σ* to Q is defined
recursively as shown below:
Basis: δ* (q,ε) = q
Induction : let w=xa
δ* (q, w) = δ* (q, xa) =δ(δ* (q, x),a)=p
Extended Transition function of DFA to strings:
The various properties of Extended Transition
function are:
δ* (q,ε) = q
δ* (q, w) = δ* (q, xa) =δ(δ* (q, x),a) where w=xa
δ* (q, w) = δ* (q, ax) = δ*(δ (q, a),x) where w=ax
For Ex:
δ* (q, w) =q
PROBLEMS ON DFA
Define a DFA to accept ( Σ = {a})
1. Empty language L={ Φ}
2. Empty string L= {ε}
3. Exactly one a
4. Zero or more a’s
5. At least one a
6. At most one a
Empty language L={ Φ}
Empty string L= {ε}
Exactly one a
Zero or more a’s
1. At least one a
2. At most one a
DRAW A DFA TO ACCEPT STRINGS OF A’S AND B’S
▪ Starting with ab
▪ Ending with ab
▪ Ending with ab or ba
• L-={w| w Є ababn or aban where n ≥ 0 }
Solution:
▪
Step 1: Identify the start state of DFA: since q0 is the start state of
▪
δ a b
->{0} {1} Φ
{1} Φ {2, 3, 4, 6, 9}
*{2, 3, 4, 6, 9} {3, 4, 5, 6, 8, 9} {3, 4, 6, 7,8, 9}
*{3, 4, 5, 6, 8, 9} {3, 4, 5, 6, 8, 9} {3, 4, 6, 7, 8, 9}
*{3, 4, 6, 7, 8, 9} {3, 4, 5, 6, 8, 9} {3, 4, 6, 7, 8, 9}
MINIMIZING FSMS
((1, a), [2, 4]) ((3, a), [2, 4]) ((5, a), [2, 4]) ((6, a), [1, 3, 5, 6])
((1, b), [2, 4]) ((3, b), [2, 4]) ((5, b), [2, 4]) ((6, b), [1, 3, 5, 6])
((1, a), [2, 4]) ((3, a), [2, 4]) ((5, a), [2, 4])
((1, b), [2, 4]) ((3, b), [2, 4]) ((5, b), [2, 4]) No splitting is required here
Step 3:
((1, a), [2]) ((3, a), [2]) ((5, a), [2])
((1, b), [4]) ((3, b), [4]) ((5, b), [4]) No splitting required here.
MINIMIZE THE GIVEN DFA
MINIMIZE THE GIVEN DFA
SIMULATORS FOR FSMS
▪ Once we have created an FSM to solve a problem, we may
want to simulate its execution.
▪ Simulating Deterministic FSMs
▪ We begin by considering only deterministic FSMs. One
approach is to think of an FSM as the specification for a
simple, table-driven program and then proceed to write the
code.
• Given an FSM M with states K, this approach will
create a program of length = 2 + (|K|.(|∑| + 2)).
• The time required to analyze an input string w is
O(|w| . |∑|).
• The biggest problem with this approach is that we
must generate new code for every FSM that we wish
to run.
SIMULATING NONDETERMINISTIC
FSMS
? Difference between DFA, NFA and ε-NFA
DFA NFA ε-NFA
The DFA is a 5-tuple The NFA is a 5-tuple The ε-NFA is a 5-tuple
M= (Q, Σ, δ, q0, F) M= (Q, Σ, δ, q0, F) M= (Q, Σ, δ, q0, F)
Where Where Where
Q is set of finite states.
• Q is set of finite states.
• Q is set of finite states.
•
δ :Q x Σ to Q
• δ :Q x Σ to 2Q
• δ :Q x (Σᴜε ) to 2Q
•
There can be zero or one There can be zero, one or There can be zero, one or
transition from a state on more transition from a state more transition from a state
an input symbol. on an input symbol. with or without giving input
.
More number of transitions. Less number of transitions. Relatively more transitions
when compared with NFA
δ :Q x Σ to Q
• δ :Q x Σ to 2Q
• δ :Q x (Σᴜε ) to 2Q
•
There can be zero or one There can be zero, one or There can be zero, one or
transition from a state on an more transition from a state more transition from a state
input symbol. on an input symbol. with or without giving input