100% found this document useful (1 vote)
223 views63 pages

Chapter Two: Finite Automata (Fa)

This document discusses deterministic finite automata (DFAs). It defines a DFA as a 5-tuple (Q, Σ, δ, q0, F) where Q is a finite set of states, Σ is an input alphabet, δ is the transition function, q0 is the initial state, and F is the set of accepting states. It provides examples of DFAs that accept or reject different input strings and explains how the transition function δ works recursively to determine the state reached for an input string. The language accepted by a DFA is defined as all strings that drive the DFA to a final accepting state.

Uploaded by

Mehari Temesgen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
223 views63 pages

Chapter Two: Finite Automata (Fa)

This document discusses deterministic finite automata (DFAs). It defines a DFA as a 5-tuple (Q, Σ, δ, q0, F) where Q is a finite set of states, Σ is an input alphabet, δ is the transition function, q0 is the initial state, and F is the set of accepting states. It provides examples of DFAs that accept or reject different input strings and explains how the transition function δ works recursively to determine the state reached for an input string. The language accepted by a DFA is defined as all strings that drive the DFA to a final accepting state.

Uploaded by

Mehari Temesgen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 63

CHAPTER TWO

FINITE AUTOMATA (FA)

1
Deterministic Finite Automata
A deterministic finite automaton (DFA) is a
5-tuple (Q, , , q0, F) where
Q is a finite set of states
 is an input alphabet
: Q ×  → Q is a transition function
q0  Q is the initial state
F  Q is a set of accepting states (or final
states).
In diagrams, the accepting states will be
denoted by double loops
2
Language of a DFA
The language of a DFA (Q, , , q0, F) is the set of
all strings over  that, starting from q0 and
following the transitions as the string is read left
to right, will reach some accepting state.
A deterministic finite automaton is a special case of an
NFA
 No state has an ε-transition
 For each state Q and input symbol a there is at most
one edge labeled a leaving S

3
Transition Graph
Abba -Finite Accepter a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

initial final
state state
transition
state “accept”
4
Initial Configuration
Input String
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

5
Reading the Input

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

6
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

7
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

8
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

9
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

Output: “accept”
10
Rejection

a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

11
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

12
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

13
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

14
a b a

a, b
Output:
q5 “reject”
a a, b
b a b
q0 a q1 b q2 b q3 a q4

15
Another Example

a a b

a a,b

q0 b q1 a, b q2

16
a a b

a a,b

q0 b q1 a, b q2

17
a a b

a a,b

q0 b q1 a, b q2

18
a a b

a a,b

q0 b q1 a, b q2

19
a a b

a a,b
Output: “accept”

q0 b q1 a, b q2

20
Rejection

b a b

a a,b

q0 b q1 a, b q2

21
b a b

a a,b

q0 b q1 a, b q2

22
b a b

a a,b

q0 b q1 a, b q2

23
b a b

a a,b

q0 b q1 a, b q2

24
b a b

a a,b

q0 b q1 a, b q2

Output: “reject”
25
Input Aplhabet 

   a, b

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

26
Set of States Q
Q   q0 , q1, q2 , q3 , q4 , q5 

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

27
Initial State q0

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

28
Set of Final States F

F   q4 

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

29
Transition Function 

 :Q  Q

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

30
  q0 , a   q1

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

31
  q0 , b   q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

32
  q2 , b   q3

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

33
Transition Function 
 a b
q0 q1 q5
q1 q5 q2
q2 q2 q3
q3 q4 q5 a, b
q4 q5 q5
q5 q5 q5 q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
34
Extended Transition Function  *

 * : Q  *  Q

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

35
 *  q0 , ab   q2

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

36
 *  q0 , abba   q4

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

37
 *  q0 , abbbaa   q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

38
Observation: There is a walk from q0 to q5
with label abbbaa

 *  q0 , abbbaa   q5
a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

39
Recursive Definition

 *  q,    q
 *  q, wa    ( * (q, w), a )
a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
40
 *  q0 , ab  
   * (q0 , a ), b  
     *  q0 ,  , a , b  
    q0 , a , b  
  q1 , b  
q2 a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
41
Languages Accepted by DFAs
Take DFA M

Definition:
The language L M  contains
all input strings accepted by M

L M  = { strings that drive M to a final state}

42
Example
L M    abba M

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
accept
43
Another Example
L M     , ab, abba M

a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
accept accept accept
44
Formally

For a DFA M   Q, ,  , q0 , F 

Language accepted by M :
L M    w  * :  *  q0 , w  F 

alphabet transition initial final


function state states
45
Observation
Language accepted by M :

L M    w  * :  *  q0 , w  F 

Language rejected by M :

L M    w  * :  *  q0 , w  F 

46
More Examples

L M   {a b : n  0}
n

a a,b

q0 b q1 a, b q2

accept trap state

47
L M  = { all substrings with prefix ab }
a, b

q0 a q1 b q2

b a accept

q3 a, b
48
Example’s on DFA

49
Transition table

50
51
Con…

52
questions
1.Construct a DFA that accepts the language

L = {010, 1} (  = {0, 1} )

53
Con--
2.Construct a DFA over alphabet {0, 1} that accepts all strings that
end in 101.
3. Construct a DFA which accepts set of all strings over {a,b} that
starts with a string abb
4.Construct a DFA which accepts set of all strings over {0,1}.
5. Construct a DFA which accepts a set of all strings over {a,b} of the
form a3bwa3 where w is any string.

54
Non-Deterministic Finite Automata (NFA)
 Non determinism means a choice of moves for an
automaton. Rather than prescribing a, unique
move in each satiation.
 it allows a set of possible moves.

55
Con..
 In non deterministic finite accepter the range of
transition function is the power set of 2 the
power of Q,
 so that its value is not a single element of Q, but
a subset of it.
 This subset defines the set of all possible states
that can be reached by the transition.
 For examples:

56
Non-Deterministic Finite Automata
Definition
An NFA M consists of five tuples: ( Σ,S, T, S0, F)
A set of input symbols Σ, the input alphabet
a finite set of states S,
a transition function T: S × (Σ U { ε}) -> S (next state),
a start state S0 from S, and
a set of accepting/final states F from S.

57
NFA…
It is a finite automata which has choice of
edges
The same symbol can label edges from one state to several
different states.

An edge may be labeled by ε, the empty string


We can have transitions without any input character
consumption.

58
Transition Graph
The transition graph for an NFA recognizing the language
of regular expression (a|b)*abb
all strings of a's and b's ending in the
particular string abb
a

start a b b
0 1 2 3

b S={0,1,2,3}
Σ={a,b}
S0=0
F={3}
59
Transition Table
The mapping T of an NFA can be
represented in a transition table
State Input Input Input
a b ε
0 {0,1} {0} ø
T(0,a) = {0,1}
T(0,b) = {0} 1 ø {2} ø
T(1,b) = {2}
2 ø {3} ø
T(2,b) = {3}
3 ø ø ø

60
Equivalence of NFA and DFA
• Since a DFA is in essence a restricted kind of NFA
• it is clear that any language is accepted by a DFA is also accepted by
some NFA.
• But the converse is not so obvious. However finding a DFA equivalent
to given NFA can be hard, there are some DFA equivalent to NFA.
• Two finite automata M and M’ are said to be equivalent if they accept
the same language. i.e L(M)=L(M’).
• Since every DFA can be treated as an NFA, one side is obvious. The
converse, given an NFA there exist an equivalent an equivalent DFA.
• Theorem2.1: Let L be the language accepted by a nondeterministic
finite automata N=(QN , Ʃ, δN , q0, FN). Then there exists
deterministic finite automata D=(QD , Ʃ, δD, q0, FD) such that
L(N)=L(D).

61
Procedure of NFA to DFA
1. Create a graph D with a vertex {q0}. Identify this vertex as the
initial vertex.
2. Repeat the following steps until no more edges are missing
 Take any vertex { q0, q1, q2 ….} of D that has no outgoing edge for some a ϵ Ʃ
Compute δ*(q0,a), δ*(q1,a), δ*(q2,a),…………. δ*(qn,a).
 If δ*(q0,a) U δ*(q1,a) U δ*(q2,a) U δ*(qn, a)={q0, q1, q2, qn } Create a vertex for
graph D labelled {q0, q1, q2, qn } if it does not already exist. Add to graph D an
edge from {q0, q1, qn} and labelled it with a.
3. Every state of graph D whose labelled contains any qf ϵFN is
identified as a final vertex.
4. If N accepted Ɛ, the vertex in graph D is also made a final vertex.

62
Cont…
 Example6: Convert the given NFA to an equivalent DFA, using the
above converting procedure.

• Firstly figure out all the transitions start from q0 as initial state.
• δ({q0}, a) = { q1, q2} ……………….. Using a and Ɛ transitions.
• δ({q0}, b) = Ø
• δ({q1,q2}, a) = { q1, q2} ……………………. Using a and Ɛ transitions.
• δ({q1,q2}, b) = { q0}. There fore the result is

63

You might also like