Global College Department of Computer Science
Automata and Complexity Theory
Chapter 2:Finite Automata
Bayisa Gutema(MSc)
11/26/2022 Global College 1
Finite Automata
• Finite automata is an abstract computing device.
• It is a mathematical model of a system with discrete:
• inputs,
• outputs
• states and
• set of transitions from state to state that occurs on input symbols from alphabet ∑.
• Finite automata are used to recognize patterns.
• Finite automata have two states, Accept state or Reject state.
• When the input string is processed successfully, and the automata reached its final state, then it will
accept.
11/26/2022 Global College 2
Finite automata can be represented by
• Graphical (Transition diagrams or transition tables)
• Tabular (transition tables)
• Mathematical (Transition function or Mapping function)
11/26/2022 Global College 3
Formal Definition of FA
• A finite automaton is a collection of 5-tuples (Q, ∑, δ, q0, F), where:
• Q is finite set of states
• ∑ is finite set of the input alphabets
• q0 ϵ Q is start state also called initial state
• F is accept state or final state
• δ: Q x ∑ → Q is transition function
11/26/2022 Global College 4
Transition Diagrams
• Transition diagram is a directed graph associated with vertices of the graph
corresponds to the state of finite automata.
11/26/2022 Global College 5
Cont..
• Transition Table is basically a tabular representation, of the transition function that
takes two arguments( a state and a symbol ) and returns a value (next state).
• Rows corresponds to states,
• Columns corresponds to input symbols
• Entries corresponds to next state
• The start state is marked with an arrow (→)
• Accept state are marked with a star(*)
• q1 intermediate state
• q2 is final state
11/26/2022 Global College 6
Cont..
•
11/26/2022 Global College 7
Transition Function
• The mapping function or transition function denoted by δ.
Two parameters are passed to this transition function
1. current state
2. input symbols
• Transition function always returns a state which can be called as next state.
δ(current state, current input symbol) = next state
Example: δ(q0, a) = q1
δ(q0, 1) = q1
11/26/2022 Global College 8
Finite Automata Classification
11/26/2022 Global College 9
Deterministic Finite Automata (DFA
• Finite automata is called deterministic finite automata if the machine read an input string one
symbol at a time.
• Deterministic refers to the uniqueness the computation.
• In DFA, there is only one path for specific input symbol from current state to the next state.
• DFA does not accept the null move.
• DFA cannot change the state without any input character.
• DFA can contains multiple final state.
• DFA is used in lexical analysis in compiler.
11/26/2022 Global College 10
Cont..
a, b
q0 b q1
a
q2
11/26/2022 Global College 11
Formal Definition of DFA
• A DFA is a collection of 5 tuples (same as FA)
Q is finite set of states
∑ is finite set of input symbols
q0 is initial state
F is final state
δ is transition function
• Transition function can be defined as δ : Q x ∑ → Q
11/26/2022 Global College 12
Cont..
• The state is represented by vertices.
• The arc labeled with an input character show the transition
• The initial state is marked with an arrow.
• The final state is denoted by a double circle.
Acceptance of a Language
• A language acceptance is defined by “if a string w is accepted by a machine m”
• If it is reaching the final state F by taking the string w.
• Not accepted if not reaching the final state.
Example
11/26/2022 Global College 13
DFA Example 1
• DFA to accept ‘a’
• DFA to accept zero or more ‘a’
a
• L = { ∑, a, aa, aaa, aaaa, …. }
q0
Note : states depends on the length of the string
11/26/2022 Global College 14
Example 2
• Let DFA be Q = {q0, q1,q2}
∑ = {0, 1}
initial state ={q0}
final state ={q2}
11/26/2022 Global College 15
Example 3
• Example 2: Design DFA with given ∑ = {0,1} that accepts those string which
starts with 1 and ends with 0.
• Solution: minimum length of string is 2.
L = { 10, 100, 1010, 11001100, …. }
Number of states = |minimum length| + 1
=2+1
=3
• DFA Diagram
11/26/2022 Global College 16
Example 4
• Design DFA with given ∑ = {0,1} that accepts even number of 0’s and even
number of 1’s.
• Solution: minimum length of string is 3.
L = { 001, 110, 100, …. }
DFA Diagram
11/26/2022 Global College 17
Example 5
• Construct DFA that accepting all strings over ∑ = {a, b} ending with ab.
• Solution: minimum length of string is 2.
number of states = 2+1 =3
L = {ab, aab, bab, bbab…. }
0
b a
DFA Diagram q0 a b q
q
1 a 2
b
11/26/2022 Global College 18
Non Deterministic Finite Automata (DFA)
• The finite automata are called NFA when there exist many paths for specific input
from the current state to the next state.
• It is easy to construct an NFA than DFA for a given regular language.
• Every NFA is not DFA, but each NFA can be translated into DFA.
• NFA is defined in the same way as DFA but with the following two exceptions:
1. it contains multiple next states, and
2. it contains ε transition.
11/26/2022 Global College 19
In the following image
• we can see that from state q0 for input a, there are two next states q1 and q2
• similarly, from q0 for input b, the next states are q0 and q1.
• Thus it is not fixed or determined that with a particular input where to go next.
• Hence this FA is called non-deterministic finite automata.
11/26/2022 Global College 20
Formal definition of NFA
• NFA also has five tuples same as DFA, but with different transition function, as
shown follows:
• δ: Q x ∑ →2Q
• where,
• Q finite set of States
• ∑ finite set of input symbol
• q0 initial state
• F final state
• δ transition function
11/26/2022 Global College 21
Graphical Representation of an NFA
• An NFA can be represented by digraphs called state diagram. In which:
The state is represented by vertices.
The arc labeled with an input character show the transitions.
The initial state is marked with an arrow.
The final state is denoted by the double circle.
• Example 1: Construct transition diagram of NFA from the below given
information
11/26/2022 Global College 22
Transition Table for the above NFA diagram
• In the above diagram, we can see that when the current state is q0, on input 0,
the next state will be q0 or q1, and on 1 input the next state will be q1.
• When the current state is q1, on input 0 the next state will be q2 and on 1
input, the next state will be q0.
• When the current state is q2, on 0 input the next state is q2, and on 1 input the
next state will be q1 or q2.
11/26/2022 Global College 23
Example 2
• NFA with ∑ = {0, 1} accepts all strings with 01
• Solution
• Transition Table:
Present State Next state for Input 0 Next State of Input 1
→q0 q1 ε
q1 ε q2
*q2 q2 q2
11/26/2022 Global College 24
Example 3
• NFA with ∑ = {0, 1} and accept all string of length at least 2.
• Solution
• Transition Table
11/26/2022 Global College 25
Example 4
• Design a NFA for the transition table as given below:
11/26/2022 Global College 26
Solution
• The transition diagram can be drawn by using the mapping function
as:
11/26/2022 Global College 27
Example 5
• Design an NFA with ∑ = {0, 1} accepts all string ending with 01.
11/26/2022 Global College 28
Example 6
• Construct NFA for set of strings of all that starts with 0 over {0, 1}
Solution:
0,1
q0 0 q1
11/26/2022 Global College 29
NFA Accepting and Rejecting State
• An NFA accepts a string: If there is a computation of the NFA that accepts the
string. i.e., all the input string is processed and the automaton is in an accepting
state
• Example aa is accepted by the NFA
11/26/2022 Global College 30
NFA with ε
• ε is empty symbol( no character to accept)
• Regular NFA with 5 tuples {Q, ∑, q0, F, δ}
where δ : Q x ∑ → 2Q
• ε -NFA with 5 tuples {Q, ∑, q0, F, δ}
where δ : Q x ∑ U ε → 2Q
• Example
• Note: Every state on ε goes to itself
B on seeing nothing, it can got o ‘C’
11/26/2022 Global College 31
Difference between DFA and NFA
11/26/2022 Global College 32