0% found this document useful (0 votes)
41 views56 pages

Deterministic Finite Automata (DFA) : Md. Rafsan Jani Assistant Professor Department of CSE Jahangirnagar University

The document discusses Deterministic Finite Automata (DFA), including the formal definition of a DFA as a 5-tuple (Q, Σ, δ, q0, F) and examples of representing a DFA as a state diagram and transition table. It also provides examples of using DFAs to recognize specific strings and describes the history and rules of the game of tennis at a high level.

Uploaded by

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

Deterministic Finite Automata (DFA) : Md. Rafsan Jani Assistant Professor Department of CSE Jahangirnagar University

The document discusses Deterministic Finite Automata (DFA), including the formal definition of a DFA as a 5-tuple (Q, Σ, δ, q0, F) and examples of representing a DFA as a state diagram and transition table. It also provides examples of using DFAs to recognize specific strings and describes the history and rules of the game of tennis at a high level.

Uploaded by

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

CSE-309

Theory of Computation

Lecture 02

Deterministic Finite Automata (DFA)

Md. Rafsan Jani


Assistant Professor
Department of CSE
Jahangirnagar University
Overview

• Definition of DFA
• Components of DFA
• Converting a problem to DFA
• Example of DFA
• Regular Language

2
Finite Automata

An automaton with a finite number of states is called a


Finite Automaton(FA) or Finite State Machine(FSM).

FA can be classified into two categories:

1. Deterministic Finite Automaton (DFA)

2. Non-deterministic Finite Automaton (NFA)

3
DFA

In DFA, for each input symbol, one can determine the state
to which the machine will move. Hence, it is called
Deterministic Automaton.

As it has a finite number of states, the machine is called


Deterministic Finite Machine or Deterministic Finite
Automaton.

4
Observations

1. Each state has a single transition for each symbol in the


alphabet.

2. Every DFA has a computation for every finite string


over the alphabet.
,

5
Formal definition of DFA
A DFA can be represented by a 5-tuple (Q, Σ, δ, q0, F), where:

• Q is a finite set of states.


• Σ is a finite set of symbols, called the alphabet.
• δ is the transition function where δ : Q x Σ → Q.
• q0 is the initial state from where any input is processed (q0
∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).

6
Graphical Representation of a DFA
A DFA is represented by digraphs called state diagram.

• The vertices represent the states.


• The arcs labeled with an input alphabet show the transitions.
• The initial state is denoted by an empty single incoming arc.
• The final state is indicated by double circles.

The dead state is a special state from where for all possible input
symbol the transition repeats to itself.

7
Example: DFA accepting only string “abba”

a, b

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

8
Set of States Q

Example

Q   q0 , q1, q2 , q3 , q4 , q5 
a, b

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

9
Input Alphabet Σ

  :the input alphabet never contains 

Example
   a, b a, b

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

10
Initial State q0

Example

a, b

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

11
Set of Accepting States F such that F ⊆ Q

Example

F   q4  a, b

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

12
Transition Function δ : Q x Σ → Q

 (q , x )  q 
x
q q

Describes the result of a transition


from state q with symbol x

13
Example:
  q0 , a   q1

a, b

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

14
  q0 , b   q5

a, b

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

15
  q2 , b   q3

a, b

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

16
Transition Table for δ
symbols
 a b
q0 q1 q5
q1 q5 q2
states

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

 : Q  *  Q
^

 (q, w)  q
18
Special case:

for any state q


^
  q,    q

19
Example:

^
^   ^  
  q0 , ab     q0 , a , b        q0 ,  , a , b       q0 , a , b    q1 , b  q2
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
20
^
^   ^  
  q1 , bba       q1 , bb  , a         q1 , b  , b , a 
     
  ^   
         q1 ,   , b , b , a         q1 , b  , b  , a 
     
     q2 , b  , a     q3 , a   q4
a, b

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

21
^
  q0 , abbbaa   q5

a, b

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

22
Example: Recognizing Strings Ending in “ing”

Not i or g

Not i
Not i or n i

nothing Saw i Saw in Saw ing


i n g

Start i i

Not i

23
Example: Strings With No 11

0 0,1

1 1
A B C

Start 0

String so far String so far Consecutive


has no 11, has no 11, 1’s have
does not but ends in been seen.(Dead State)
end in 1. a single 1.

24
Alternative Representation: Transition Table

Final states
starred Columns =
0 1 input symbols

* A A B
Arrow for B A C
*
start state C C C

0 0,1
Rows = states
1 1
A B C
Each entry is δ
of the row and Start 0
column.

25
Example : Tennis
• Probably, it was invented in the 12th century or 1879.

• Match = 3-5 sets.

• Set = 6 or more games.

• Game =  at least four points and at least two points more than
the opponent

26
Winning a Game
• One person serves throughout.
• To win, you must score at least 4 points.
• You also must win by at least 2 points.
• Inputs are s = “server wins point” & o = “opponent wins point.
• Scores from zero to three points are described as " love",
"fifteen", "thirty", and "forty", respectively
• Scores equal to forty for each, the score is not called out as
"forty-forty", but rather as "deuce“
• For server "advantage" is called “Ad-in“
• For opponent   "advantage“ is called “Ad-out" 
27
Server
s Wins
40-Love s
s s Ad-in
o s
30-Love
s 40-15 o
o s o
Start 15-Love s
30-15 40-30
s s s
o o o
Love 15-all 30-all o deuce
s s s
o o
15-30 30-40
Love-15 s o
s
o o s
Love-30 15-40
s o
o
o Ad-out
Love-40
o
o
Opp’nt
Wins

28
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
* o
Love-15
s
o
15-30
s
s
30-40
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 29
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s

Start
*15-Love s o s
40-15 o
s
o
30-15 40-30
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 30
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s
o * s
o
s
o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 31
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s

*
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 32
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s

Love
s
o
15-all
s
o *
30-all
s
o
deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 33
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s

*
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 34
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s
o
s
o
s
o *
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 35
Example: Processing a String

sosososososs
Server
Wins
*
s
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 36
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s

Love
s
o
15-all
s
o
30-all
s
o *
deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 37
Example: Processing a String

sosososososs
Server
Wins
*
s
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 38
Example: Processing a String

sosososososs
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s

Love
s
o
15-all
s
o
30-all
s
o *
deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 39
Example: Processing a String

sosososososs
Server
Wins
*
s
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 40
Example: Processing a String

sosososososs *
Server
s Wins
40-Love s
s s Ad-in
30-Love o s
s 40-15 o
o s o
Start 15-Love 30-15 40-30 s
s s s
o o o
Love 15-all 30-all deuce
o s
s s
o o
15-30 30-40
Love-15 s
s o
o o s
Love-30 15-40
s o
o Ad-out
Love-40 o
o
o Opp’nt
Wins 41
  {a , b }

L M  = { all strings with prefix “ab” }

a, b

q0 a q1 b q2

b a accept

q3 a, b

42
L M  = { all binary strings containing substring “001” }

0,1
1 0
1

 0 0 00 1 001
0

43
L M  = { all binary strings without substring “001”}

1 0 0,1
1

 0 1
0 00 001

0
44

L(M )  awa : w   a , b 
*
 a
b
b
q0 a q2 q3

b a
q4

a, b
45
Language of a DFA
Automata of all kinds define languages.

If A is an automaton, L(A) is its language.

For a DFA A, L(A) is the set of strings labeling paths from


the start state to a final state.

Formally: L(A) = the set of strings w such that δ(q0, w) is in F.

46
Example: String in a Language

String 101 is in the language of the DFA below.

Start at A.
0 0,1

1 1
A B C

Start 0

47
Example: String in a Language

String 101 is in the language of the DFA below.

Follow arc labeled 1.


0 0,1

1 1
A B C

Start 0

48
Example: String in a Language

String 101 is in the language of the DFA below.

Then arc labeled 0 from current state B.


0 0,1

1 1
A B C

Start 0

49
Example: String in a Language

String 101 is in the language of the DFA below.


Finally arc labeled 1 from current state A. Result
is an accepting state, so 101 is in the language.
0 0,1

1 1
A B C

Start 0

50
Example – Concluded
The language of our example DFA is:
{w | w is in {0,1}* and w does not have two consecutive 1’s}

These conditions
Such that… about w are true.

Read a set former as


“The set of strings w…

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

Language accepted by A :

 ^

L  A    w   :   q0 , w   F 
*

 

q0 w q q  F

52
Language rejected by : A

 ^

L  A    w   :   q0 , w   F 
*

 

q0 w q q  F

53
Regular Languages
Definition:

A language L is regular if there is a DFA A that accepts


it ( L( A)  L )

The languages accepted by all DFAs form the family of


regular languages

54
Example regular languages:

 abba   , ab, abba


{a b : n  0} awa : w  a , b  
n *

{ all strings in {a,b}* with prefix “ab”}


{ all binary strings without substring “001” }

{x : x  {1} and x is even}


*

{ } { } {a , b } *

There exist automata that accept these languages (see previous


slides).
55
There exist languages which are not Regular:

n n
L {a b : n  0}

ADDITION  {x  y  z : x  1 , y  1 , z  1 ,
n m k

nm k}

There is no DFA that accepts these languages (we will prove this in a later class)

56

You might also like