Finite Automata (Finite State Machine)

Preview:

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

1

Finite Automata

(Finite State Machine)

Lecture 4-5

Ref. Handout p18-24

2

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

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

5

State Diagrams

when in state A if x happens then

we change to state B

A Bx

a state transition

6

State Transition Diagram

starttomorrow

cancelled

done

next week

AnxiousHappy

7

A Finite Automata

tomorrow

cancelled

donenext week

AnxiousHappy

8

Components

starting state (one per machine)

transition

d

input

symbol

halting

state

(one or

more)

non-halting

state

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

10

The Original Example ...

tomorrow

cancelled

donenext week

AnxiousHappy

Some

acceptable

inputs

nnnntc

ntd

Λ

nntcntd

11

Recognising Strings

the set of all strings accepted/recognised by an FA

=

the language accepted/recognised by the FA

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

13

Rejected / Accepted Strings

t

c

d n

AnxiousHappy

tdnnn yes/no

tdnnt yes/no

n yes/no

ntc yes/no

ntcd yes/no

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 }

15

An Assignment Related Example

Draw an FA to recognise non-negative integers

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

16

Memo for In-class test 4 [ /5]

questions my answers

correct answers

comments

1

2

3

4

5

17

Non-Deterministic Automata

1

a

b

c

d43

2

d

What happens

here?

cd

cdacd

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.

19

Deterministic FAs and Non-Deterministic FAs

For every

non-deterministic FA (NFA)

there is a

deterministic FA (DFA)

which accepts

the same language

20

A Simple Example

b

1

a

ba

a

2

3

NFA

DFA

21

Step by Step (1)

1

a

ba

a

2

3

NFA

after ‘a’, must be in

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

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}

23

Last Step

1

a

ba

a

2

3

NFA

3 is a halt state

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

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

25

Building DFAs

start haltMachine A

Language L

start haltMachine B

Language K

26

What does this do?

start

haltMachine A

Language L

haltMachine B

Language K

27

What does this do?

startMachine A

Language L

?? haltMachine B

Language K

28

What does this do?

startMachine A

Language Lhalt

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, .... }

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, .... }

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

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

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!

34

Limitations of FAs

Can you draw an FA to accept this?

{ anbn | n > 0 }

35

Memo for In-class test 5 [ /5]

questions my answers

correct answers

comments

1

2

3

4

5

Recommended