Nondeterministic Finite Automata CSCI 3130 Formal Languages and - - PowerPoint PPT Presentation

nondeterministic finite automata
SMART_READER_LITE
LIVE PREVIEW

Nondeterministic Finite Automata CSCI 3130 Formal Languages and - - PowerPoint PPT Presentation

Nondeterministic Finite Automata CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Fall 2018 Chinese University of Hong Kong 1/22 Example from last lecture with a simpler solution q 2 0 1 0 or q 0 q 1 0 1 1 1 0 0 1 Three


slide-1
SLIDE 1

Nondeterministic Finite Automata

CSCI 3130 Formal Languages and Automata Theory

Siu On CHAN Fall 2018

Chinese University of Hong Kong 1/22

slide-2
SLIDE 2

Example from last lecture with a simpler solution

Construct a DFA over {0, 1} that accepts all strings ending in 01

qε q0 q1 q00 q01 q10 q11 1 1 1 1 1 1 1

  • r

q0 q1 q2 1 1 1

Three weeks later: DFA minimization

2/22

slide-3
SLIDE 3

Another example from last lecture

Construct a DFA over {0, 1} that accepts all strings ending in 101

  • r

q0 q1 q2 q2 1 1 1 1

3/22

slide-4
SLIDE 4

String matching DFAs

Ending in 01 q0 q1 q2 1 1 1 Ending in 101 q0 q1 q2 q2 1 1 1 1 Fast string matching algorithms to turn a pattern into a string matching DFA and execute the DFA: Boyer–Moore (BM) and Knuth–Morris–Pratt (KMP) (won’t cover in class)

4/22

slide-5
SLIDE 5

Nondeterminism

slide-6
SLIDE 6

In a few lectures

q0 q1 q2 q2 1 1 1 1 What problems can fjnite state machines solve? We’ll answer this question in the next few lectures Useful to consider hypothetical machines that are nondeterministic

5/22

slide-7
SLIDE 7

Even easier with guesses

Suppose we could guess when the input string has only 3 symbols left Accept strings ending in 101: 3 symbols left 1 1 1 This is not a DFA!

6/22

slide-8
SLIDE 8

Nondeterministic fjnite automata

A machine that allows us to make guesses q0 q1 q2 q3 0,1 1 1 Each state can have zero, one, or more outgoing transitions labeled by the same symbol

7/22

slide-9
SLIDE 9

Choosing where to go

q0 q1 q2 q3 0,1 1 1 State q0 has two transitions labeled 1 Upon reading 1, we have the choice of staying at q0 or moving to q1

8/22

slide-10
SLIDE 10

Ability to choose

q0 q1 q2 q3 0,1 1 1 State q1 has no transition labeled 1 Upon reading 1 at q1, die; upon reading 0, continue to q2

9/22

slide-11
SLIDE 11

Ability to choose

q0 q1 q2 q3 0,1 1 1 State q1 has no transition going out Upon reading 0 or 1 at q3, die

10/22

slide-12
SLIDE 12

Meaning of NFA

q0 q1 q2 q3 Guess if we are 3 symbols away from end of input If so, guess we will see the pattern 101 Check that we are at the end of input 0,1 1 1

11/22

slide-13
SLIDE 13

How to run an NFA

q0 q1 q2 q3 0,1 1 1 input: 01101 The NFA can have several active states at the same time NFA accepts if at the end, one of its active states is accepting

12/22

slide-14
SLIDE 14

Example

Construct an NFA over alphabet {0, 1} that accepts all strings containing the pattern 001 somewhere 11001010, 001001, 111001 should be accepted ε, 000, 010101 should not

13/22

slide-15
SLIDE 15

Example

Construct an NFA over alphabet {0, 1} that accepts all strings containing the pattern 001 somewhere q0 q1 q2 q3 0,1 1 0,1

14/22

slide-16
SLIDE 16

Defjnition

A nondeterministic fjnite automaton (NFA) is a 5-tuple (Q, Σ, δ, q0, F) where

  • Q is a fjnite set of states
  • Σ is an alphabet
  • δ : Q × (Σ ∪ {ε}) → subsets of Q is a transition function
  • q0 ∈ Q is the initial state
  • F ⊆ Q is a set of accepting states

Differences from DFA:

  • transition function δ can go into several states
  • allows ε-transitions

15/22

slide-17
SLIDE 17

Language of an NFA

The NFA accepts string x if there is some path that, starting from q0, ends at an accepting state as x is read from left to right The language of an NFA is the set of all strings accepted by the NFA

16/22

slide-18
SLIDE 18

ε-transitions

ε-transitions can be taken for free: q0 q1 q2 ε a b a accepts a, b, aab, bab, aabab, … rejects ε, aa, ba, bb, …

17/22

slide-19
SLIDE 19

Example

q0 q1 q2 ε,1 ε alphabet Σ = {0, 1} states Q = {q0, q1, q2} initial state q0 accepting states F = {q2} table of transition function δ

inputs

1 ε

states

q0 ∅ {q1} {q1} q1 {q0, q1} ∅ {q2} q2 ∅ ∅ ∅

18/22

slide-20
SLIDE 20

Some computational paths of the NFA

ε

q0 q1 q2 ε,1

1

ε

2

00

q0 q1 q2 ε,1

1 2 3

ε

4

q0 q1 q2 ε,1

1 4 3 2

ε

5

q0 q1 q2 ε,1

1 3 2 4

ε

5

19/22

slide-21
SLIDE 21

Some computational paths of the NFA

001

q0 q1 q2 ε

1

, 1

4 3 2

ε

5

101

q0 q1 q2 ε,1

1 3 2

ε

4

11

q0 q1 q2 ε,1

1

ε q0 q1 q2 ε,1

1

ε

2

20/22

slide-22
SLIDE 22

Language of this NFA

q0 q1 q2 ε,1 ε What is the language of this NFA?

21/22

slide-23
SLIDE 23

Example of ε-transitions

Construct an NFA that accepts all strings with an even number of 0s

  • r an odd number of 1s

q0 r0 r1 s0 s1 even number of 0s

  • dd number of 1s

1 1 1 1

22/22

slide-24
SLIDE 24

Example of ε-transitions

Construct an NFA that accepts all strings with an even number of 0s

  • r an odd number of 1s

q0 r0 r1 s0 s1 even number of 0s

  • dd number of 1s

ε ε 1 1 1 1

22/22