Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite...

20
Deterministic Finite Automata CS 154, Omer Reingold

Transcript of Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite...

Page 1: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Deterministic Finite Automata

CS 154, Omer Reingold

Page 2: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

00,1

00

1

1

1

Anatomy of Deterministic Finite Automata

states

states

q0

q1

q2

q3start state (q0)

accept states (F)transition: for every state and alphabet symbol

Page 3: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

00,1

00

1

1

1

0111 111

11

1

The automaton accepts the string if this process ends in a double-circle (accept state). Otherwise, the automaton rejects the string.

The DFA reads its string from left to right

Page 4: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Why so Many Models?

Page 5: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

What and Why DFASimple: Constant-size memory & read-once input

Both as important?

Foundational or archaic object?

So “close” to a Turing Machine and yet so far: nondeterminism (verified guessing) is “weak”, optimizing (and some settings of learning) is easy

Allows us to talk about – useful vocabulary, nondeterminism, (learning), limitations, streaming, communication complexity

Page 6: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

IBM JOURNAL APRIL 1959

Turing Award winning paper

Page 7: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:
Page 8: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

1

42

00

Streaming Algorithms

Page 9: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

An alphabet Σ is a finite set (e.g., Σ = {0,1})

A string over Σ is a finite length sequence of elements of Σ

For string x, |x| is the length of xThe unique string of length 0 is denoted by ε

and is called the empty string

Some Vocabulary

Σ* = the set of all strings over Σ

Page 10: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Every language L over Σ corresponds to a unique function f : Σ* → {0,1}:

Define f such that f(x) = 1 if x L= 0 otherwise

Languages

A language over Σ is a set of strings over ΣIn other words: a language is a subset of Σ*

Languages = Boolean functions over strings

Page 11: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Q is the set of states (finite)Σ is the alphabet (finite) : Q Σ→ Q is the transition functionq0 Q is the start stateF Q is the set of accept/final states

Definition. A DFA is a 5-tuple M = (Q, Σ, , q0, F)

Page 12: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Definition. A DFA is a 5-tuple M = (Q, Σ, , q0, F)

Let w1, ... , wn Σ and w = w1... wn Σ*M accepts w if there are r0, r1, ..., rn Q, s.t.

• r0 = q0

• (ri, wi+1) = ri+1 for all i = 0, ..., n-1, and • rn F

Page 13: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Q = {q0, q1, q2, q3}

Σ = {0,1}

: Q Σ → Q transition function*q0 Q is start state

F = {q1, q2} Q accept states

M = (Q, Σ, , q0, F) where

0 1

q0 q0 q1

q1 q2 q2

q2 q3 q2

q3 q0 q2

*

Page 14: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

A DFA is a 5-tuple M = (Q, Σ, , q0, F)

L(M) = set of all strings that M accepts = “the language recognized by M”= the function computed by M

Page 15: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

1

0

0,1

1010 010100

0,1

L(M) = { w | w begins with 1}

M

Page 16: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

0,1q0

L(M) ={0,1}*

Page 17: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

q0 q1

0 0

1

1

L(M) = { w | w has an even number of 1s}

Page 18: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

0

1

1

0

p q

Theorem:L(M) = {w | w has odd

number of 1s }

Induction Step Suppose for all w Σ*, |w| = n,M accepts w w has odd number of 1s

A string of length n+1 has the form w0 or w1, |w|=n, continue with a case analysis …

Proof: By induction on n, the length of a string.

Base Case n=0: ε L and ε L(M)

Page 19: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

q q00

1 0

1q0 q001

0 0 1

0,1

Build a DFA that accepts exactly the strings containing 001

Page 20: Deterministic Finite Automata - Omer Reingold · 2020. 9. 6. · Anatomy of Deterministic Finite Automata states states q 0 q 1 q 2 start state (q 0) q 3 accept states (F) transition:

Definition: A language L’ is regular if

L’ is recognized by a DFA;

that is, there is a DFA M where L’ = L(M).

L’ = { w | w contains 001} is regular

L’ = { w | w has an even number of 1s} is regular