55
Theory of Computation Deterministic Finite Automata Barath Raghavan CS 361 Fall 2009 Williams College Tuesday, September 15, 2009

cs361-lecture02-1x1

Embed Size (px)

DESCRIPTION

Theoty of computation

Citation preview

Page 1: cs361-lecture02-1x1

Theory ofComputation

Deterministic Finite Automata

Barath RaghavanCS 361 Fall 2009Williams College

Tuesday, September 15, 2009

Page 2: cs361-lecture02-1x1

MISC

Anonymous feedbackHomework 1

LaTeX

Tuesday, September 15, 2009

Page 3: cs361-lecture02-1x1

Claim:In any set of n hats, all are the same color.

“Proof” by induction:Base case: If n = 1, all hats are the same color.Inductive case: Assume that the claim holds for all

n ≤ k. Examine any set of n = k+1 hats. Remove one hat from the set; the remaining set has k hats and thus is of a single color. Replace the hat and remove a different hat from the set; the resulting set has k hats and thus is of a single color. The two sets overlap, thus they must be of the same color.

Therefore, all k+1 hats are the same color. ☐

Tuesday, September 15, 2009

Page 4: cs361-lecture02-1x1

Claim:In any set of n hats, all are the same color.

“Proof” by induction:Base case: If n = 1, all hats are the same color.Inductive case: Assume that the claim holds for all

n ≤ k. Examine any set of n = k+1 hats. Remove one hat from the set; the remaining set has k hats and thus is of a single color. Replace the hat and remove a different hat from the set; the resulting set has k hats and thus is of a single color. The two sets overlap, thus they must be of the same color.

Therefore, all k+1 hats are the same color. ☐

Tuesday, September 15, 2009

Page 5: cs361-lecture02-1x1

Deterministic

FiniteAutomata

Tuesday, September 15, 2009

Page 6: cs361-lecture02-1x1

Tuesday, September 15, 2009

Page 7: cs361-lecture02-1x1

“An organism or an automaton receives stimuli via its sensory receptor organs, and performs actions via its effector organs. To say that certain actions are a response to certain stimuli means, in the simplest case, that the actions are performed when and only when those stimuli occur... So we ask what kind of events are capable of being represented in the state of an automaton.”

-- Kleene, “Representation of events in nerve nets and finite automata” (1956)

Tuesday, September 15, 2009

Page 8: cs361-lecture02-1x1

Tuesday, September 15, 2009

Page 9: cs361-lecture02-1x1

1 2 3

1 2 32, 3 3

1, 21

Elevator Automaton

Tuesday, September 15, 2009

Page 10: cs361-lecture02-1x1

StatesAlphabetTransitionStart stateFinal states

Tuesday, September 15, 2009

Page 11: cs361-lecture02-1x1

Q set of states

Tuesday, September 15, 2009

Page 12: cs361-lecture02-1x1

Q set of states

Σ the alphabet

Tuesday, September 15, 2009

Page 13: cs361-lecture02-1x1

Q set of states

Σ the alphabet

δ : Q× Σ→ Q transitionfunction

Tuesday, September 15, 2009

Page 14: cs361-lecture02-1x1

Q set of states

Σ the alphabet

δ : Q× Σ→ Q transitionfunction

q0 ∈ Q start state

Tuesday, September 15, 2009

Page 15: cs361-lecture02-1x1

Q set of states

Σ the alphabet

δ : Q× Σ→ Q transitionfunction

q0 ∈ Q start state

F ⊆ Q set of final states

Tuesday, September 15, 2009

Page 16: cs361-lecture02-1x1

1 2 3

1 2 32, 3 3

1, 21

Tuesday, September 15, 2009

Page 17: cs361-lecture02-1x1

1 2 3

1 2 32, 3 3

1, 21

Q = { 1�, 2�, 3�}

Tuesday, September 15, 2009

Page 18: cs361-lecture02-1x1

1 2 3

1 2 32, 3 3

1, 21

Q = { 1�, 2�, 3�}Σ = {1, 2, 3}

Tuesday, September 15, 2009

Page 19: cs361-lecture02-1x1

1 2 3

1 2 32, 3 3

1, 21

Q = { 1�, 2�, 3�}Σ = {1, 2, 3}

q0 = 1� F = { 3�}Tuesday, September 15, 2009

Page 20: cs361-lecture02-1x1

1 2 3

1 2 32, 3 3

1, 21

Inputs

States

δ 1 2 31� 1� 2� 2�2� 1� 2� 3�3� 2� 2� 3�

Tuesday, September 15, 2009

Page 21: cs361-lecture02-1x1

What languages do these automata recognize?

Tuesday, September 15, 2009

Page 22: cs361-lecture02-1x1

A B0, 1

0, 1

Tuesday, September 15, 2009

Page 23: cs361-lecture02-1x1

L = {ε}

A B0, 1

0, 1

Tuesday, September 15, 2009

Page 24: cs361-lecture02-1x1

A B C D

0 0 0 0, 1

1 1 1

Tuesday, September 15, 2009

Page 25: cs361-lecture02-1x1

A B C D

0 0 0 0, 1

1 1 1

L = {w | w contains at least 3 1s}

Tuesday, September 15, 2009

Page 26: cs361-lecture02-1x1

?Tuesday, September 15, 2009

Page 27: cs361-lecture02-1x1

A B C D

0 1 0, 1

1

0

1 0

L = {w | w doesn’t contain 110}d)

L = {w | w contains at most two 1s}a)

L = {w | |w| < 3}b)

L = {w | |w| < 3 or contains at least two 1s}c)

Tuesday, September 15, 2009

Page 28: cs361-lecture02-1x1

A B C D

0 1 0, 1

1

0

1 0

L = {w | w doesn’t contain 110}

Tuesday, September 15, 2009

Page 29: cs361-lecture02-1x1

A B C D

0 1 0, 1

1

0

1 0

L = {w | w doesn’t contain 110}d)

L = {w | w contains at most two 1s}a)

L = {w | |w| < 3}b)

L = {w | |w| < 3 or contains at least two 1s}c)

Tuesday, September 15, 2009

Page 30: cs361-lecture02-1x1

A B C D

0 1 0, 1

1

0

1 0

L = {w | w doesn’t contain 110}d)

L = {w | w contains at most two 1s}a)

L = {w | |w| < 3}b)

L = {w | |w| < 3 or contains at least two 1s}c)

Tuesday, September 15, 2009

Page 31: cs361-lecture02-1x1

A B C D

0 1 0, 1

1

0

1 0

L = {w | w doesn’t contain 110}d)

L = {w | w contains at most two 1s}a)

L = {w | |w| < 3}b)

L = {w | |w| < 3 or contains at least two 1s}c)

Tuesday, September 15, 2009

Page 32: cs361-lecture02-1x1

A B C D

0 1 0, 1

1

0

1 0

L = {w | w doesn’t contain 110}d)

L = {w | w contains at most two 1s}a)

L = {w | |w| < 3}b)

L = {w | |w| < 3 or contains at least two 1s}c)

Tuesday, September 15, 2009

Page 33: cs361-lecture02-1x1

What automata recognize these

languages?

Tuesday, September 15, 2009

Page 34: cs361-lecture02-1x1

L = {w | |w| is odd and begins with 0 oris even and begins with 1}

Tuesday, September 15, 2009

Page 35: cs361-lecture02-1x1

L = {w | |w| is odd and begins with 0 oris even and begins with 1}

A B

C

0

1

0, 1

0, 1

Tuesday, September 15, 2009

Page 36: cs361-lecture02-1x1

L = {w | w = ε or every odd position of w is a 1}

Tuesday, September 15, 2009

Page 37: cs361-lecture02-1x1

L = {w | w = ε or every odd position of w is a 1}

A B

C

1

0, 10

0, 1

Tuesday, September 15, 2009

Page 38: cs361-lecture02-1x1

?Tuesday, September 15, 2009

Page 39: cs361-lecture02-1x1

L = {w | w is not the string 11 or 111}

Tuesday, September 15, 2009

Page 40: cs361-lecture02-1x1

L = {w | w is not the string 11 or 111}

A B C D

E

1 1 1

0 00

0, 1

0, 1

Tuesday, September 15, 2009

Page 41: cs361-lecture02-1x1

Definition

1. A language L is regular if some DFA recognizes it.

2. The language L(A) recognized by a DFA A is regular.

Tuesday, September 15, 2009

Page 42: cs361-lecture02-1x1

L1 = {w | |w| is odd and begins with 0 oris even and begins with 1}

L2 = {w | w = ε or every odd position of w is a 1}

Can we build an automaton that accepts:

L3 = L1 ∪ L2

Tuesday, September 15, 2009

Page 43: cs361-lecture02-1x1

L1 = {w | |w| is odd and begins with 0 oris even and begins with 1}

L2 = {w | w = ε or every odd position of w is a 1}

L3 = L1 ∪ L2

A1 B1

C1

0

1

0, 1

0, 1

A2 B2

C2

1

0, 10

0, 1

Tuesday, September 15, 2009

Page 44: cs361-lecture02-1x1

How can we combine two DFAs?

Tuesday, September 15, 2009

Page 45: cs361-lecture02-1x1

Q = {(r1, r2) | r1 ∈ Q1 and r2 ∈ Q2}

Tuesday, September 15, 2009

Page 46: cs361-lecture02-1x1

Q = {(r1, r2) | r1 ∈ Q1 and r2 ∈ Q2}

Σ = Σ1 ∪Σ2

Tuesday, September 15, 2009

Page 47: cs361-lecture02-1x1

Q = {(r1, r2) | r1 ∈ Q1 and r2 ∈ Q2}

Σ = Σ1 ∪Σ2

δ((r1, r2), a) = (δ1(r1, a), δ2(r2, a))

Tuesday, September 15, 2009

Page 48: cs361-lecture02-1x1

Q = {(r1, r2) | r1 ∈ Q1 and r2 ∈ Q2}

Σ = Σ1 ∪Σ2

δ((r1, r2), a) = (δ1(r1, a), δ2(r2, a))

q0 = (q1, q2)

Tuesday, September 15, 2009

Page 49: cs361-lecture02-1x1

Q = {(r1, r2) | r1 ∈ Q1 and r2 ∈ Q2}

Σ = Σ1 ∪Σ2

δ((r1, r2), a) = (δ1(r1, a), δ2(r2, a))

q0 = (q1, q2)

F = {(r1, r2) | r1 ∈ F1 or r2 ∈ F2}

Tuesday, September 15, 2009

Page 50: cs361-lecture02-1x1

A1 B1

C1

0

1

0, 1

0, 1

A2 B2

C2

1

0, 10

0, 1

Tuesday, September 15, 2009

Page 51: cs361-lecture02-1x1

A1A2

B1A2 B1C2

C1B2 C1C2

0

1

10

0, 10, 1

0, 1

Tuesday, September 15, 2009

Page 52: cs361-lecture02-1x1

Regular languages are

closed under union.

if L1 and L2 are regular languagesthen L1 ∪ L2 is a regular language

Tuesday, September 15, 2009

Page 53: cs361-lecture02-1x1

Reading: Sipser 1.1

Tuesday, September 15, 2009

Page 54: cs361-lecture02-1x1

?Tuesday, September 15, 2009

Page 55: cs361-lecture02-1x1

L = {w | w �= ε}

WHATAUTOMATONRECOGNIZES

?

Tuesday, September 15, 2009