finite automata - stanford university · finite automata (this week) are an abstraction of...

221
Finite Automata Part One Problem Set Four checkpoint due in the box up front. Late Problem Set Three's also due up front. Problem Set Four checkpoint due in the box up front. Late Problem Set Three's also due up front.

Upload: others

Post on 12-Mar-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Finite AutomataPart One

Problem Set Four checkpoint due in the box up front. Late Problem Set Three's

also due up front.

Problem Set Four checkpoint due in the box up front. Late Problem Set Three's

also due up front.

Page 2: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Last Thoughts on First-Order Logic

Page 3: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

An Extremely Important Table

For any choice of x,P(x) ∃x. ¬P(x)

When is this true? When is this false?

For some choice of x,P(x) ∀x. ¬P(x)

For any choice of x,¬P(x) ∃x. P(x)

For some choice of x,¬P(x) ∀x. P(x)

∀x. P(x)

∃x. P(x)

∀x. ¬P(x)

∃x. ¬P(x)

Page 4: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Negating First-Order Statements

● Use the equivalences

¬∀x. φ ≡ ∃x. ¬φ

¬∃x. φ ≡ ∀x. ¬φ

to negate quantifiers.● Mechanically:

● Push the negation across the quantifier.● Change the quantifier from ∀ to ∃ or vice-versa.

● Use techniques from propositional logic to negate connectives.

Page 5: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Analyzing Relations

“R is a binary relation over set A that is not reflexive”

¬∀a ∈ A. aRa∃a ∈ A. ¬aRa

“Some a ∈ A is not related to itself by R.”

Page 6: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Analyzing Relations

“R is a binary relation over A that is not antisymmetric”

¬∀x ∈ A. ∀y ∈ A. (xRy ∧ yRx → x = y)∃x ∈ A. ¬∀y ∈ A. (xRy ∧ yRx → x = y)∃x ∈ A. ∃y ∈ A. ¬(xRy ∧ yRx → x = y)

∃x ∈ A. ∃y ∈ A. (xRy ∧ yRx ∧ ¬(x = y))∃x ∈ A. ∃y ∈ A. (xRy ∧ yRx ∧ x ≠ y)

“Some x ∈ A and y ∈ A are related to one another by R, but are not equal”

Page 7: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Useful Equivalence

● The following equivalences are useful when negating statements in first-order logic:

¬(p ∧ q) ≡ p → ¬q

¬(p → q) ≡ p ∧ ¬q● These identities are useful when negating

statements involving quantifiers.● ∧ is used in existentially-quantified statements.● → is used in universally-quantified statements.

Page 8: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Negating Quantifiers

● What is the negation of the following statement?

∃x. (Puppy(x) ∧ Cute(x))● We can obtain it as follows:

¬∃x. (Puppy(x) ∧ Cute(x))

∀x. ¬(Puppy(x) ∧ Cute(x))

∀x. (Puppy(x) → ¬Cute(x))● “All puppies are not cute.”

Page 9: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Uniqueness

Page 10: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Uniqueness

● Often, statements have the form “there is a unique x such that …”

● Some sources use a uniqueness quantifier to express this:

∃!n. P(n)● However, it's possible to encode uniqueness

using just the two quantifiers we've seen.

∃!n. P(n) ≡ ∃n. (P(n) ∧ ∀m. (P(m) → m = n))

In CS103, do not use the ∃! quantifier. Just use ∃ and ∀. And whenever P is

true, it must be for n.

And whenever P is true, it must be for n.

There is some n where P(n) is true

There is some n where P(n) is true

Page 11: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Uniqueness

● Often, statements have the form “there is a unique x such that …”

● Some sources use a uniqueness quantifier to express this:

∃!n. P(n)● However, it's possible to encode uniqueness

using just the two quantifiers we've seen.

∃!n. P(n) ≡ ∃n. (P(n) ∧ ∀m. (P(m) → m = n))● In CS103, do not use the ∃! quantifier. Just use

∃ and ∀.

Page 12: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Summary of First-Order Logic

● Predicates allow us to reason about different properties of the same object.

● Functions allow us to transform objects into one another.

● Quantifiers allow us to reason about properties of some or all objects.

● There are many useful identities for negating first-order formulae.

Page 13: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

An Important Milestone

Page 14: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recap: Discrete Mathematics

● The past four weeks have focused exclusively on discrete mathematics:

Induction Functions

Graphs The Pigeonhole Principle

Relations Logic

Set Theory Cardinality

● These are the building blocks we will use throughout the rest of the quarter.

● These are the building blocks you will use throughout the rest of your CS career.

Page 15: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Next Up: Computability Theory

● It's time to switch gears and address the limits of what can be computed.

● We'll explore● What is the formal definition of a computer?● What might computers look like with various resource

constraints?● What problems can be solved by computers?● What problems can't be solved by computers?

● Get ready to explore the boundaries of what computers could ever be made to do.

Page 16: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computability Theory

Page 17: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What problems can we solve with a computer?

Page 18: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What problems can we solve with a computer?

What kind of computer?

Page 19: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computers are Messy

http://www.intel.com/design/intarch/prodbref/272713.htm

Page 20: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

http://www.dharmanitech.com/

Computers are Messy

Page 21: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computers are Messy

http://techon.nikkeibp.co.jp/article/HONSHI/20090119/164259/

Page 22: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computers are Messy

http://en.wikipedia.org/wiki/File:Eniac.jpg

Page 23: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

We need a simpler way of discussing computing machines.

Page 24: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

An automaton (plural: automata) is a mathematical model of a computing device.

Page 25: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computers are Messy

http://www.intel.com/design/intarch/prodbref/272713.htm

Page 26: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Automata are Clean

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 27: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

http://www.dharmanitech.com/

Computers are Messy

Page 28: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Automata are Clean

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 29: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computers are Messy

http://techon.nikkeibp.co.jp/article/HONSHI/20090119/164259/

Page 30: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Automata are Clean

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 31: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Computers are Messy

http://en.wikipedia.org/wiki/File:Eniac.jpg

Page 32: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Automata are Clean

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 33: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Why Build Models?

● The models of computation we will explore in this class correspond to different conceptions of what a computer could do.

● Finite automata (this week) are an abstraction of computers with finite resource constraints.● Provide upper bounds for the computing machines

that we can actually build.

● Turing machines (later) are an abstraction of computers with unbounded resources.● Provide upper bounds for what we could ever hope

to accomplish.

Page 34: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What problems can we solve with a computer?

Page 35: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What problems can we solve with a computer?

What is a “problem?”

Page 36: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Strings

● An alphabet is a finite set of characters.● Typically, we use the symbol Σ to refer to an

alphabet.

● A string is a finite sequence of characters drawn from some alphabet.

● Example: If Σ = {a, b}, some valid strings include

● a

● aabaaabbabaaabaaaabbb

● abbababba

● The empty string contains no characters and is denoted ε.

Page 37: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Languages

● A formal language is a set of strings.● We say that L is a language over Σ if it is a

set of strings formed from characters in Σ.● Example: The language of palindromes over

Σ = {a, b, c} is the set

{ε, a, b, c, aa, bb, cc, aaa, aba, aca, bab, … }

● The set of all strings composed from letters in Σ is denoted Σ*.

● Formally: L is a language over Σ iff L ⊆ Σ*.

Page 38: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

The Model

● Goal: Given an alphabet Σ and a language L over Σ, can we build an automaton that can determine which strings are in L?

● Actually a very expressive and powerful framework; we'll see this over the next few weeks.

Page 39: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

To Summarize

● An automaton is an idealized mathematical computing machine.

● A language is a set of strings.● The automata we will study will accept as

input a string and (attempt to) output whether that string is contained in a particular language.

Page 40: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What problems can we solve with a computer?

Page 41: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Finite Automata

Page 42: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A finite automaton is a mathematical machine for determining whether a string

is contained within some language.

Page 43: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Each finite automaton consists of a setof states connected by transitions.

Page 44: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 45: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

Each circle represents a state of the automaton.

Each circle represents a state of the automaton.

Page 46: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 47: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

One special state is designated as the

start state.

One special state is designated as the

start state.

Page 48: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 49: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 50: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 0

The automaton is run on an input string and answers

“yes” or “no.”

The automaton is run on an input string and answers

“yes” or “no.”

0 1 0 1 1 0

Page 51: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 52: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 53: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 0

The automaton can be in one state at a time. It begins in the start state.

The automaton can be in one state at a time. It begins in the start state.

0 1 0 1 1 0

Page 54: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 55: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 56: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

The automaton now begins processing characters in the

order in which they appear.

The automaton now begins processing characters in the

order in which they appear.

Page 57: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 58: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 59: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Each arrow in this diagram represents a transition. The automaton always

follows the transition corresponding to the current symbol being

read.

Each arrow in this diagram represents a transition. The automaton always

follows the transition corresponding to the current symbol being

read.

Page 60: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 61: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 62: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 63: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 64: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 0

After transitioning, the automaton

considers the next symbol in the

input.

After transitioning, the automaton

considers the next symbol in the

input.

0 1 0 1 1 0

Page 65: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 66: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 67: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 68: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 69: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 70: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 71: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 72: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 73: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 74: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 75: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 76: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 77: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 78: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 79: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 80: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 81: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 82: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 83: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 84: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 85: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Page 86: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 00 1 0 1 1 0

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

Page 87: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 0

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

The double circle indicates that this

state is an accepting state, so the automaton outputs “yes.”

The double circle indicates that this

state is an accepting state, so the automaton outputs “yes.”

Page 88: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 0

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

The double circle indicates that this

state is an accepting state, so the automaton outputs “yes.”

The double circle indicates that this

state is an accepting state, so the automaton outputs “yes.”

Page 89: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

0 1 0 1 1 0

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

Now that the automaton has

looked at all this input, it can decide whether to say “yes”

or “no.”

The double circle indicates that this

state is an accepting state, so the automaton outputs “yes.”

The double circle indicates that this

state is an accepting state, so the automaton outputs “yes.”

Page 90: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 91: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 92: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 93: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 94: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 95: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 96: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 97: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 98: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 99: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 100: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 101: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 102: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 103: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 104: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 105: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 106: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 107: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 108: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 109: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 110: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 111: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 112: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 113: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 114: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 115: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 116: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 117: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

Page 118: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

This state is not an accepting state, so the automaton

says “no.”

This state is not an accepting state, so the automaton

says “no.”

Page 119: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

This state is not an accepting state, so the automaton

says “no.”

This state is not an accepting state, so the automaton

says “no.”

Page 120: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 0 1 0 0 0

This state is not an accepting state, so the automaton

says “no.”

This state is not an accepting state, so the automaton

says “no.”

Page 121: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 122: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Simple Finite Automaton

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

1 1 0 1 1 1 0 0

Try it yourself! Does the

automaton accept (say yes) or

reject (say no)?

Try it yourself! Does the

automaton accept (say yes) or

reject (say no)?

Page 123: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

The Story So Far

● A finite automaton is a collection of states joined by transitions.

● Some state is designated as the start state.

● Some states are designated as accepting states.

● The automaton processes a string by beginning in the start state and following the indicated transitions.

● If the automaton ends in an accepting state, it accepts the input.

● Otherwise, the automaton rejects the input.

Page 124: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Time-Out For Announcements

Page 125: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Midterm Exam

● Midterm is October 29 from 7PM – 10PM.● Location information TBA.● Need to take the exam at an alternate time? Fill

out the alternate time form ASAP.● Covers material up through and including DFAs.

● Two practice exams available online.● Handout: Exam Strategies and Policies

available online.● Review session later this week; more details

on Wednesday.

Page 126: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Your Questions

Page 127: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

“Keith, why did you choose to go into academia as opposed to industry? Do you

have any advice for students deciding between the two?”

Page 128: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

“What do you think is the coolest real-world application of CS103-related

material?”

Page 129: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

“Why are you taking away the Checkpoint problems... don't?”

Page 130: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Back to CS103!

Page 131: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 132: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 133: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 134: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 135: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 136: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 137: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 138: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 139: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 140: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 141: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 142: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 143: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 144: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Accepting States, Revisited

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

1 1 0 1

Page 145: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A finite automaton does not accept as soon as the input enters an accepting state.

A finite automaton accepts if it ends in an accepting state.

Page 146: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 147: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 148: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 149: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 150: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 151: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 152: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 153: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

No matter where we start in the automaton, after seeing two 1's, we end up in accepting

state q3.

No matter where we start in the automaton, after seeing two 1's, we end up in accepting

state q3.

Page 154: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 155: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 156: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 157: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 158: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 159: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 160: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

No matter where we start in the automaton, after seeing two 0's, we end up in accepting

state q5.

No matter where we start in the automaton, after seeing two 0's, we end up in accepting

state q5.

Page 161: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 162: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

What Does This Accept?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

This automaton accepts a string iff it ends in 00 or 11.

This automaton accepts a string iff it ends in 00 or 11.

Page 163: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

The language of an automaton is the set of strings that it accepts.

If D is an automaton, we denote the language of D as ℒ(D).

ℒ(D) = { w ∈ Σ* | D accepts w }

Page 164: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0

Page 165: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 166: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 167: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 168: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 169: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 170: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 171: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 172: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

A Small Problem

q0

q1

0

start

q2 1

0 0 1 1 0

Page 173: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1startq1

0

0, 1

0, 1

Page 174: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 175: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 176: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 177: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 178: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 179: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 180: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Another Small Problem

q0

q2

0, 1start

0 0 0

q1

0

0, 1

0, 1

Page 181: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

The Need for Formalism

● In order to reason about the limits of what finite automata can and cannot do, we need to formally specify their behavior in all cases.

● All of the following need to be defined or disallowed:● What happens if there is no transition out of

a state on some input?● What happens if there are multiple

transitions out of a state on some input?

Page 182: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

DFAs

● A DFA is a● Deterministic● Finite● Automaton

● DFAs are the simplest type of automaton that we will see in this course.

Page 183: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

DFAs, Informally

● A DFA is defined relative to some alphabet Σ.

● For each state in the DFA, there must be exactly one transition defined for each symbol in the alphabet.● This is the “deterministic” part of DFA.

● There is a unique start state.● There are zero or more accepting states.

Page 184: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 185: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0 q1

q2q3

0

1

0

1

0

1 1

0

start

q2

Page 186: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 187: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0

q2

0

start

q5

0

0

q1

q3

1

1

1

0

1

0 1

Page 188: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 189: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0

q1

0

start

q2 1

0

Page 190: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0

q1

0

start

q2 1

0

Page 191: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 192: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0 q10, 1start

q3

0, 10, 1

q20, 1

Page 193: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 194: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0

q2

0, 1startq1

0

0, 1

0, 1

Page 195: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

q0

q2

0, 1startq1

0

0, 1

0, 1

Page 196: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 197: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Page 198: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Is this a DFA?

Drinking Family of Aardvarks

Page 199: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Designing DFAs

● At each point in its execution, the DFA can only remember what state it is in.

● DFA Design Tip: Build each state to correspond to some piece of information you need to remember.● Each state acts as a “memento” of what

you're supposed to do next.● Only finitely many different states ≈ only

finitely many different things the machine can remember.

Page 200: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

Page 201: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

start

Page 202: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

start

1

Page 203: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1

0

1

Page 204: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1

0

1

1

Page 205: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1 q2

0 0

1

1

Page 206: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1 q2

0 0

1

1

Page 207: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1 q2

0 0

1

1

0, 1

Page 208: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1 q2

0 0

1

1

0, 1

Page 209: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1 q2

0 0

1

1

Σ

Page 210: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}* | w contains 00 as a substring }

q0

startq1 q2

0 0

1

1

Σ

Page 211: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

Page 212: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

YES

010001

0101010001

NO

1001

00001

Page 213: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

Page 214: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

start

Page 215: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

startq1

0

Page 216: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

startq1

0

Σ

Page 217: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

startq1

q2

0

1 Σ

Page 218: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

startq1

q2

0

1 Σ

Σ

Page 219: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

States like these are called dead

states.

States like these are called dead

states.

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

startq1

q2

0

1 Σ

Σ

Page 220: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Recognizing Languages with DFAs

L = { w ∈ {0, 1}*| every other character of w, starting with the first character, is 0 }

q0

startq1

q2

0

1 Σ

Σ

q0 q1

Page 221: Finite Automata - Stanford University · Finite automata (this week) are an abstraction of computers with finite resource constraints. Provide upper bounds for the computing machines

Next Time

● Regular Languages● What is the expressive power of DFAs?

● NFAs● Automata with magic superpowers!

● Nondeterminism● Nondeterminisic computation.● Intuitions for nondeterminism.● Programming with nondeterminism.