Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 3

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

CS-352 TAFL

Deterministic Finite Automata


with Examples

Instructor: Yusra Arshad

Book: Prof. Sipser-MIT

1
Deterministic Finite Automaton (DFA)

Input Tape
String
Output
“Accept”
Finite
or
Automaton
“Reject”

2
Transition Graph
a, b

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

initial accepting
state state
transition
state
3
Recap Formal Definition
Deterministic Finite Automaton (DFA)

M = (Q, ,  , q0 , F )
Q : set of finite states
 : set of finite input alphabet   
 : transition function δ : Q × Σ → Q
q0 : initial state

F : set of accepting states


4
Extended Transition Function

 :Q   → Q
* *

 (q ,w ) = q 
*

Describes the resulting state


after scanning string w from state q

5
Alphabet  = {a , b }
a, b

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

For every state, there is a transition


for every symbol in the alphabet

6
Recap 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
7
head Initial Configuration
Input Tape
a b b a
Input String
a, b

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

Initial state
8
Scanning the Input

a b b a

a, b

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

9
Scanning forward…

a b b a

a, b

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

10
Scanning forward…

a b b a

a, b

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

11
Input finished

a b b a

a, b

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

Last state determines the outcome


12
A Rejection Case

a b a
Input String
a, b

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

13
Scanning forward…

a b a

a, b

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

14
Scanning forward…

a b a

a, b

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

15
Input finished

a b a

a, b

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

Last state determines the outcome


16
Another Rejection Case

Tape is empty
( )

Input Finished (no symbol read)


a, b

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

reject
For DFA some authors denote empty string by  17
This automaton accepts only one string

Language Accepted: L = abba 

a, b

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

18
To accept a string:
all the input string is scanned
and the last state is accepting

To reject a string:
all the input string is scanned
and the last state is non-accepting

19
Another Example

L = , ab , abba 
a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
Accept Accept Accept
state state state
20
Language Accepted by DFA

Language accepted by DFA M:


it is denoted as L (M ) and contains
all the strings accepted by M

We also say that M recognizes L (M )

21
For a DFA M = (Q, ,  , q0 , F )
Language accepted by M:

L(M ) = w   :  (q0 ,w )  F
* *

q0 w q q  F

22
 = {a , b }

L(M ) = { all strings with prefix ab }


a, b

q0 a q1 b q2

b a accept

q3 a, b

23
 = {a , b }

L(M ) = { all strings with prefix ab }


a, b

q0 a q1 b q2

b a accept

q3 a, b

24
Consider the following DFA.

Guess its accepted language!

a a, b

b a, b
q0 q1 q2

Accept trap state


state
25
Language Accepted: L = {a b : n  0 }
n

a a, b

b a, b
q0 q1 q2

26
Another Example
Alphabet:  = {1}
1

q0 q1
1
Language Accepted:

EVEN = {x : x   and x is even}


*

= { , 11, 1111, 111111, }


27
L (M ) = { all binary strings containing
substring 001 }

0,1
1 0
1

 0 0 00 1 001
0

28
L (M ) = { all binary strings without
substring 001 }

1 0 0,1
1

 0 1
0 00 001

0
29
Thank You!

31

You might also like