You are on page 1of 57

ATFL- Lecture #3

Finite Automata

A. Senthil - Professor/CSE 1
Finite Automaton

Input
String

Output
Finite String
Automaton

A. Senthil - Professor/CSE 2
Finite Accepter

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

A. Senthil - Professor/CSE 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”

A. Senthil - Professor/CSE 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

A. Senthil - Professor/CSE 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

A. Senthil - Professor/CSE 6
a b b a

a, b

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

A. Senthil - Professor/CSE 7
a b b a

a, b

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

A. Senthil - Professor/CSE 8
a b b a

a, b

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

A. Senthil - Professor/CSE 9
Input finished

a b b a

a, b

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

Output: “accept”
A. Senthil - Professor/CSE 10
Rejection

a b a

a, b

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

A. Senthil - Professor/CSE 11
a b a

a, b

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

A. Senthil - Professor/CSE 12
a b a

a, b

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

A. Senthil - Professor/CSE 13
a b a

a, b

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

A. Senthil - Professor/CSE 14
Input finished

a b a

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

A. Senthil - Professor/CSE 15
Another Rejection

a, b

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

A. Senthil - Professor/CSE 16
l

a, b

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

Output:
“reject” A. Senthil - Professor/CSE 17
Another Example

a a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 18
a a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 19
a a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 20
a a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 21
Input finished

a a b

a a, b
Output: “accept”

q0 b q1 a, b q2

A. Senthil - Professor/CSE 22
Rejection

b a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 23
b a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 24
b a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 25
b a b

a a, b

q0 b q1 a, b q2

A. Senthil - Professor/CSE 26
Input finished

b a b

a a, b

q0 b q1 a, b q2

Output: “reject”

A. Senthil - Professor/CSE 27
Formalities
Deterministic Finite
Accepter (DFA)
M = (Q, S, d , q0 , F )
Q : set of states
S : input alphabet
d : transition function
q0 : initial state q0 Î Q

F : set of final states F Í Q


A. Senthil - Professor/CSE 28
Input Alphabet S

S = {a, b}

a, b

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

A. Senthil - Professor/CSE 29
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

A. Senthil - Professor/CSE 30
Initial State q0

a, b

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

A. Senthil - Professor/CSE 31
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

A. Senthil - Professor/CSE 32
Transition Function d

d :Q´S ® Q

a, b

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

A. Senthil - Professor/CSE 33
d (q0 , a ) = q1

a, b

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

A. Senthil - Professor/CSE 34
d (q0 , b ) = q5

a, b

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

A. Senthil - Professor/CSE 35
d (q2 , b ) = q3

a, b

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

A. Senthil - Professor/CSE 36
Transition Function d
d a b
q0 q1 q5
q1 q5 q2
q2 q5 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
A. Senthil - Professor/CSE 37
Extended Transition Function
d *or dˆ
d * : Q ´ S* ® Q
a, b

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

A. Senthil - Professor/CSE 38
d * (q0 , ab ) = q2

a, b

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

A. Senthil - Professor/CSE 39
d * (q0 , abba ) = q4

a, b

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

A. Senthil - Professor/CSE 40
d * (q0 , abbbaa ) = q5

a, b

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

A. Senthil - Professor/CSE 41
Observation: There is a walk from q to q¢
with label w

d * ( q , w ) = q¢

q w q¢

w = s 1s 2 !s k
s1 s2 sk
q q¢

A. Senthil - Professor/CSE 42
Example: There is a walk from q0 to q5
with label abbbaa

d * (q0 , abbbaa ) = q5
a, b

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

A. Senthil - Professor/CSE 43
Inductive Definition
Basis d * (q , l ) = q
Induction d * (q, ws ) = d (d * (q, w),s )

q w q1 s q¢

d * ( q , ws ) = q¢
d * (q, ws ) = d (q1,s )
d (q1,s ) = q¢
d * (q, ws ) = d (d * (q, w),s )
d * (q, w) = q1

A. Senthil - Professor/CSE 44
d * (q0 , ab ) =
d (d * (q0 , a ), b ) =
d (d (d * (q0 , l ), a ), b ) =
d (d (q0 , a ), b ) =
d (q1 , b ) =
q2 a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
A. Senthil - Professor/CSE 45
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}

A. Senthil - Professor/CSE 46
Example
L(M ) = {abba} M

a, b

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

A. Senthil - Professor/CSE 47
Another Example
L(M ) = {l , ab, abba} M

a, b

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

A. Senthil - Professor/CSE 48
Formally
For a DFA M = (Q, S, d , q0 , F )

Language accepted by M :

L(M ) = {w Î S* : d * (q0 , w) Î F }

q0 w q¢ q¢ Î F

A. Senthil - Professor/CSE 49
Observation
Language rejected by M :

L(M ) = {w Î S* : d * (q0 , w) Ï F }

q0 w q¢ q¢ Ï F

A. Senthil - Professor/CSE 50
More Examples

L(M ) = {a b : n ³ 0}
n

a a, b

q0 b q1 a, b q2

accept trap state

A. Senthil - Professor/CSE 51
L(M ) = { all strings with prefix ab }
a, b

q0 a q1 b q2

b a accept

q3 a, b

A. Senthil - Professor/CSE 52
L (M ) = { all strings without
substring 001 }

1 0 0,1
1

l 0 1
0 00 001

0
A. Senthil - Professor/CSE 53
Regular Languages

A language L is regular if there is


a DFA M such that L = L( M )

All regular languages form a language family

A. Senthil - Professor/CSE 54
Examples of regular languages:

{abba} {l , ab, abba} n


{a b : n ³ 0}
{ all strings with prefix ab }
{ all strings with prefix ab }
{ all strings without substring 001 }

There exist automata that accept these


Languages (see previous slides).
A. Senthil - Professor/CSE 55
Another Example
The language L = {awa : w Î {a, b}*}
is regular:
a
b
L = L( M ) b
q0 a q2 q3

b a
q4

a, b
A. Senthil - Professor/CSE 56
There exist languages which are not Regular:

Example: n n
L= {a b : n ³ 0}

There is no DFA that accepts such a language

(we will prove this later in the class)

A. Senthil - Professor/CSE 57

You might also like