Finite Automata & Regular Languages

Download Report

Transcript Finite Automata & Regular Languages

Finite Automata &
Regular Languages
Sipser, Chap 1
Hopcroft, Motawi, Ullman, Chap 2
Deterministic Finite Automata

A DFA or deterministic finite automaton M is a
5-tuple, M = (Q, , , q0, F), where:





Q is a finite set of states of M
 is the finite input alphabet of M
: Q    Q is the state transition function
q0 is the start state of M
F  Q is the set of accepting states or final states
of M
DFA Example


State diagram
Q = { q0, q1 }
 = { 0, 1 }
F = { q1 }
0
M
q0
1
0
q1
1

q0
0
q0
1
q1
q1
q1
q0
State
Table
State table &
state transition function


State table

q0
0
q0
1
q1
q1
q1
q0
State transition function
(q0, 0) = q0, (q0, 1) = q1
(q1, 0) = q1, (q1, 1) = q0
State transitions


If q, q’  Q, s  , and (q, s) = q’,
then we say that q’ is an s-successor of
q, or there is a transition from q to q’
on input s, and we write
q s q’
Example: since (q0, 1) = q1, then there
is a transition from q0 to q1 on input 1,
and we write q0 1 q1.
State sequences

If a string of input symbols
w = s0s1s2 … sk-1 takes M from initial
state q0 to state qk, namely
q0 s0 q1 s1 q2 s2 q3  … s[k-1] qk
then we say that qk is a w-successor of
q0, and write q0 w qk. Also q0q1q2 … qk
is called an admissible state sequence
for w.
Strings accepted by a DFA

Let M = (Q, , , q0, F) be a DFA, and
w = s0s1s2 … sk-1  * be a string over
alphabet . Then M accepts w if there
exists an admissible state sequence
q0q1q2 … qk for w, starting at initial
state q0 and ending with state qk,
where qk  F. That is, M accepts input
string w if M ends up in one of the final
states.
Language recognized by a DFA


The language L(M) that is recognized
by a DFA, M = (Q, , , q0, F), is the set
of all strings accepted by M. That is,
L(M) = { w  * | M accepts w }
= { w  * | q0 w qk, qk  F }.
Example: For the previous DFA, L(M) is
the set of all strings of 0s and 1s with
odd parity, that is, odd number of 1s.
DFA Example 2

Recognizer for 11*01*
1
B
* means zero or more
occurrences of the
preceding symbol
0
1
1
C
A
0
0
Trap
D
0,1
DFA Example 2

M = (Q, , , q0, F), L(M) = 11*01*
Q = { q0=A, B, C, D }
 = { 0, 1 }

0
1
F={C}
A
D
B
B
C
B
C
D
C
D
D
D
DFA Example 3

0
Modulo 3 counter
B
1
0
2
A
1
2
2
1
C
0
DFA Example 3

M = (Q, , , q0, F)
Q = { q0=A, B, C }
 = { 0, 1, 2 }
F={A}

0
1
2
A
A
B
C
B
B
C
A
C
C
A
B
Regular Languages and DFAs


A language L  * is called regular if
there exists a DFA M such that L(M)=L
Examples of regular languages



Binary strings with odd parity
Language described by 11*01*
Strings that form integers divisible by 3
Next



Variations on Finite Automata; e.g.,
Nondeterministic Finite Automata
(NFAs)
Equivalences of these variations with
DFAs
Regular expressions