Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nondeterminism The Chinese University of Hong Kong Fall 2010

Similar presentations


Presentation on theme: "Nondeterminism The Chinese University of Hong Kong Fall 2010"— Presentation transcript:

1 Nondeterminism The Chinese University of Hong Kong Fall 2010
CSC 3130: Formal languages and automata theory Nondeterminism Andrej Bogdanov

2 Example Construct a DFA over alphabet {0, 1} that accepts those strings that end in 101 Sketch of answer: q000 1 q00 1 q001 q0 1 q01 qe 1 q101 q10 1 q1 1 q11 1 q111 1

3 Would be easier if… Suppose we could guess when the string we are reading has only 3 symbols left Then we could simply look for the sequence 101 and accept if we see it 1 1 3 symbols left 1 qdie This is not a DFA!

4 Nondeterminism Nondeterminism is the ability to make guesses, which we can later verify How a nondeterministic automaton for strings that end in 101 works: Guess if you are approaching end of input If guess is yes, look for 101 and accept if you see it If guess is no, read one more symbol and go to step 1

5 Nondeterministic finite automaton
This is a kind of automaton that allows you to make guesses Each state can have zero, one, or more outgoing transitions labeled by the same symbol 0, 1 1 1 q0 q1 q2 q3

6 The ability to make choices
0, 1 1 1 q0 q1 q2 q3 State q0 has two transitions labeled 1 Upon reading 1, we have the choice of staying in q0 or moving to q1

7 The ability to make choices
0, 1 1 1 q0 q1 q2 q3 State q1 has no transition labeled 1 Upon reading 1 in q1, we die; upon reading 0, we continue to q2

8 The ability to make choices
0, 1 1 1 q0 q1 q2 q3 State q3 has no transition going out Upon reading 0 or 1 in q3, we die

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

10 The NFA can have several active states
How to run an NFA , 1 1 1 q0 q1 q2 q3 input: 1 1 1 The NFA can have several active states at the same time

11 Example Construct an NFA over alphabet {0, 1} that accepts those strings that contain the pattern 001

12 Example Construct an NFA over alphabet {0, 1} that accepts those strings that contain the pattern 001 somewhere Answer 0, 1 0, 1 1 q0 q1 q2 q3

13 Definition A nondeterministic finite automaton (NFA) is a 5-tuple (Q, S, d, q0, F) where Q is a finite set of states S is an alphabet d: Q × (S ∪ {e}) → subsets of Q is a transition function q0 Î Q is the initial state F Í Q is a set of accepting states (or final states). Differences from DFA: transition function d can go into several states It allows e-transitions

14 Language of an NFA The language of an NFA is the set of all strings for which there is some path that, starting from q0, leads to an accepting state as the string is read left to right (and e-transitions are taken for free). Example e, 00, 001, 101 are accepted, but 11, 0110 are not , 1 q0 q1 q2

15 Example table of transition function d: alphabet S = {0, 1}
, 1 q0 q1 q2 table of transition function d: alphabet S = {0, 1} states Q = {q0, q1, q2} initial state q0 accepting states F = {q2} inputs 1 q0 Æ {q1} {q1} q1 {q0, q1} Æ {q2} states q2 Æ Æ Æ

16 Examples e 00 or or , 1  q0 q1 q2 , 1  q0 q1 q2 , 1  q0 q1 q2
, 1 1 e 2 q0 q1 q2 2 3 , 1 1 00 q0 q1 4 q2 2 , 1 1 4 or q0 q1 5 q2 3 , 1 1 3 or q0 q1 5 q2 2 4

17 Examples 001 101 11  , 1  q0 q1 q2 , 1  q0 q1 q2 , 1  q0 q1 q2
 , 1 1 4 001 5 q0 q1 q2 3 , 1 1 3 101 q0 q1 4 q2 2 , 1 1 11 q0 q1 q2 STOP , 1 1 q0 q1 2 q2 STOP

18 Example of e-transitions
Construct an NFA that accepts all strings with an even number of 0s or an odd number of 1s r0 r1 1 even number of 0s q0 e-transitions s0 s1 1 odd number of 1s can be taken for free (without reading input)


Download ppt "Nondeterminism The Chinese University of Hong Kong Fall 2010"

Similar presentations


Ads by Google