1 12/17/2015 math 224 – discrete mathematics deterministic finite automata finite state machines...

8
1 08/26/22 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0 Q Accepting States qf Q Alphabet e.g, {0, 1} Transitions (, qi) qj q0 qf 1 qf 2 q 1 q 2 q 3 q i q j

Upload: hilary-walsh

Post on 18-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

104/21/23

MATH 224 – Discrete Mathematics

Deterministic Finite AutomataFinite State Machines

Set of States Q

Start State q0 Q

Accepting States qf Q

Alphabet e.g, {0, 1}

Transitions (, qi) qj

q0

qf1 qf2

q1 q2 q3

qi qj

Page 2: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

204/21/23

MATH 224 – Discrete Mathematics

DFA Represented by a Directed Graph

Multitasking in an operating System

Ready Queue Running

Start

Blocked Waiting

Time slice expired

Dequeued

Blocked waiting for a resource, e.g. data from a disk

Finished with resource and ready to run

Page 3: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

304/21/23

MATH 224 – Discrete MathematicsDFA for Multiples of 3 in binary

q0

qf-3

q2

q1

0

1

0

1

0

1

1

Start

0

Example 1

46 remainder 1

string 1 0 1 1 1 0

States 0 1 2 2 2 2 1

Example 2

51 remainder 0

string 1 1 0 0 1 1

States 0 1 3 3 3 1 3

Page 4: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

404/21/23

MATH 224 – Discrete MathematicsDFA to Recognize Floating Point

q0

qf-0

q1

0 - 9

+, – 0 - 9 e, E

q2

q3 +, –

0 - 9 0 - 9

0 - 9

q4Qf-1

q5

Start 0 - 9

. 0 - 9

Page 5: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

504/21/23

MATH 224 – Discrete MathematicsCrossing the Bridge in Minimum Time 1, 2, 5 and 10 minutes

q0

q1

q2q3

q13

q7

Start

1 & 2

1 & 5 1&10q4

q6

q52 &10

2 & 5

5 &10

1

q8

2

q9

5q10

1

q11 q12

5 &10

qf142

2 minutes

3 minutes

13 minutes

15 minutes 17 minutes1 & 2

5 minutes

6 minutes

q151 &10 16 minutes

q161

17 minutes

qf17

1 & 2

19 minutes

Only 2 of the final states are shown here, one of the two shortest and one of the next shortest.What would the longest time be?

Page 6: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

604/21/23

MATH 224 – Discrete Mathematics

Other DFAs

Construct a DFA that recognizes legal identifier names in C++ using α to represent letters and δ to represent the digits 0 through 9.

Construct a DFA to recognize even numbers in binary.

Construct a DFA to recognize multiples of four in binary.

Construct a DFA to recognize multiples of 5 in binary.

Construct a DFA to recognize multiples of 5 in decimal.

Page 7: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

704/21/23

MATH 224 – Discrete MathematicsRepresenting a DFA in a Computer Program

Probably the simplest way to represent a DFA in a program is to use a 2-dimensional array, where each column corresponds to a character in the alphabet and each row corresponds to a state. So for example here is the DFA that recognizes multiples of 3 in binary.

0 1 Blank

0 3 1 Halt

1 3 2 Halt

2 1 2 Halt

3 3 1 Halt

qf-3

Page 8: 1 12/17/2015 MATH 224 – Discrete Mathematics Deterministic Finite Automata Finite State Machines Set of States Q Start State q0  Q Accepting Statesqf

804/21/23

MATH 224 – Discrete MathematicsDFA for Multiples of 6 in binary

q0

q3

q2

q1

0

1

0

0

1

1

Start

0

qf-6 0

1 1