Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Finite Automata (Finite State Machine) Lecture 4-5 Ref. Handout p18-24."— Presentation transcript:

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

2 2

3 3 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

4 4 State Transition Table StateEventActionNew State happy work due next weeknonehappy work due tomorrow start workanxious Work cancellednonehappy anxiouswork done hand in workhappy

5 5 State Diagrams when in state A if x happens then we change to state B AB x a state transition

6 6 State Transition Diagram start tomorrow cancelled done next week AnxiousHappy

7 7 A Finite Automata tomorrow cancelled done next week AnxiousHappy

8 8 Components starting state (one per machine) transition d input symbol halting state (one or more) non-halting state

9 9 Sequence of Input Symbols What input sequences leave this FA in its halt state? S1 S2 S3 a b c ac ab abc abac { (ab) n ac | n>=0 } yes no yes { ac, abac, ababac, abababac,... }

10 10 The Original Example... tomorrow cancelled done next week AnxiousHappy Some acceptable inputs nnnntc ntd Λ nntcntd

11 11 Recognising Strings the set of all strings accepted/recognised by an FA = the language accepted/recognised by the FA

12 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 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 14 Recall some simple languages... Can you draw FA to recognise them? { Λ, a, aa, aaa, aaaa,...} = { a n | n >= 0 } { a, aa, aaa, aaaa,...} = { a n | n > 0 } { 00, 01, 10, 11 }

15 15 An Assignment Related Example Draw an FA to recognise non-negative integers Extend it to all integers (i.e. allowing +,- signs)

16 16 Memo for In-class test 4 [ /5] questionsmy answers correct answers comments 1 2 3 4 5

17 17 Non-Deterministic Automata 1 a b c d 43 2 d What happens here? cd cdacd

18 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 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 20 A Simple Example b 1 a ba a 2 3 NFA DFA

21 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 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 23 Last Step 1 a ba a 2 3 NFA 3 is a halt state { 2,3 }{ 1 } b {3}

24 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 25 Building DFAs starthalt Machine A Language L starthalt Machine B Language K

26 26 What does this do? start halt Machine A Language L halt Machine B Language K

27 27 What does this do? start Machine A Language L ??halt Machine B Language K

28 28 What does this do? start Machine A Language L halt

29 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 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 31 What if we need an FA for the union of G and P i.e. G U P b 1-9. j p g a. g i f

32 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. j p g

33 33 What happens now? If we need an FA for the union of G and P. i.e. G U P a 1-9. j p g a. g i f It’s a NFA!

34 34 Limitations of FAs Can you draw an FA to accept this? { a n b n | n > 0 }

35 35 Memo for In-class test 5 [ /5] questionsmy answers correct answers comments 1 2 3 4 5


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

Similar presentations


Ads by Google