Languages and Finite Automata

Download Report

Transcript Languages and Finite Automata

Deterministic
Finite Automata
And Regular Languages
Prof. Busch - LSU
1
Deterministic Finite Automaton (DFA)
Input Tape
String
Finite
Automaton
Prof. Busch - LSU
Output
“Accept”
or
“Reject”
2
Transition Graph
a,b
q5
b
q0 a
a
q1 b
initial
state
state
a
q2 b
b
q3 a
transition
Prof. Busch - LSU
a,b
q4
accepting
state
3
Alphabet
  {a , b }
a,b
q5
b
q0 a
a
q1 b
a
q2 b
b
q3 a
a,b
q4
For every state, there is a transition
for every symbol in the alphabet
Prof. Busch - LSU
4
Initial Configuration
head
a b b a
Input Tape
Input String
a,b
q5
b
q0 a
a
q1 b
a
q2 b
b
q3 a
a,b
q4
Initial state
Prof. Busch - LSU
5
Scanning the Input
a b b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
6
a b b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
7
a b b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
8
Input finished
a b b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
b
q3 a
a,b
q4
accept
Last state determines the outcome
Prof. Busch - LSU
9
A Rejection Case
a b a
Input String
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
10
a b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
11
a b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
12
Input finished
a b a
a,b
q5
b
q0 a
a
q1 b
a
q2 b
b
q3 a
reject
a,b
q4
Last state determines the outcome
Prof. Busch - LSU
13
Another Rejection Case
Tape is empty
( )
Input Finished (no symbol read)
a,b
q5
b
q0 a
a
q1 b
a
q2 b
b
q3 a
a,b
q4
reject
Prof. Busch - LSU
14
This automaton accepts only one string
Language Accepted:
L  abba

a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
15
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
Prof. Busch - LSU
16
Another Example
L   , ab , abba

a,b
q5
b
q0 a
Accept
state
a
a
q1 b
q2 b
Accept
state
Prof. Busch - LSU
b
q3 a
a,b
q4
Accept
state
17
Empty Tape
( )
Input Finished
a,b
q5
b
q0 a
a
a
q1 b
q2 b
b
q3 a
a,b
q4
accept
Prof. Busch - LSU
18
Another Example
a,b
a
q0
b
q1
Accept
state
Prof. Busch - LSU
a,b
q2
trap state
19
a
a b
Input String
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
20
a
a b
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
21
a
a b
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
22
Input finished
a
a b
a
q0
a,b
accept
b
q1
Prof. Busch - LSU
a,b
q2
23
A rejection case
b
a b
Input String
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
24
b
a b
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
25
b
a b
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
26
Input finished
b
a b
a,b
a
q0
b
q1
a,b
q2
reject
Prof. Busch - LSU
27
Language Accepted: L  { a n b : n  0 }
a,b
a
q0
b
q1
Prof. Busch - LSU
a,b
q2
28
Another Example
Alphabet:   { 1 }
1
q0
q1
1
Language Accepted:
EVEN
*
 { x : x   and x is even}
 {  , 11 , 1111 , 111111 ,  }
Prof. Busch - LSU
29
Formal Definition
Deterministic Finite Automaton (DFA)
M  Q ,  ,  , q 0 , F 
Q
: set of states

: input alphabet
 
 : transition function
q 0 : initial state
F
: set of accepting states
Prof. Busch - LSU
30
Set of States Q
Example
Q  q 0 , q1 , q 2 , q 3 , q 4 , q 5 
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
31
Input Alphabet 
   :the input alphabet never contains 
Example
  a , b 
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
32
Initial State q 0
Example
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
33
Set of Accepting States F  Q
Example
F  q 4 
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
34
Transition Function
 :Q    Q
 (q , x )  q 
q
x
q
Describes the result of a transition
from state q with symbol x
Prof. Busch - LSU
35
Example:
  q 0 , a   q1
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
36
 q0 , b   q5
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
37
 q 2 , b   q3
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
38
Transition Table for

symbols
states

a
q0
q1
b
q5
q1
q5
q2
q2
q5
q3
q3
q4
q5
q4
q5
q5
q5
q5
q5
a,b
q5
b
q0 a
a
q1 b
Prof. Busch - LSU
a
q2 b
b
q3 a
a,b
q4
39
Extended Transition Function
*
*
 :Q    Q
*
 (q , w )  q 
Describes the resulting state
after scanning string w from state q
Prof. Busch - LSU
40
Example: 
*
q 0 , ab   q 2
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
41

*
q 0 , abbbaa   q 5
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
42

*
q 1 , bba   q 4
a,b
q5
b
q0 a
a
q1 b
a
q2 b
Prof. Busch - LSU
b
q3 a
a,b
q4
43
Special case:
for any state q

*
q ,    q
Prof. Busch - LSU
44
In general:

*
q , w   q 
implies that there is a walk of transitions
w   1 2   k
q
1
k
2
q
states may be repeated
q
w
Prof. Busch - LSU
q
45
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
Prof. Busch - LSU

46
For a DFA
M  Q ,  ,  , q 0 , F 
Language accepted by
M
:
L M   w   : 
*
q0
w
Prof. Busch - LSU
*
q 0 , w   F 
q
q  F
47
Language rejected by M :
L M   w   : 
*
q0
w
*
q 0 , w   F 
q
Prof. Busch - LSU
q  F
48
More DFA Examples
  {a , b }
a,b
a,b
q0
q0
L (M )  { }
L (M )  
Empty language
All strings
Prof. Busch - LSU
*
49
  {a , b }
a,b
q0
a,b
q0
L (M )  {  }
Language of the empty string
Prof. Busch - LSU
50
  {a , b }
L  M  = { all strings with prefix ab }
a,b
q0
a
q1
b
a
q3
Prof. Busch - LSU
b
q2
accept
a,b
51
L  M  = { all binary strings containing
substring 001 }
1
0 ,1
0
1

0
0
00
1
001
0
Prof. Busch - LSU
52
L  M  = { all binary strings without
substring 001 }
1
0
0 ,1
1

0
0
00
1
001
0
Prof. Busch - LSU
53

L ( M )  awa : w  a , b 
*
b

a
b
q0
a
q2
q3
a
b
q4
a,b
Prof. Busch - LSU
54
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
Prof. Busch - LSU
55
Example regular languages:
abba 
 , ab , abba 
n
{ a b : n  0}
awa
: w  a , b 
*

{ 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 DFAs that accept these
languages (see previous slides).
Prof. Busch - LSU
56
There exist languages which are not Regular:
n n
L  { a b : n  0}
ADDITION
 {x  y  z
n
m
k
: x  1 , y  1 ,z  1 ,
nm k}
There are no DFAs that accept these languages
(we will prove this in a later class)
Prof. Busch - LSU
57