lecture 22: dfas and finite state machines with …...finite state machines • states •...
TRANSCRIPT
![Page 1: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/1.jpg)
CSE 311: Foundations of Computing
Lecture 22: DFAs and Finite State Machines with Output
![Page 2: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/2.jpg)
Finite State Machines
• States
• Transitions on input symbols
• Start state and final states
• The “language recognized” by the machine is the
set of strings that reach a final state from the start
s0
s2
s3
s1
111
0,1
0
0
0Old State 0 1
s0 s0 s1
s1 s0 s2
s2 s0 s3
s3 s3 s3
![Page 3: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/3.jpg)
Old State 0 1
s0 s0 s1
s1 s0 s2
s2 s0 s3
s3 s3 s3
Finite State Machines
• Each machine designed for strings over some
fixed alphabet Σ.
• Must have a transition defined from each state for
every symbol in Σ.
s0
s2
s3
s1
111
0,1
0
0
0
![Page 4: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/4.jpg)
Strings over {0, 1, 2}
M1: Strings with an even number of 2’s
M2: Strings where the sum of digits mod 3 is 0
s0 s
1
t0 t
2
t1
20,10,1
2
![Page 5: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/5.jpg)
Strings over {0, 1, 2}
M1: Strings with an even number of 2’s
M2: Strings where the sum of digits mod 3 is 0
s0 s
1
t0
t2
t1
20,10,1
2
0
0
0
1 1
1
2 2
2
![Page 6: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/6.jpg)
What language does this machine recognize?
s0
s2
s3
s1
1
1
1
1
0
0
0
0
![Page 7: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/7.jpg)
What language does this machine recognize?
s0
s2
s3
s1
1
1
1
1
0
0
0
0
The set of all binary strings with # of 1’s ≣ # of 0’s (mod 2)
(both are even or both are odd).
Can you think of a simpler description?
![Page 8: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/8.jpg)
Strings over {0, 1, 2}
M1: Strings with an even number of 2’s
M2: Strings where the sum of digits mod 3 is 0
s0 s
1
t0
t2
t1
20,10,1
2
0
0
0
1 1
1
2 2
2
![Page 9: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/9.jpg)
Strings over {0,1,2} w/ even number of 2’s and mod 3 sum 0
s0t0
s1t0
s0t1
s0t2
s1t1
s1t2
![Page 10: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/10.jpg)
Strings over {0,1,2} w/ even number of 2’s and mod 3 sum 0
s0t0
s1t0
s0t1
s0t2
s1t1
s1t2
0 0
1
1
1
1
0
0 0
0
1
1
2
2
2 2
2
2
![Page 11: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/11.jpg)
Strings over {0,1,2} w/ even number of 2’s OR mod 3 sum 0?
s0t0
s1t0
s0t1
s0t2
s1t1
s1t2
0 0
1
1
1
1
0
0 0
0
1
1
2
2
2 2
2
2
![Page 12: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/12.jpg)
Strings over {0,1,2} w/ even number of 2’s OR mod 3 sum 0
s0t0
s1t0
s0t1
s0t2
s1t1
s1t2
0 0
1
1
1
1
0
0 0
0
1
1
2
2
2 2
2
2
![Page 13: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/13.jpg)
The set of binary strings with a 1 in the 3rd position from the start
![Page 14: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/14.jpg)
The set of binary strings with a 1 in the 3rd position from the start
s0
s2
As1
10,10,1
0,1
R
00,1
![Page 15: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/15.jpg)
The set of binary strings with a 1 in the 3rd position from the end
![Page 16: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/16.jpg)
3 bit shift register
001 011
111
110
101010000
100
1
11 0
1
1
1
1
000
1
0
0
00
“Remember the last three bits”
![Page 17: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/17.jpg)
001 011
111
110
101010000
100
1
11 0 1
1
1
1
000
1
0
0
00
10
00 01 10 11
11
1
0
0 0
0 0 0 01
1
1
1
The set of binary strings with a 1 in the 3rd position from the end
![Page 18: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/18.jpg)
001 011
111
110
101010000
100
1
11 0
1
1
1
1
000
1
0
0
00
The set of binary strings with a 1 in the 3rd position from the end
![Page 19: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/19.jpg)
The beginning versus the end
001 011
111
110
101010000
100
1
11 0
1
1
1
1
000
1
0
0
00
s0
s2
As1
10,10,1
0,1
R
0 0,1
![Page 20: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/20.jpg)
Adding Output to Finite State Machines
• So far we have considered finite state
machines that just accept/reject strings
– called “Deterministic Finite Automata” or DFAs
• Now we consider finite state machines that
with output
– These are the kinds used as controllers
![Page 21: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/21.jpg)
Vending Machine
Enter 15 cents in dimes or nickels
Press S or B for a candy bar
![Page 22: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/22.jpg)
Vending Machine, v0.1
0 5 10 15
D D
N N N, D
B, S
Basic transitions on N (nickel), D (dime), B (butterfinger), S (snickers)
![Page 23: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/23.jpg)
Vending Machine, v0.2
0’
[B]5 10
15
Adding output to states: N – Nickel, S – Snickers, B – Butterfinger
15’
[N]
0
0”
[S]
N
N
N
N
N
B
D
D
D
D
D B
S
S
![Page 24: Lecture 22: DFAs and Finite State Machines with …...Finite State Machines • States • Transitions on input symbols • Start state and final states • The “language recognized”](https://reader033.vdocuments.us/reader033/viewer/2022060515/5f89d1b54d0d3103100fd29f/html5/thumbnails/24.jpg)
Vending Machine, v1.0
0’ [B]
5 10
15
Adding additional “unexpected” transitions to cover all symbols for each state
15’
[N]
0
0”
[S]
N
N
N
N
N
B
D
D
D
D
DB
S
S
15”
[D]S
B
B,S
B,S
B,S
B,SB,S
N
N
N
D
D
D