finiteautomata - clemson universitygoddard/texts/... · finiteautomata a finite automaton has a...

22
Finite Automata A finite automaton has a finite set of states with which it accepts or rejects strings.

Upload: letram

Post on 23-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Finite Automata

A finite automaton has a finite set of states withwhich it accepts or rejects strings.

Page 2: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

A Finite Automaton

An FA has three components:

1. input tape contains single string;

2. head reads input string one symbol at a time;and

3. Memory is in one of a finite number of states.

Goddard 1: 2

Page 3: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Operating an FA

Operating an FA.1) Set the machine to start state.2) If End-of-String then halt.3) Read a symbol.4) Update state according to current state andsymbol read.5) Goto Step 2.

Goddard 1: 3

Page 4: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

An FA Accepts Strings

“Program” prescribes how symbols read affectcurrent state.

Final state is state FA is in when finished read-ing the input string.

There are accept states (double circle) and re-ject states.

An FA accepts input string if final state is ac-cept state; otherwise it rejects.

Goddard 1: 4

Page 5: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

An Example FA

A B C

1

0

1

00

1

Final state for 101001 is C, final state for 11101is A.

Goddard 1: 5

Page 6: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Example FA

A B

0

1

1

0

Accepts all strings of 0’s and 1’s with odd num-ber of 1’s.

Goddard 1: 6

Page 7: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Terminology

alphabet is a set of symbols (often denoted Σ)

language is a set of strings (unary languagemeans |Σ| = 1)

language of FA is the set of strings it accepts

length of a string is the number of symbols

empty string is denoted ε.

Goddard 1: 7

Page 8: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Do the Obvious

Starts with 00:

Goddard 1: 8

Page 9: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Do the Obvious

Starts with 00:

A B C

D

0 00, 1

11

0, 1

Goddard 1: 9

Page 10: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Recent Memory

Ends with 00:

Goddard 1: 10

Page 11: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Recent Memory

Ends with 00:

A B C

1

0

1

00

1

Goddard 1: 11

Page 12: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Traps

A trap is state that, once entered, one can neverleave. Used to reject partly read strings thatwill never be accepted, or to accept partly readstrings that will definitely be accepted.

Goddard 1: 12

Page 13: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Example with a Trap

Alternating 0’s and 1’s:

Goddard 1: 13

Page 14: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Example with a Trap

Alternating 0’s and 1’s:

A

B

C

D

E

F

0

1

0

0

1

1

0

1

1

00, 1

Goddard 1: 14

Page 15: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Alternating 0’s and 1’s again

A

B D

F

0 1

1

00 1

0, 1

Goddard 1: 15

Page 16: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Permanent Memory

An FA remembers permanently by splitting intopieces. Here is one for first and last bit thesame:

Goddard 1: 16

Page 17: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Building FAs: Permanent Memory

An FA remembers permanently by splitting intopieces. Here is one for first and last bit thesame:

S

A B

C D

0

1

1

0

1

0

0

1

0

1

Goddard 1: 17

Page 18: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Practice

Give FAs for each of the following three lan-guages:

1. All binary strings with at least one 0

2. All binary strings with at most one 0

3. All binary strings starting and ending with 0(and single-0 string counts)

Goddard 1: 18

Page 19: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Solutions to Practice

1)A B

00, 1

1

2)

A B C0

11

00, 1

3) A B C

D

0

1

0, 1

1

0

0

1

Goddard 1: 19

Page 20: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Transition Table

A transition table is matrix that lists new stategiven current state and symbol read.

Here’s transition table for FA for all binary stringsthat begin and end with same symbol.

Sta

teInput0 1

S A CA A BB A BC D CD D C

Goddard 1: 20

Page 21: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Formal Definition

A (deterministic) FA is 5-tuple(Q,Σ, q0, T, δ) where:

•Q is finite set of states;

• Σ is alphabet of input symbols;

• q0 is start state;

• T is subset of Q giving the accept states; and

• δ is transition function that maps state andsymbol to state. (Mathematically, δ:Q × Σ 7→Q.)

Goddard 1: 21

Page 22: FiniteAutomata - Clemson Universitygoddard/texts/... · FiniteAutomata A finite automaton has a finite set of states with which it accepts or rejects strings. A Finite Automaton

Summary

A finite automaton (FA) is a device that recog-nizes a language (set of strings). It has finitememory and an input tape; each input symbolthat is read causes the machine to update itsstate based on its current state and the symbolread. The machine accepts the input if it is inan accept state at the end of the string; other-wise, the input is rejected.

Goddard 1: 22