35
1 Finite Automata (Finite State Machine) Lecture 4-5 Ref. Handout p18-24

Finite Automata (Finite State Machine)

  • Upload
    hilde

  • View
    164

  • Download
    3

Embed Size (px)

DESCRIPTION

Finite Automata (Finite State Machine). Lecture 4-5 Ref. Handout p18-24. Controlling Things. If x has happened thendo something If in state y thendo something change to new state If x happened while in state y do something change to new state. State Transition Table. - PowerPoint PPT Presentation

Citation preview

Page 1: Finite Automata (Finite State Machine)

1

Finite Automata

(Finite State Machine)

Lecture 4-5

Ref. Handout p18-24

Page 2: Finite Automata (Finite State Machine)

2

Page 3: Finite Automata (Finite State Machine)

3

Controlling Things ...

If x has happened then do something

If in state y then do somethingchange to new state

If x happened while in state ydo somethingchange to new state

Page 4: Finite Automata (Finite State Machine)

4

State Transition Table

State Event Action New State

happy

work due

next week none happy

happy

work due

tomorrow

start

work anxious

anxious

Work

cancelled none happy

anxious work done

hand in

work happy

Page 5: Finite Automata (Finite State Machine)

5

State Diagrams

when in state A if x happens then

we change to state B

A Bx

a state transition

Page 6: Finite Automata (Finite State Machine)

6

State Transition Diagram

starttomorrow

cancelled

done

next week

AnxiousHappy

Page 7: Finite Automata (Finite State Machine)

7

A Finite Automata

tomorrow

cancelled

donenext week

AnxiousHappy

Page 8: Finite Automata (Finite State Machine)

8

Components

starting state (one per machine)

transition

d

input

symbol

halting

state

(one or

more)

non-halting

state

Page 9: Finite Automata (Finite State Machine)

9

Sequence of Input Symbols

What input sequences leave this FA in its halt state?

S1S2

S3

a

b

c ac ab abc abac

{ (ab)nac | n>=0 }

yes

no

no

yes

{ ac, abac, ababac, abababac, ... }

Rong Yang
ac/ab/abc/abac
Page 10: Finite Automata (Finite State Machine)

10

The Original Example ...

tomorrow

cancelled

donenext week

AnxiousHappy

Some

acceptable

inputs

nnnntc

ntd

Λ

nntcntd

Page 11: Finite Automata (Finite State Machine)

11

Recognising Strings

the set of all strings accepted/recognised by an FA

=

the language accepted/recognised by the FA

Page 12: Finite Automata (Finite State Machine)

12

Rejecting Strings

An FA rejects a string if

with some symbols remaining

there is no transition for the next symbol

or

with no symbols remaining

the FA is not in a halt state

Page 13: Finite Automata (Finite State Machine)

13

Rejected / Accepted Strings

t

c

d n

AnxiousHappy

tdnnn yes/no

tdnnt yes/no

n yes/no

ntc yes/no

ntcd yes/no

Page 14: Finite Automata (Finite State Machine)

14

Recall some simple languages ...Can you draw FA to recognise them?{ Λ, a, aa, aaa, aaaa, ...}

= { an | n >= 0 }

{ a, aa, aaa, aaaa, ...}

= { an | n > 0 }

{ 00, 01, 10, 11 }

Page 15: Finite Automata (Finite State Machine)

15

An Assignment Related Example

Draw an FA to recognise non-negative integers

Extend it to all integers (i.e. allowing +,- signs)

Page 16: Finite Automata (Finite State Machine)

16

Memo for In-class test 4 [ /5]

questions my answers

correct answers

comments

1

2

3

4

5

Page 17: Finite Automata (Finite State Machine)

17

Non-Deterministic Automata

1

a

b

c

d43

2

d

What happens

here?

cd

cdacd

Page 18: Finite Automata (Finite State Machine)

18

Non-Deterministic Automata

In deterministic automata, there can never be two transitions to different state for the same input symbol.

If there are more than one transition to different states for the same input symbol, we call it a non-deterministic automata.

Page 19: Finite Automata (Finite State Machine)

19

Deterministic FAs and Non-Deterministic FAs

For every

non-deterministic FA (NFA)

there is a

deterministic FA (DFA)

which accepts

the same language

Page 20: Finite Automata (Finite State Machine)

20

A Simple Example

b

1

a

ba

a

2

3

NFA

DFA

Page 21: Finite Automata (Finite State Machine)

21

Step by Step (1)

1

a

ba

a

2

3

NFA

after ‘a’, must be in

state 2 or 3{ 2,3 }{ 1 }

Page 22: Finite Automata (Finite State Machine)

22

Step by Step (2)

1

a

ba

a

2

3

NFA

from state 2, read

‘b’, move to state 3

{ 2,3 }{ 1 } b {3}

Page 23: Finite Automata (Finite State Machine)

23

Last Step

1

a

ba

a

2

3

NFA

3 is a halt state

{ 2,3 }{ 1 } b {3}

Page 24: Finite Automata (Finite State Machine)

24

A General Algorithm

1. Write down {1} as the start state of the DFA

2. Choose a state in the DFA which hasn’t been processed

3. Work out all transitions from it adding new states

4. Repeat from step 2 until all states have been processed

5. Mark halting states

Page 25: Finite Automata (Finite State Machine)

25

Building DFAs

start haltMachine A

Language L

start haltMachine B

Language K

Page 26: Finite Automata (Finite State Machine)

26

What does this do?

start

haltMachine A

Language L

haltMachine B

Language K

Page 27: Finite Automata (Finite State Machine)

27

What does this do?

startMachine A

Language L

?? haltMachine B

Language K

Page 28: Finite Automata (Finite State Machine)

28

What does this do?

startMachine A

Language Lhalt

Page 29: Finite Automata (Finite State Machine)

29

Using Building Blocks

For example, you are asked to define a format for a collection of pictures’ file names

G = { a1.gif, a2.gif, a3.gif, ... a33.gif, .... }

Page 30: Finite Automata (Finite State Machine)

30

Using Building Blocks

Now you are asked to define a format for another collection of pictures’ file names

P = { b1.jpg, b2.jpg, b3.jpg, ... b33.jpg, .... }

Page 31: Finite Automata (Finite State Machine)

31

What if we need an FA for the union of G and P i.e. G U P

b 1-9 1-9

.j p g

a 1-91-9.

g i f

Page 32: Finite Automata (Finite State Machine)

32

Using Building Blocks

Let’s change the language P to

P = { a1.jpg, a2.jpg, a3.jpg, ... a33.jpg, .... }

(replace ‘b’ by ‘a’)

a 1-9 1-9

.j p g

Page 33: Finite Automata (Finite State Machine)

33

What happens now? If we need an FA for the union of G and P. i.e. G U P

a 1-9 1-9

.j p g

a 1-91-9.

g i f

It’s a NFA!

Page 34: Finite Automata (Finite State Machine)

34

Limitations of FAs

Can you draw an FA to accept this?

{ anbn | n > 0 }

Page 35: Finite Automata (Finite State Machine)

35

Memo for In-class test 5 [ /5]

questions my answers

correct answers

comments

1

2

3

4

5