automata theory - computer science - university of san francisco

37
Automata Theory CS411 20145-03 Determinisitic Finite Automata David Galles Department of Computer Science University of San Francisco

Upload: others

Post on 10-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automata Theory - Computer Science - University of San Francisco

Automata TheoryCS411 20145-03

Determinisitic Finite Automata

David Galles

Department of Computer Science

University of San Francisco

Page 2: Automata Theory - Computer Science - University of San Francisco

03-0: Generators vs. Checkers

Regular expressions are one way to specify aformal language

String Generator Generates strings in thelanguage

Deterministic Finite Automata (DFA) areanother way to specify a language

String Checker Given any string, determinesif that string is in the language or not

Page 3: Automata Theory - Computer Science - University of San Francisco

03-1: DFA Example

Example Deterministic Finite Automaton

a

a,b

b

a,b

0

1

2

Page 4: Automata Theory - Computer Science - University of San Francisco

03-2: DFA Example

DFA for all strings over {a,b} that contain exactly 2 a’s

Page 5: Automata Theory - Computer Science - University of San Francisco

03-3: DFA Example

DFA for all strings over {a,b} that contain exactly 2 a’s

a

b

0a

b

1a

b

2

a,b

3

Page 6: Automata Theory - Computer Science - University of San Francisco

03-4: DFA Example

All strings over a, b that have length 3.

Page 7: Automata Theory - Computer Science - University of San Francisco

03-5: DFA Example

All strings over a, b that have length 3.

a,b0

a,b1

a,b2 3

a,b

a,b

3

Page 8: Automata Theory - Computer Science - University of San Francisco

03-6: DFA Components

What makes up a DFA?

a

b

0a

b

1a

b

2

a,b

3

Page 9: Automata Theory - Computer Science - University of San Francisco

03-7: DFA Components

What makes up a DFA?

a

b

0a

b

1a

b

2

a,b

3

States

Page 10: Automata Theory - Computer Science - University of San Francisco

03-8: DFA Components

What makes up a DFA?

a

b

0a

b

1a

b

2

a,b

3

Alphabet (characters than can occur in stringsaccepted by DFA)

Page 11: Automata Theory - Computer Science - University of San Francisco

03-9: DFA Components

What makes up a DFA?

a

b

0a

b

1a

b

2

a,b

3

Transitions

Page 12: Automata Theory - Computer Science - University of San Francisco

03-10: DFA Components

What makes up a DFA?

a

b

0a

b

1a

b

2

a,b

3

Initial State

Page 13: Automata Theory - Computer Science - University of San Francisco

03-11: DFA Components

What makes up a DFA?

a

b

0a

b

1a

b

2

a,b

3

Final State(s) (there can be > 1)

Page 14: Automata Theory - Computer Science - University of San Francisco

03-12: DFA Definition

A DFA is a 5-tuple M = (K,Σ, δ, s, F )

K Set of states

Σ Alphabet

δ : (K × Σ) 7→ K is a Transition function

s ∈ K Initial state

F ⊆ K Final states

Page 15: Automata Theory - Computer Science - University of San Francisco

03-13: DFA Definition

a

b

0a

b

1a

b

2

a,b

3

K = {q0, q1, q2, q3}

Σ = {a, b}

δ ={((q0, a), q1), ((q0, b), q0), ((q1, a), q2), ((q1, b), q1),((q2, a), q3), ((q2, b), q2), ((q3, a), q3), ((q3, b), q3)}

s = q0

F = {q2}

Page 16: Automata Theory - Computer Science - University of San Francisco

03-14: Fun with DFA

Create a DFA for:

All strings over {0, 1} that contain the substring1001

Page 17: Automata Theory - Computer Science - University of San Francisco

03-15: Fun with DFA

Create a DFA for:

All strings over {0, 1} that contain the substring1001

1

0

00

1

10

2 3 41

10

0,1

Page 18: Automata Theory - Computer Science - University of San Francisco

03-16: Fun with DFA

Create a DFA for:

All strings over {0, 1} that end with 111

Page 19: Automata Theory - Computer Science - University of San Francisco

03-17: Fun with DFA

Create a DFA for:

All strings over {0, 1} that end with 111

01 1

11

2 3

0 0 0

0 1

Page 20: Automata Theory - Computer Science - University of San Francisco

03-18: Fun with DFA

Create a DFA for:

All strings over {0, 1} that begin with 111

Page 21: Automata Theory - Computer Science - University of San Francisco

03-19: Fun with DFA

Create a DFA for:

All strings over {0, 1} that begin with 111

10

11

12 3

0,1

4

00

0

0,1

Page 22: Automata Theory - Computer Science - University of San Francisco

03-20: Fun with DFA

Create a DFA for:

All strings over {0, 1} that begin or end with 111

Page 23: Automata Theory - Computer Science - University of San Francisco

03-21: Fun with DFA

Create a DFA for:

All strings over {0, 1} that begin or end with 111

10

11

12 3

0,1

41 1

51

6 7

0 0

0 0 0

1

0

0

Page 24: Automata Theory - Computer Science - University of San Francisco

03-22: Fun with DFA

Create a DFA for:

All strings over {0, 1} that begin and end with 111

Page 25: Automata Theory - Computer Science - University of San Francisco

03-23: Fun with DFA

Create a DFA for:

All strings over {0, 1} that begin and end with 111

10

11

12 3

1

41 1

51

6 7

0

0 0 0

1

0

8

00

0

0,1

Page 26: Automata Theory - Computer Science - University of San Francisco

03-24: Fun with DFA

Create a DFA for:

All strings over {0, 1} that contain 1001 or 0110

Page 27: Automata Theory - Computer Science - University of San Francisco

03-25: Fun with DFA

Create a DFA for:

All strings over {0, 1} that contain 1001 or 0110

0

1

01 12

0

03

14 05

16

1

0

1

0

0

1

0,17

Page 28: Automata Theory - Computer Science - University of San Francisco

03-26: Fun with DFA

Create a DFA for:

All strings over {a, b} that begin and end with thesame letter

Page 29: Automata Theory - Computer Science - University of San Francisco

03-27: Fun with DFA

Create a DFA for:

All strings over {a, b} that begin and end with thesame letter

0

1 2

b

a b

1 2

a

b a

a

b

a

b

Page 30: Automata Theory - Computer Science - University of San Francisco

03-28: Why DFA?

Why are these machines called “DeterministicFinite Automata”

Deterministic Each transition is completelydetermined by the current state and next inputsymbol. That is, for each state / symbol pair,there is exactly one state that is transitioned to

Finite Every DFA has a finite number of states

Automata (singular automaton) means“machine”(From Merriam-Webster Online Dictionary, definition 2: A machine or control

mechanism designed to follow automatically a predetermined sequence of

operations or respond to encoded instructions)

Page 31: Automata Theory - Computer Science - University of San Francisco

03-29: DFA Configuration & ⊢M

Way to describe the computation of a DFA

Configuration: What state the DFA is currentlyin, and what string is left to process

∈ K × Σ∗

(q2, abba) Machine is in state q2, has abba left toprocess

(q8, bba) Machine is in state q8, has bba left toprocess

(q4, ǫ) Machine is in state q4 at the end of thecomputation (accept iff q4 ∈ F )

Page 32: Automata Theory - Computer Science - University of San Francisco

03-30: DFA Configuration & ⊢M

Way to describe the computation of a DFA

Configuration: What state the DFA is currentlyin, and what string is left to process

∈ K × Σ∗

Binary relation ⊢M : What machine M yields in onestep

⊢M⊆ (K × Σ∗)× (K × Σ∗)

⊢M= {((q1, aw), (q2, w)) : q1, q2 ∈ KM , w ∈Σ∗

M, a ∈ ΣM , ((q1, a), q2) ∈ δM}

Page 33: Automata Theory - Computer Science - University of San Francisco

03-31: DFA Configuration & ⊢M

Given the following machine M :

a

a,b

b

a,b

0

1

2

((q0, abba), (q2, bba)) ∈⊢M

can also be written (q0, abba) ⊢M (q2, bba)

Page 34: Automata Theory - Computer Science - University of San Francisco

03-32: DFA Configuration & ⊢M

01 1

11

2 3

0 0 0

0 1

(q0, 11101) ⊢M (q1, 1101)

⊢M (q2, 101)

⊢M (q3, 01)

⊢M (q0, 1)

⊢M (q1, ǫ)

Page 35: Automata Theory - Computer Science - University of San Francisco

03-33: DFA Configuration & ⊢M

01 1

11

2 3

0 0 0

0 1

(q0, 10111) ⊢M (q1, 0111)

⊢M (q0, 111)

⊢M (q1, 11)

⊢M (q2, 1)

⊢M (q3, ǫ)

Page 36: Automata Theory - Computer Science - University of San Francisco

03-34: DFA Configuration & ⊢∗M

⊢∗

Mis the reflexive, transitive closure of ⊢M

Smallest superset of ⊢M that is both reflexiveand transitive

“yields in 0 or more steps”

Machine M accepts string w if:

(sM , w) ⊢∗

M(f, ǫ) for some f ∈ FM

Page 37: Automata Theory - Computer Science - University of San Francisco

03-35: DFA & Languages

Language accepted by a machine M = L[M ]

{w : (sM , w) ⊢∗

M(f, ǫ) for some f ∈ FM}

DFA Languages, LDFA

Set of all languages that can be defined by aDFA

LDFA = {L : ∃M,L[M ] = L}

To think about: How does LDFA relate to LREG