0% found this document useful (0 votes)
14 views57 pages

02 Dfa

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 57

Deterministic

Finite Automata

And Regular Languages


Deterministic Finite Automaton (DFA)

Input Tape
String
Output
“Accept”
Finite
or
Automaton
“Reject”
Transition Graph
a, b

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

initial accepting
state state
transition
state
Alphabet Σ = {a , b }
a, b

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

For every state, there is a transition


for every symbol in the alphabet
head Initial Configuration
Input Tape
a b b a
Input String
a, b

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

Initial state
Scanning the Input

a b b a

a, b

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

a, b

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

a, b

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

a b b a

a, b

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

accept
A Rejection Case

a b a
Input String
a, b

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

a, b

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

a, b

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

a b a

a, b

reject
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Another Rejection Case

Tape is empty
(λ )

Input Finished
a, b

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

reject
Language Accepted: L = {abba }

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
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
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
Empty Tape
(λ )

Input Finished a, b

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

accept
Another Example

a a, b

q0 b q1 a, b q2

Accept trap state


state
a a b
Input String
a a, b

q0 b q1 a, b q2
a a b

a a, b

q0 b q1 a, b q2
a a b

a a, b

q0 b q1 a, b q2
Input finished

a a b

a a, b
accept

q0 b q1 a, b q2
A rejection case

b a b
Input String
a a, b

q0 b q1 a, b q2
b a b

a a, b

q0 b q1 a, b q2
b a b

a a, b

q0 b q1 a, b q2
Input finished

b a b

a a, b

q0 b q1 a, b q2

reject
Language Accepted: L = {a b : n ≥ 0 }
n

a a, b

q0 b q1 a, b q2
Another Example
Alphabet: Σ = {1}
1

q0 q1
1
Language Accepted:
EVEN = {x : x ∈ Σ and x is even}
*

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


Formal Definition
Deterministic Finite Automaton (DFA)

M = ( Q, Σ, δ , q0 , F )
Q : set of states
Σ : input alphabet λ ∉Σ
δ : transition function
q0 : initial state
F : set of accepting states
Set of States Q
Example

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
Input Alphabet Σ

λ ∉Σ :the input alphabet never contains λ

Example
Σ = { a, b} a, b

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

Example
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Set of Accepting States F ⊆ Q

Example
F = { q4 } a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Transition Function δ :Q×Σ → Q

δ (q , x ) = q ′
x
q q′

Describes the result of a transition


from state q with symbol x
Example:
δ ( q0 , a ) = q1

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
δ ( q0 , b ) = q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
δ ( q2 , b ) = q3

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
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
Extended Transition Function
δ :Q × Σ → Q
* *

δ (q ,w ) = q ′
*

Describes the resulting state


after scanning string w from state q
Example: δ ( q0 , ab ) = q2
*

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
δ ( q0 , abbbaa ) = q5
*

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
δ ( q1 , bba ) = q4
*

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Special case:

for any state q

δ (q , λ ) = q
*
In general: δ ( q ,w ) = q ′
*

implies that there is a walk of transitions

w = σ 1σ 2 σ k
σ1 σ2 σk
q q′
states may be repeated

q w q′
Language Accepted by DFA

Language of DFA M:
it is denoted as L ( M ) and contains
all the strings accepted by M

We say that a language L ′


is accepted (or recognized)
( )
by DFA M if L M = L ′
For a DFA M = ( Q, Σ, δ , q0 , F )
Language accepted by M:
L ( M ) = {w ∈ Σ : δ ( q0 ,w ) ∈ F }
* *

q0 w q′ q′ ∈ F
Language rejected by M:

L ( M ) = {w ∈ Σ : δ ( q0 ,w ) ∉ F }
* *

q0 w q′ q′ ∉ F
More DFA Examples
Σ = {a , b }
a, b
a, b

q0 q0

L (M ) = { } L (M ) = Σ *

Empty language All strings


Σ = {a , b }

a, b

q0 a, b q0

L (M ) = { λ }
Language of the empty string
Σ = {a , b }
L( M ) = { all strings with prefix ab }
a, b

q0 a q1 b q2

b a accept

q3 a, b
L ( M ) = { all binary strings containing
substring 001 }

0,1
1 0
1

λ 0 0 00 1 001
0
L ( M ) = { all binary strings without
substring 001 }

1 0 0,1
1

λ 0 1
0 00 001

0
{
L(M ) = awa : w ∈ {a , b }
*
} a
b
b
q0 a q2 q3

b a
q4

a, b
Regular Languages
Definition:
A language L is regular if there is
a DFA M that accepts it ( L(M ) = L )

The languages accepted by all DFAs


form the family of regular languages
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).
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)

You might also like