Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

Finite State Automata,

Deterministic Finite Automata,

Transition Function
Finite Automata Theory
& Formal Languages
(Content for this lecture is also taken from J. Ullman’s slides)
Khawaja 2023 Automata Theory & Languages 1
Finite State Automata

Khawaja 2023 Automata Theory & Languages 2


FSA - Informal Explanation
• Finite State Automata is also called Finite State Machines
• Automata is plural of Automaton
• Finite State automata are finite collections of states with
transition rules that take you from one state to another
• FSA is specified to model a machine that operates
automatically on a predetermined sequence of operations
• In our context, automata represents specified kind of
algorithms

Khawaja 2023 Automata Theory & Languages 3


Representing Finite Automata
• Simplest representation is often a graph
– State

– Start State Start

– Final (Accepting) State

– Arc indicates Transition from


one state to another state
i
– Label on arc tells what causes the transition

Khawaja 2023 Automata Theory & Languages 4


First Example of FSA
Example: A language over given Σ
Σ = {0, 1}
L : The set of strings of 0’s and 1’s with two consecutive 1’s.
For example, 01101 ϵ L
Similarly 1111 ϵ L since it has two consecutive 1’s.
On the other hand, 1010010 does not belong to L.

• Start scanning the string from its left end.


• Go over the string one symbol at a time.
• Will have the answer when reached the end of the string.

Khawaja 2023 Automata Theory & Languages 5


First Example of FSA (ctd)
Σ = {0, 1}
L : The set of strings of 0’s and 1’s with two consecutive 1’s.

0 0, 1
0

Start 1 1
q0 q1 q2

Final state

q0 = seen no 1
q1 = seen one 1
q2 = seen two consecutive 1’s
Khawaja 2023 Automata Theory & Languages 6
Second Example of FSA
Example: A language over given Σ
Σ = {0, 1}
L : { x ϵ {0, 1}* | x has even number of 0's}
For example, 0101100 ϵ L
Similarly 1111 ϵ L since it has zero (even) number of 0's.
On the other hand, 1011011000 does not belong to L.

• Start scanning the string from its left end.


• Go over the string one symbol at a time.
• Will have the answer when reached the end of the string.

Khawaja 2023 Automata Theory & Languages 7


Second Example of FSA (ctd)
Σ = {0, 1}
L : { x ϵ {0, 1}* | x has even number of 0's}

q0 = seen even 0’s 1 0 1


q1 = seen odd 0’s

q0 q1

Start Final state


0

Khawaja 2023 Automata Theory & Languages 8


Third Example: Recognizing Strings Ending in
“ing”

Not i or g

Not i
Not i or n i

No
Saw “i” Saw “in” Saw “ing”
progress i n g

i
Start i

Not i

Try different input strings to see how it works, ex: ring, rang, rings, ringing

Khawaja 2023 Automata Theory & Languages 9


Deterministic Finite Automata

Khawaja 2023 Automata Theory & Languages 10


Deterministic Finite Automata - DFA
• There are two classes of FSA:
1. Deterministic Finite Automata (DFA)
2. Non-deterministic Finite Automata (NFA)
• The Deterministic finite automaton is the one that is in a single state
after reading any sequence of inputs.
• The term "deterministic" refers to the fact that on each input there is
one and only one state to which the automaton can transition from
its current state.
• In contrast "nondeterministic" finite automata can be in several states
at once.
Khawaja 2023 Automata Theory & Languages 11
Formal Definition of a DFA
Now we can say that a DFA consists of:
1. A finite set of States Q
The two states in our example are q0 and q1.
2. Input Alphabet Σ
3. A Start State (one of the states in Q. In our example it is q 0)
4. A set of Final or Accepting States F
A string ending in one of these states means the string is in the
Language.
5. Transition Function (delta) δ(q, a) = p
(explanation on next slide)

Khawaja 2023 Automata Theory & Languages 12


Formal Definition of a DFA (ctd)
Transition Function δ(q, a) = p
• Transition function takes as arguments a state and an input symbol and
returns a state.
• In our informal graph representation of automata, δ was represented by
arcs between states and the labels on the arcs.
• If q is a state and a is an input symbol then δ(q, a) is that state p such
that there is an arc labeled a from q to p.
• For example in this figure, δ(q0, 0) = q1
δ(q1, 1) = q1
if q is q0 and a is 0,
then p is q1

Khawaja 2023 Automata Theory & Languages 13


Formal Definition of a DFA (ctd)
• Therefore, we can represent a DFA in the form of a five-tuple
notation:
A = (Q, Σ, δ, q0, F)
Where,
A is the name of the DFA
Q is its set of states
Σ is its set of input symbols (alphabet)
δ is its transition function
q0 is its start state
F is its set of accepting states
Khawaja 2023 Automata Theory & Languages 14
Processing Strings using DFA
• The language of the DFA is the set of all strings that the DFA accepts.
• Suppose a1 a2 a3 … an is a sequence of input symbols
• We start out with the DFA in its start state q0
• Using transition function δ,
δ(q0, a1) = q1 the state that the DFA A enters after processing the first input
symbol a1
• Similarly, δ(q1, a2) = q2
• Using the same, we find the states q1 q2 q3 … qn
• Such that δ(qi-1, ai) = qi for each i
• If qn is a member of F, then the input a1 a2 a3 … an is accepted, and if not then
it is rejected.
Khawaja 2023 Automata Theory & Languages 15
Example: Processing Strings using DFA
• We can formally specify a DFA that accepts all and only the strings of 0s
and 1s that have the sequence 01 somewhere in the string.
• We can write this language L as:
{ w | w is of the form x01y for some string x and y consisting of 0's and 1's only }
• Or we can write the same language as:
{ x01y | x and y are any string of 0's and 1's }
• Examples of strings in the language include 01, 11010, 100011 etc.
• Examples of strings not in the language include ε, 0, 111000 etc.

Khawaja 2023 Automata Theory & Languages 16


Example: Processing Strings using DFA (ctd)
To decide whether 01 is a substring of the input, DFA A needs to remember
following:
1. If it has not seen 01 yet, and its last input was either non existent (it just started) or it last saw
a 1? In this case, it cannot accept until it first sees a 0 and then sees a 1 immediately after.
2. If it has not seen 01 yet, but its most recent input symbol was 0. So if it now sees a 1, it will
have seen 01. If it sees a 0, it will stay in the same state to wait for 1 to accept the string.
3. If it has already seen 01. In this case, it accepts every sequence of further inputs i.e., it will
only be in accepting state from now on.

These three conditions above can each be represented by using transition


function:
4. δ(q0, 1) = q0 , δ(q0, 0) = q1
5. δ(q1, 1) = q2 , δ(q1, 0) = q1
6. δ(q2, 0) = q2 , δ(q2, 1) = q2

Khawaja 2023 Automata Theory & Languages 17


Example: Processing Strings using DFA (ctd)
The complete specification will be:
A = ( { q0, q1, q2 }, {0, 1}, δ, q0, { q2 } )

1. δ(q0, 1) = q0 , δ(q0, 0) = q1
2. δ(q1, 1) = q2 , δ(q1, 0) = q1
3. δ(q2, 0) = q2 , δ(q2, 1) = q2

Khawaja 2023 Automata Theory & Languages 18


Simpler Notations for DFAs
• There are two preferred notations for describing DFA:
1. Transition Diagrams:
The graphs that we saw earlier
2. Transition Tables:
A tabular listing of the δ function
(set of states, input alphabet and resulting states)

Khawaja 2023 Automata Theory & Languages 19


Transition Diagram
• Below is the transition diagram for the last example, with:
– all the states, including the start state and the final state
– the inputs
1. δ(q0, 1) = q0 , δ(q0, 0) = q1
– the transition arcs 2. δ(q , 1) = q , δ(q , 0) = q
1 2 1 1
3. δ(q2, 0) = q2 , δ(q2, 1) = q2

Khawaja 2023 Automata Theory & Languages 20


Transition Table
• Below is the transition table for the last example, with:
– rows for the states and columns for the inputs
– The entry for the row corresponding to state q and the column
corresponding to input a is the state δ(q, a)

Khawaja 2023 Automata Theory & Languages 21


Exercise 1
Design the DFA for the following language:
L = { w ϵ {0, 1}* | w starts with 01 }
Draw the transition diagram, the transition table and write down the transition
function values for each state and each input symbol:
δ(q, a) = p
0 1 δ(q0, 0) = q1
Start 0 1
q0 q1 q2 δ(q0, 1) = q3
 q0 q1 q3
q1 q3 q2
δ(q1, 0) = q3
1 0
δ(q1, 1) = q2
q3 0, 1 * q2 q2 q2
δ(q2, 0) = q2
q3 q3 q3 δ(q2, 1) = q2
0, 1
δ(q3, 0) = q3
δ(q3, 1) = q3
Khawaja 2023 Automata Theory & Languages 22
Exercise 2
Design the DFA for the following language:
L = { w | w has both an even number of 0’s and an even number of 1’s }
Draw the transition diagram, the transition table and write down the transition
function values for each state and each input symbol:

δ(q, a) = p
δ(q0, 0) = q2
δ(q0, 1) = q1
δ(q1, 0) = q3
δ(q1, 1) = q0
δ(q2, 0) = q0
δ(q2, 1) = q3
δ(q3, 0) = q1
δ(q3, 1) = q2
Khawaja 2023 Automata Theory & Languages 23
Regular Languages
and
Nonregular Languages

Khawaja 2023 Automata Theory & Languages 24


Regular Languages
• A language L is regular if it is the language accepted by some
DFA.
– Note: the DFA must accept only the strings in L, no others.
• Some languages are not regular.
– For example, DFAs (regular languages) “cannot count” to arbitrarily
high integers.

Khawaja 2023 Automata Theory & Languages 25


Example: A Non-regular Language
L1 = {0n1n | n ≥ 1}
• Note: ai is conventional for i a’s.
– Thus, 04 = 0000
• Read: “The set of strings consisting of n 0’s followed by n 1’s,
such that n is at least 1.”
• Thus, L1 = {01, 0011, 000111, …}
• Why is this a non-regular language?

Khawaja 2023 Automata Theory & Languages 26


Another Example of Nonregular Language

L2 = {w | w in {(, )}* and w is balanced }


– Note: alphabet consists of the parenthesis symbols ’(’ and ’)’.
– Balanced parenthesis are those that can appear in an
arithmetic expression.
• E.g.: (), ()(), (()), (()()), …

Why is this a non-regular language?

Khawaja 2023 Automata Theory & Languages 27


Exercise 3
Draw the transition diagram of DFA for the following language:
L = { w ϵ {a, b}* | |w| >= 2 }

Khawaja 2023 Automata Theory & Languages 28


Exercise 4
Draw the transition diagram of DFA for the following language:
L = { w ϵ {a, b}* | |w| <= 2 }

Khawaja 2023 Automata Theory & Languages 29


Exercise 5
Draw the transition diagram of DFA for strings not ending in “ing” (lower case letters
only):

Khawaja 2023 Automata Theory & Languages 30

You might also like