Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

16
Finite Automata Course: Theory of Computation Date: Nov 16 th , 2011 Lin Liu lliu AT cs.kent.edu

Transcript of Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Page 1: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Finite Automata

Course: Theory of ComputationDate: Nov 16th, 2011

Lin Liu lliu AT cs.kent.edu

Page 2: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Why finite automata are important?

Many real applications– elevators– coke machines– train track switches– complier design and parsing

Page 3: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Outline

• A Classic RiddleMan, Wolf, Goat and Cabbage

• Definition for Finite Automata (FA)The 5-Tuple

• The Language Accepted by FADefinitionExamples

Page 4: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

A Classic Riddle

• A man travels with wolf, goat and cabbage and wants to cross a river from east to west.

• A rowboat is available, but only large enough for the man plus one possession.

• Wolf eats goat if left alone together.• Goat eats cabbage if left alone together.• How can the man cross without loss?

Page 5: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Solutions As Strings

• Four moves can be encoded as four symbols:– Man crosses with wolf (w)– Man crosses with goat (g)– Man crosses with cabbage (c)– Man crosses with nothing (n)

• Then a sequence of moves is a string, such as the solution gnwgcng:– First cross with goat, then cross back with

nothing, then cross with wolf, …

Page 6: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Transition Diagram• Showing all legal moves

• All reachable states• Start state and goal state

E: W: mwgc

E: mwgc W:

E: wc W: mg g

g E: mwc W: g n

n

E: c W: mwg

E: w W: mgc

E: mgc W: w

E: mgw W: c

E: mg W: wc g

g E: g W: mwc n

n

g g g g

w w c

c

c c w w

Page 7: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

The Language Of Solutions

• Every path gives some x {w,g,c,n}*• The diagram defines the language of

solutions to the problem: {x {w,g,c,n}* | starting in the start state and following the transitions of x ends up in the goal state}

• This is an infinite language• (The two shortest strings in the

language are gnwgcng and gncgwng)

Page 8: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Definition for Finite Automaton

A finite automaton is a 5-tuple (Q, , , q0, F), where– Q is a finite set called the states; is a finite set called the alphabet; : Q x Q is the transition function;

– q0 Q is the start state;

– F Q is the set of accepting states.

Page 9: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

One finite automaton

startstate

accepting state

statetransition

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 10: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

After reading a string s…

• FA accepts the string s, if after reading the last symbol of s, FA ends up in an accepting state;

• FA rejects the string s, if after reading the last symbol of s, FA ends up in a non-accepting state;

• FA crashes, if FA fails during reading s.

Page 11: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Input strings Results

abba Accept

aabb Reject

abbc Crash

Page 12: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

The language accepted by FA

L = {x * | FA accepts x}, where * = 0 + 1 + 2 + … k = All length k strings over the

alphabet .

Page 13: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

Accepted language examples

What is the language accepted by this FA?

a, b

L = {a,b}* = all finite strings of a’s and b’s

Page 14: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

What language is accepted by this machine? a, b

a, b

L=all even length strings containing a’s and b’s

Page 15: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

What language is accepted by this machine?

b

a

a, b

L = All strings in {a, b}* with at least one a.

Page 16: Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.

References

• www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/.../automata.ppt

• Michael Sipser. Introduction to the Theory of Computation, first edition, December 1996

• http://en.wikipedia.org/wiki/Automata_theory

• www.webber-labs.com/fl/lectures/ppt-slides/02.ppt