CSE322
Formal Languages and
Automation Theory
Lecture #1
Definition
An automaton is defined as a system where energy,
materials and information are transformed, transmitted
and used for performing some functions without direct
participation of man.
Formal Definition
• Finite Automaton (FA)
FqQM ,,,,
0
• Finite Automaton (FA)
FqQM ,,,,
0
Q
0
q
F
: set of states
: input alphabet
: transition function
: initial state
: set of accepting states
• There are ________ tuples in finite state
machine.
a) 4
b) 5
c) 6
d) unlimited
DESCRIPTION OF A FINITE AUTOMATON
•Transition function maps.
a) Σ * Q -> Σ
b) Q * Q -> Σ
c) Σ * Σ -> Q
d) Q * Σ -> Q
•The transition function which maps Q x ∑*
into Q (i.e. maps a state and a string of
input symbols including the empty string
into a state) is called the indirect
transition function.
Transition System
•110011
•110110
Extended transition function is .
a) Q * Σ* -> Q
b) Q * Σ -> Q
c) Q* * Σ* -> Σ
d) Q * Σ -> Σ
110101
•Check for the 101101
•11111
•000000
•Find input sequence not accepted by M.
0
q
1
q
2
q
3
q
4
qa b b a
5
q
aa bb
ba,
ba,
ba,
Input alphabet
0
q
1
q
2
q
3
q
4
qa b b a
5
q
aa bb
ba,
543210
,,,,, qqqqqqQ
ba,
Set of States
1
q
2
q
3
q
4
qa b b a
5
q
aa bb
ba,
ba,
0
q
Initial State
Set of Accepting States
F
0
q
1
q
2
q
3
qa b b a
5
q
aa bb
ba,
4
qF
ba,
4
q
Accepting State
•Which of the following is not a part of 5-
tuple finite automata?
a) Input alphabet
b) Transition function
c) Initial State
d) Output Alphabet
Deterministic
Finite Automata
DFA
•FA and DFA are both abbreviations for finite
automata, but DFA stands for deterministic
finite automaton.
•A Deterministic Finite Automaton (DFA) is a
mathematical model of computation used to
recognize patterns within input strings. It's a
finite state machine where each input symbol
determines a unique transition from one state to
another.
Formal Definition
FqQM ,,,,
0
FqQM ,,,,
0
Q
0
q
F
: set of states
: input alphabet
: transition function
: initial state
: set of accepting states
How DFA works
•A DFA processes an input string one symbol
at a time.
•Starting from the start state, it moves to
the next state based on the current state
and the input symbol.
•The process continues until the end of the
input string is reached.
•If the final state is an accept state, the
string is accepted; otherwise, it is
rejected.
Rules of DFA:
•Deterministic Nature: For each state and each symbol in the
input alphabet, there is exactly one transition to a new state.
This ensures that the DFA's behavior is fully determined by
its current state and the current input symbol.
•Single Start State: The DFA must have one and only one
start state.
•Unique Transition: There is exactly one transition for each
symbol in the alphabet from each state. Formally, for any
state q Qq \in Qq Q and any symbol a Σa \in Σa Σ,
∈ ∈ ∈ ∈
there is exactly one state p Qp \in Qp Q such that
∈ ∈
δ(q,a)=pδ(q, a) = pδ(q,a)=p.
•Acceptance: A string is accepted by the DFA if, after
processing all input symbols, the DFA ends in one of the
accepting states.
Example
•Let's consider a DFA that accepts strings
ending with 'ab'.
Example 2
•DFA accepting strings that end with '11‘
•Alphabet: {0, 1}
•States: {q0, q1, q2}
•Start state: q0
•Accept states: {q2}
Example 4:
•Construct a DFA that either starts with aa
or with bb from input (a,b).
•Designing DFA Step-by-Step:
•Step-1: Take initial state qo, and smallest
possible string are aa and bb if qo takes ‘a’
as the first input alphabet it goes to
state q1 and if qo takes ‘b’ as the first
input alphabet it goes to state q3.
•Step-2: Now think about state q1, if it takes
input alphabet ‘b’, it breaks our condition of ‘aa’
but if takes input alphabet ‘a’ it makes an
acceptable string, and now it goes to
state q2 which is set to the final state.
•Step-3: On state q3 if it takes input alphabet ‘a’,
it breaks our condition of ‘bb’ but if takes input
alphabet ‘b’ it makes an acceptable string, and
now it goes to state q2 which is set to the final
state.
•Step-4: If input alphabet ‘a’ of state q3 breaks
the condition and Input alphabet ‘b’ of
state q1 breaks the condition so they go to some
dead state(D).
•Step-5: Till now, our machine accepts strings that
starts from ‘aa’ or from ‘bb’ but we also have to
take care of all the symbols after the string has
begun from ‘aa’ or ‘bb’ and hence we introduce
ourselves loops in q2(final state) and D(dead
state).
Applications of DFA
•DFAs have various applications in computer
science, including:
•Lexical analysis: Breaking text into tokens
for compilers and interpreters.
•Pattern matching: Finding specific
patterns within text or data.
•Protocol analysis: Validating data packets
in communication protocols.
•Text search algorithms: Implementing
basic search functionalities.
Non-Deterministic
Finite Automata
1
q
2
q
3q
a
a
a
0q
}{aAlphabet =
Nondeterministic Finite Automaton
1
q
2
q
3q
a
a
a
0q
Two choices
}{aAlphabet =
No transition
1
q
2
q
3q
a
a
a
0q
Two choices
No transition
}{aAlphabet =
a a
0q
1
q
2
q
3q
a
a
First Choice
a
a a
0q
1
q
2
q
3q
a
a
a
First Choice
aa
0q
1
q
2
q
3q
a
a
First Choice
a
aa
0q
1
q
2
q
3q
a
a
a
“accept”
First Choice
All input is consumed
a a
0q
1
q
2
q
3q
a
a
Second Choice
a
a a
0q
1
q
2
q
a
a
Second Choice
a
3q
a a
0q
1
q
2
q
a
a
a
3q
Second Choice
No transition:
the automaton hangs
a a
0q
1
q
2
q
a
a
a
3q
Second Choice
“reject”
Input cannot be consumed
An NFA accepts a string:
when there is a computation of the
NFA that accepts the string
all the input is consumed and the automaton
is in an accepting state
There is a computation:
Example
aais accepted by the NFA:
0q
1q
2q
3q
a
a
a
“accept”
0
q
1q
2q
a
a
a
3
q
“reject”
because this
computation
accepts aa
a
0q
1
q
2
q
3q
a
a
Rejection example
a
a
0q
1
q
2
q
3q
a
a
a
First Choice
a
0q
1
q
2
q
3q
a
a
a
First Choice
“reject”
Second Choice
a
0q
1
q
2
q
3q
a
a
a
Second Choice
a
0q
1
q
2
q
a
a
a
3q
Second Choice
a
0q
1
q
2
q
a
a
a
3q“reject”
Which of the following not an
example Bounded
Information?
a) fan switch outputs {on, off}
b) electricity meter reading
c) colour of the traffic light
at the moment
d) none of the mentioned
An NFA rejects a string:
when there is no computation of the
NFA that accepts the string.
• All the input is consumed and the
automaton is in a non final state
• The input cannot be consumed
OR
For each computation:
Example
ais rejected by the NFA:
0
q
1
q
2
q
a
a
a
3
q
“reject”
0
q
1
q
2
q
a
a
a
3q
“reject”
All possible computations lead to rejection
Rejection example
a a
0q
1
q
2
q
3q
a
a
a
a
a a
0q
1
q
2
q
3q
a
a
a
First Choice
a
aa
0q
1
q
2
q
3q
a
a
First Choice
a
a
No transition:
the automaton hangs
aa
0q
1
q
2
q
3q
a
a
a
“reject”
First Choice
a
Input cannot be consumed
a a
0q
1
q
2
q
3q
a
a
Second Choice
a
a
a a
0q
1
q
2
q
a
a
Second Choice
a
3q
a
a a
0q
1
q
2
q
a
a
a
3q
Second Choice
No transition:
the automaton hangs
a
a a
0q
1
q
2
q
a
a
a
3q
Second Choice
“reject”
a
Input cannot be consumed
aaais rejected by the NFA:
0q
1q
2q
3q
a
a
a
“reject”
0
q
1q
2q
a
a
a
3
q
“reject”
All possible computations lead to rejection
1
q
2
q
3q
a
a
a
0q
Language accepted: }{aaL
Lambda Transitions
1
q
3
qa
0
q
2
qa
aa
1
q
3
qa
0
q
2
qa
aa
1
q
3
qa
0
q
2
qa
aa
1
q
3
qa
0
q
2
qa
(read head does not move)
aa
1
q
3
qa
0
q
2
qa
aa
1
q
3
qa
0
q
2
qa
“accept”
String is acceptedaa
all input is consumed
aa
1
q
3
qa
0
q
2
qa
Rejection Example
a
aa
1
q
3
qa
0
q
2
qa
a
aa
1
q
3
qa
0
q
2
qa
(read head doesn’t move)
a
aa
1
q
3
qa
0
q
2
qa
a
No transition:
the automaton hangs
aa
1
q
3
qa
0
q
2
qa
“reject”
String is rejectedaaa
a
Input cannot be consumed
Language accepted: }{aaL
1
q
3
qa
0
q
2
qa
Another NFA Example
0q 1q
2qa b
3
q
ab
0q 1q
2qa b
3
q
0q 2qa b
3
q
ab
1
q
ab
0q 1q a b
3
q
2
q
ab
0q 1q a b
3
q
2
q
“accept”
0q
a b
ab
Another String
ab
1
q
2
q
3
q
0q
a b
abab
1
q
2
q
3
q
0q
a b
abab
1
q
2
q
3
q
0q
a b
abab
1
q
2
q
3
q
0q
a b
abab
1
q
2
q
3
q
0q
a b
abab
1
q
2
q
3
q
0q
a b
abab
1
q
2
q
3
q
abab
0q
a b
1
q
2
q
3
q
“accept”
ab
ababababababL ...,,,
Language accepted
0q 1q
2qa b
3
q
Remarks:
•The symbol never appears on the
input tape
0
q
2
M
0
q
1
M
{}=)M(L
1 }λ{=)M(L
2
•Simple automata:
0
q
2q
1
q
a
a
a
0
q
1
q
a
}{=)(
1
aML
2
M
1
M
}{=)(
2
aML
NFA FA
•NFAs are interesting because we can
express languages easier than FAs
Formal Definition of NFAs
FqQM ,,,,
0
:Q
:
:
0q
:F
Set of states, i.e.
210
,,qqq
:Input aplhabet, i.e.ba,
Transition function
Initial state
Accepting states
•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
*
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
10,* qaq
540 ,,* qqaaq
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
0320 ,,,* qqqabq
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
Formally
wqq
ij
,* : there is a walk from to
with label
i
q
j
q
w
i
q j
q
w
kw
21
1
2
k
i
q j
q
•Which of the following is correct proposition?
Statement 1: Non determinism is a generalization of Determinism.
Statement 2: Every DFA is automatically an NFA
a) Statement 1 is correct because Statement 2 is correct
b) Statement 2 is correct because Statement 2 is correct
c) Statement 2 is false and Statement 1 is false
d) Statement 1 is false because Statement 2 is false
The Language of an NFA
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
540
,,* qqaaq )(MLaa
50
,qqF
F
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
0320
,,,* qqqabq MLab
50
,qqF
F
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
50
,qqF
540
,,* qqabaaq )(MLaaba
F
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
50
,qqF
10
,* qabaq MLaba
F
0
q
5
q
4
q
3
q
2
q
1
q
a
aa
b
}{*aaabML
•NFA, in its name has ’non-deterministic’
because of :
a) The result is undetermined
b) The choice of path is non-deterministic
c) The state to be transited next is non-
deterministic
d) All of the mentioned
Diffrence B/w DFA NFA
DFA NFA
DFA stands for Deterministic Finite
Automata.
NFA stands for Nondeterministic
Finite Automata.
For each symbolic representation of
the alphabet, there is only one state
transition in DFA.
No need to specify how does the NFA
react according to some symbol.
DFA cannot use Empty String
transition.
NFA can use Empty String transition.
DFA can be understood as one machine.NFA can be understood as multiple
little machines computing at the same
time.
In DFA, the next possible state is
distinctly set.
In NFA, each pair of state and input
symbol can have many possible next
states.
DFA is more difficult to construct.NFA is easier to construct.