finite automata – introductionpeople.hsc.edu/faculty-staff/robbk/coms461/lectures... · 2016. 8....

33
Finite Automata – Introduction Lecture 4 Section 2.1 Robb T. Koether Hampden-Sydney College Wed, Aug 31, 2016 Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 1 / 21

Upload: others

Post on 07-Sep-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Finite Automata – IntroductionLecture 4

Section 2.1

Robb T. Koether

Hampden-Sydney College

Wed, Aug 31, 2016

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 1 / 21

Page 2: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Outline

1 An Automaton

2 Definition of a DFA

3 Examples

4 Assignment

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 2 / 21

Page 3: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Outline

1 An Automaton

2 Definition of a DFA

3 Examples

4 Assignment

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 3 / 21

Page 4: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Describe the operation of a canal lock operated so that the gatescan never be opened when the water on the two sides of the gateis not at the same level.

Lower PaddleUpper Paddle

Upper Gate Lower Gate

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 4 / 21

Page 5: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

The working parts of the lock areUpper gateUpper paddleLower gateLower paddle

Each gate or paddle is either open or closed.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 5 / 21

Page 6: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 7: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 8: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 9: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 10: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 11: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 12: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 13: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 14: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 15: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 16: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 17: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 6 / 21

Page 18: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

What are the states?Each gate or paddle is open or closed.So there are 16 conceivable combinations.How many are feasible? (We can never have an upper gate orpaddle open while a lower gate or paddle is open.)Also, the water can he high or low, but that is typically determinedby the state of the gates and paddles.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 7 / 21

Page 19: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

The following table shows the possible states (X = closed, O =open).

State UG UP LG LP Water1 X X X X Low2 X X X X High3 X X X O Low4 X X O X Low5 X X O O Low6 X O X X High7 O X X X High8 O O X X High

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 8 / 21

Page 20: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Draw a state diagram where the actions are(a) Open upper gate.(b) Close upper gate.(c) Open upper paddle.(d) Close upper paddle.(e) Open lower gate.(f) Close lower gate.

(g) Open lower paddle.(h) Close lower paddle.

Show only feasible transitions.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 9 / 21

Page 21: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

The state diagram for the canal lock.

CUG

OUG

CUP

OUPOLP

OUP

CUP CUGOUG

OUP

OLP

OLP

CLP

CLP

OLG

OLGCLG

CLG

Highwater

Lowwater

Both closed

Oneopen

Both open

Upper lock Lower lock

Both closed

Oneopen

Both open

XX

XOOX

OO

XX

XOOX

OO

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 10 / 21

Page 22: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Describe how to move a boat downstream through the lockswhere the initial conditions are

All gates and paddles are closed.The water level is low.

and the final conditions are the same.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 11 / 21

Page 23: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

A Canal Lock

Describe how to move a boat upstream through the locks wherethe initial conditions are

All gates and paddles are closed.The water level is high.

and the final conditions are the same.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 12 / 21

Page 24: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Outline

1 An Automaton

2 Definition of a DFA

3 Examples

4 Assignment

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 13 / 21

Page 25: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Definition of a Finite Automaton

Definition (Deterministic finite automaton)A deterministic finite automaton, written DFA, is a 5-tuple(Q,Σ, δ,q0,F ), where

Q is a finite set of states,Σ is a finite alphabet,δ : Q × Σ→ Q is the transition function,q0 ∈ Q is the start state, andF ⊆ Q is the set of accept states.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 14 / 21

Page 26: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Outline

1 An Automaton

2 Definition of a DFA

3 Examples

4 Assignment

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 15 / 21

Page 27: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Examples

Example (Definition of a DFA)Describe the canal locks formally.

Let the start and end states be that the gates and paddles areclosed and the water is low.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 16 / 21

Page 28: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Definition (Language of a DFA)The language of a DFA M is the set of all strings that are accepted bythat language.

L(M) = {w ∈ Σ∗ | M accepts w}.

Definition (Regular language)A language L is regular if there exists a DFA M such that L = L(M).

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 17 / 21

Page 29: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Examples

Example (Examples)Design DFAs that will recognize the following regular languages overΣ = {a,b}.

All strings that start with a.All strings that end with a.All strings that contain aaa.All strings in which each a is followed immediately by b.All strings that contain aba or bab.All strings that contain aba and bab.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 18 / 21

Page 30: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Examples

Example (Binary Addition)Design a DFA that will recognize mathematically correct binaryaddition problems.For example:

101100010011010

The input symbols are triples of binary digits (000, 001, 010, etc.),representing the columns.Read the columns from right to left.

Can we also process them from left to right with a DFA?

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 19 / 21

Page 31: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Examples

Example (Binary Addition)Design a DFA that will recognize mathematically correct binaryaddition problems.For example:

101100010011010

The input symbols are triples of binary digits (000, 001, 010, etc.),representing the columns.Read the columns from right to left.Can we also process them from left to right with a DFA?

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 19 / 21

Page 32: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Outline

1 An Automaton

2 Definition of a DFA

3 Examples

4 Assignment

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 20 / 21

Page 33: Finite Automata – Introductionpeople.hsc.edu/faculty-staff/robbk/Coms461/Lectures... · 2016. 8. 31. · Definition of a Finite Automaton Definition (Deterministic finite automaton)

Assignment

AssignmentSection 2.1 Exercises 1, 2, 3, 4bc, 7ef, 8a.

Robb T. Koether (Hampden-Sydney College) Finite Automata – Introduction Wed, Aug 31, 2016 21 / 21