0% found this document useful (0 votes)
83 views43 pages

Unit 2 Introduction To Finite Automata

The document provides an introduction to finite automata, detailing both deterministic (DFA) and non-deterministic (NFA) models, their structures, and transition functions. It highlights applications of finite state machines in various fields such as computer science, networking, and language processing. Additionally, it discusses the equivalence between DFA and NFA, including the concept of ε-transitions in NFAs.

Uploaded by

neupanejasmine0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views43 pages

Unit 2 Introduction To Finite Automata

The document provides an introduction to finite automata, detailing both deterministic (DFA) and non-deterministic (NFA) models, their structures, and transition functions. It highlights applications of finite state machines in various fields such as computer science, networking, and language processing. Additionally, it discusses the equivalence between DFA and NFA, including the concept of ε-transitions in NFAs.

Uploaded by

neupanejasmine0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Finite Automata

State Machine
Machine can be in some state/configuration with some
external events/inputs
State may be same or different.

Switch on
TV TV
on off
Switch off

1
Introduction to Finite Automata
A finite automaton is a mathematical (model) abstract machine that has a set of
“states” and its “control” moves from state to state in response to external “inputs”.
The control may be either “deterministic” meaning that the automation can’t be in
more than one state at any one time, or “non deterministic”, meaning that it may be
in several states at once. This distinguishes the class of automata as DFA or NFA.

a b c d e f
input

q0, q1, q2, Finite


q3, q4, q5….. control

2
Applications

The finite state machines are used in applications in computer science and data
networking. For example, finite-state machines are basis for programs

• for spell checking


• indexing,
• grammar checking,
• searching large bodies of text,
• recognizing speech,
• transforming text using markup languages such as XML & HTML,
• network protocols that specify how computers communicate.
• Traffic light control system
• Vending machine
• Compilers and language processors

3
Deterministic finite state automata [DFSA]
A deterministic finite automaton is defined by a quintuple (5-
tuple) as (Q, Σ, δ, q0, F).
Where,
Q = Finite set of states,
Σ = Finite set of input symbols,
δ = A transition function that maps Q × Σ -> Q
q0 = A start state; q0 ∈ Q
F = Set of final states; F ⊆ Q.

4
General Notations of DFA

There are two preferred notations for describing this class of automata;
1. Transition Table
 0 1
2. Transition Diagram
-> A C B
B C B
C C D
*D D D

5
Extended Transition Function of DFA( 𝛿መ )
The extended transition function of DFA, denoted by 𝛿መ is a transition function that takes two
arguments as input, one is the state q of Q and another is a string w∈ Σ*, and generates a state p ∈ Q.
This state p is that the automaton reaches when starting in state q & processing the sequence of inputs
w.
෡ (q, w) = p
i.e.𝜹
Let us define by induction on length of input string as follows:

Basis step: 𝛿መ (q,є) =q. i.e. from state q, reading no input symbol stays at the same state.

Induction: Let w be a string from Σ* such that w = xa, where x is substring of w without last symbol
and a is the last symbol of w, then
෡ (q, w) = δ (𝜹
𝜹 ෡ (q, x), a).
Thus, to compute 𝛿መ (q, w), we first compute 𝛿መ (q, x), the state the automaton is in after processing
෡ (q, x) = p.
all but last symbol of w. let this state is p, i.e. 𝜹

Then, 𝛿መ (q, w) is what we get by making a transition from state p on input a, the last symbol of w.

i.e. 𝜹 (q, w) = δ (p, a)

6
Extended Transition Function of DFA( 𝛿መ )

Basis step: 𝛿መ (q,є) =q. i.e. from state q, reading no input symbol stays at the same state.
Induction: Let w be a string from Σ* such that w = xa, where x is substring of w without
last symbol and a is the last symbol of w, then
෡ (q, w) = δ (𝜹
𝜹 ෡ (q, x), a).
෡ (q, w) = δ (p, a)
෡ (q, x) = p then 𝜹
let this state is p, i.e. 𝜹
Now compute 𝜹 ෡ (q0,1001)
=(𝛿መ (A,100),1)
= (  ( 𝛿መ (A,10),0),1)
= (  (  ( 𝛿መ (A,1),0),0),1)
=(  (  (  (𝛿መ (A, ),1),0),0),1)
=(  (  (  (𝐴,1),0),0),1) This Photo by Unknown Author is licensed under CC BY-SA
=(  (  (B,0),0),1)
=(  ( C,0),1)
=( C,1)
=D, Which is final state so accepted.

7
Language of DFA
String accepted by a DFA

A string x is accepted by a DFA (Q, Σ, δ, q0, F)


෡ (q, x) = p ∈ F.
if; 𝜹
Language of DFA

The language of DFA M = (Q, Σ, δ, q0, F) denoted by L(M) is a set of strings over
Σ* that are accepted by M.

෡ (q0, w) = p ∈ F}
i.e; L(M) = {w/ 𝜹
That is; the language of a DFA is the set of all strings w that take DFA starting from
start state to one of the accepting states.
The language of DFA is called regular language.

8
Examples

1. Construct a DFA, that accepts all the strings over Σ = {a, b} that do not end
with ba.
2. DFA accepting all string over Σ = {0, 1} ending with 3 consecutive 0’s.
3. DFA over {a, b} accepting {baa, ab, abb}
4. DFA accepting zero or more consecutive 1’s. i.e. L (M) = {1n / n = 0, 1, 2,
……}
5. DFA over {0, 1} accepting {1, 01}
6. DFA over {a, b} that accepts the strings ending with abb.

7. Give the DFA for the language of string over {0.1} in which each string end
with 11.
8. Give the DFA accepting the string over {a,b} such that each string does not end
with ab.
9. Give the DFA for the language of string over {a,b} such that each string contain
aba as substring.
10. Give the DFA for the language of string over {0,1} such that each string start
with 01.
11. The question from book: 2.2.4, 2.2.5 (a,b,c,d)of chapter 2.
9
Non-Deterministic Finite Automata (NFA)
A non-deterministic finite automaton is a mathematical model
that consists of:
Q: A set of states Q, (finite)
Σ :A finite set of input symbols, (alphabets)
δ : A transition function that maps state symbol pair to sets of states.
q0: A state q0 ∈ Q, that is distinguished as a start (initial) state.
F: A set of final states F distinguished as accepting (final) state. F ⊆ Q.

Thus, NFA can also be interpreted by a quintuple; (Q, Σ, δ, q0, F) where δ is


Q × Σ =2Q. Unlike DFA, a transition function in NFA takes the NFA from
one state to several states just with a single input.

10
Transition function δ
δ, the transition function is a function that takes a state in Q and an input symbol
in ∑ as arguments and returns a subset of Q The only difference between an NFA
and DFA is in type of value that δ returns. In NFA, δ returns a set of states and in
case of DFA it returns a single state.

NFA over {0,1} Ending with 11 or 10

δ 0 1
a {a} {a,b}

b {c} {c}

*c {} {}

11
NFA over {0, 1} accepting strings {0, 01, 11}.
0
q0 q
q22

0,1 Computation tree for


q1 1
01
q0
0
0

q1 q2
1 dies

Computation tree for q2


0110 Final , so 01 is accepted
q0
0 0

q1 q2 dies
1

q2 Dies, so 0110 is not accepted


12
The Extended transition function of NFA

As for DFA’s, we need to define the extended transition function 𝛿መ that takes a state q and a string of
input symbol w and returns the set of states that is in if it starts in state q and processes the string w.

Definition by Induction:

Basis Step: 𝛿መ (q, ε) = {q} i.e. reading no input symbol remains into the same state.

Induction: Let w be a string from Σ* such that w = xa, where x is a substring of without last symbol
a.

Also let,
෡ (q, x) = {p1, p2, p3, …pk}
𝜹
And 𝒌

ራ 𝜹 𝒑𝒊, 𝒂 = {r1,r2,r3, …rm}


𝒊=𝟏

Then, ෡ (q, w) = {r1,r2,r3, …rm}


𝜹
Thus, to compute 𝛿መ (q, w) we first compute 𝛿መ (q, x) & then following any transition from each of
these states with input a.

13
The Extended transition function of NFA
Strings ending with 0
෡ (q0,1010)
Computing for 𝜹
෡ (q0,1010)
𝜹

෡ (q0, ) = { q0 }
𝛅
෡ (q0, 1) = (q0, 1) = { q0 }
𝛅
෡ (q0, 10) = (q0, 0)={q0, q1}
𝛅
෡ (q0, 101) = (q0, 1)(q1,1)={q0}
𝛅
෡ (q0, 1010) = (q0, 0) = {q0, q1}
𝛅
Thus, 𝛅෡ (q,1010) = {q0, q1}
The resulting set of state contains the final state hence the
string w=1010 is accepted

14
Examples
1. Construct a NFA over {a, b} that accepts strings having aa as substring.
2. NFA for strings over {0, 1} that contain substring 0110 or 1001
3. NFA over {a, b} that have “a” as one of the last 3 characters.
4. NFA over {a, b} that accepts strings starting with a and ending with b.
5. Design a NFA for the language over {0, 1} that have at least two consecutive
0’s or1’s, compute for acceptance of string 11001

15
Design a NFA for the language over {0, 1} that have at least
two consecutive 0’s or1’s, compute for acceptance of string
11001

16
Language of NFA

The language of NFA, M = (Q, Σ, δ, q0, F), denoted by L (M)


is;
෡ (q, w) ∩ F ≠ φ}
L (M) = {w/ 𝜹

መ 0,w)
i.e. L(M) is the set of strings w in ∑* such that 𝛿(q
contains at least one state accepting state.

17
1. Give a NFA to accept the language of string over{a.b} in which each string
contain abb as substring.
2. Give a NFA which accepts binary strings which have at least one pair of
‘00’ or one pair of ‘11’.

18
Equivalence of NFA & DFA
To convert a NFA, N = (QN, Σ, δN, q0, FN) into an equivalent DFA D =
(QD, Σ, δD, q0, FD), we have following steps.

[Link] start state of D is the set of start states of N i.e. if q0 is start state
of N then D has start state as {q0}.

[Link] is set of subsets of QN i.e. QD = 2QN. So, QD is power set of QN.


So if QN has n states then QD will have 2n states. However, all of these
states may not be accessible from start state of QD so they can be
eliminated. So QD will have less than 2n states.

[Link] is set of subsets S of QN such that S ∩ FN ≠ φ i.e. FD is all sets of


N’s states that include at least one final state of N.

For each set S ⊆ QN & each input a ∈ Σ,


δD (S, a)= ‫𝑝 𝑁𝛿 𝑠 𝑛𝑖 𝑝ڂ‬, 𝑎 .
19
Equivalence of NFA & DFA

20
NFA to DFA

21
NFA to DFA

22
NFA with ε-transition (ε-NFA)

A NFA with ε-transition is defined by five tuples (Q, Σ, δ, q0, F), where;

Q = set of finite states


Σ = set of finite input symbols
q0 = Initial state, q0 ∈ Q
F = set of final states; F ⊆ Q
δ = a transition function that maps;
Q × Σ ∪ {ε}→ 2Q

23
ε-closure of a state

ε-closure of a state ‘q’ can be obtained by following all transitions


out of q that are labeled ε. After we get to another state by following
ε, we follow the ε-transitions out of those states & so on, eventually
finding every state that can be reached from q along any path whose
arcs are all labeled ε.

Formally, we can define ε-closure of the state q as;

Basis: state q is in ε-closure (q).

Induction: If state q is reached with ε-transition from state p, q is in


ε-closure (p). And if there is an arc from p to r labeled ε, then r is in
ε-closure (q) and so on.

24
Extended Transition Function of ε-NFA

The extended transition function of ε-NFA denoted by 𝛿መ ,is defined as;


i) BASIS STEP: - 𝜹 ෡ (q, ε) = ε-closure (q)
ii) INDUCTION STEP: -

Let w = xa be a string, where x is substring of w without last symbol a and a ∈ Σ


but a ≠ ε.

෡ (q, x) = {p1, p2, … pk} i.e. pi’s are the states that can be reached from q
Let 𝜹
following path labeled x which can end with many ε & can have many ε.

Also let,
𝒌

ራ 𝜹 𝒑𝒊, 𝒂
𝒊=𝟏
={r1,r2,….rm} then
𝒎

ራ  − 𝒄𝒍𝒖𝒔𝒖𝒓𝒆 𝒓𝒋
ො (q, w) =
𝜹 𝐣=𝟏
25
Extended Transition Function of ε-NFA
Now compute for string ba
-𝛿መ (p, ε)= ε-closure(p)={p, q, r, u}

Compute for b
- δ(p,b)U δ(q,b)U δ(r,b)U δ(u,b)={s,v}
- ε-closure(s)U ε-closure(v)={s,t,v}

Computer for next input ‘a’


- δ(s,a)U δ(t,a)U δ(v,a)={y,w}
- ε-closure(y)U ε-closure(w)={y,w}

The final result set contains the one of the final state so the string is accepted.
26
Finite State Machines with output
• Moore Machine and Mealy Machines, Illustration of the
Moore and Mealy Machines

28
Moore Machine

A Moore machine is defined as a machine in theory of computation whose


output values are determined only by its current state.
It has also 6 tuples: (Q, q0, ∑, O, δ, λ)
Q is finite set of states
q0 is the initial state
∑ is the input alphabet
O is the output alphabet
δ is transition function which maps Q×∑ → Q
λ is the output function which maps Q → O

29
Design Moore Machine which determine
the residue mod-3 for each binary string
treated as binary integer

30
Design Moore Machine which determine
the residue mod-3 for each binary string
treated as binary integer

31
Design a Moore machine which counts the
occurrence of sub string aab in input string

32
Design a Moore machine which counts the
occurrence of sub string aab in input string

33
CSC 257
Design Moore machine which calculate
residue mod-4 for each binary string treated
as binary integer.

34
Design Moore machine which calculate
residue mod-4 for each binary string treated
as binary integer.

35
Mealy Machine

A mealy machine is defined as a machine in


theory of computation whose output values are
determined by both its current state and current
inputs. In this machine at most one transition is
possible.
It has 6 tuples: (Q, q0, ∑, O, δ, λ’)
Q- is finite set of states
q0- is the initial state
∑ -is the input alphabet
O -is the output alphabet
δ -is transition function which maps Q×∑ → Q
‘λ’- is the output function which maps Q×∑→
O

36
Design Mealy machine , which prints 1’s
complement of input bit string over
alphabet {0,1}

37
Design Mealy machine , which prints 1’s
complement of input bit string over alphabet {0,1}

Input: 1010
q0 --(1/0) --q0-- (0/1)-- q0 --(1/0) --q0 --(0/1)
Output : 0101

38
Design mealy machine which marks as a increment machine that
assumes that its input is a binary number and prints out the
binary number that is one larger.

39
Design mealy machine which marks as a increment machine that
assumes that its input is a binary number and prints out the
binary number that is one larger
0/0

No 1/1
0/1
Carry

0/1
Initial

1/0
1/0

Carry

Let us pass 100 = 4 , Input string as 001 that is in inverse order


0/1 No 0/0 No 1/1 No
Initial
Carry Carry Carry

Output string =101=5 which is 4+1


Next, Input string w =11 =3
1/0 1/0
Initial Carry Carry

Output string =100=4, which is 3+1

40
Construct mealy machine for string ending
with 00 or 11

41
# Construct mealy machine for string
ending with 00 or 11
Here are three states of
mealy machine that use its
state to remember that last
symbol read, emits output y
whenever the current input
matches the previous one
,and emits n otherwise

42
Mealy Machine which calculate residue mod-4 for
each binary string treated as integer

43
Mealy Machine which calculate residue mod-4 for
each binary string treated as integer

44

You might also like