1 / 19

CSCI 3130: Formal languages and automata theory

Fall 2011. The Chinese University of Hong Kong. CSCI 3130: Formal languages and automata theory. Nondeterminism. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Example from last time. Construct a DFA over alphabet {0, 1} that accepts those strings that end in 101.

grooms
Download Presentation

CSCI 3130: Formal languages and automata theory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fall 2011 The Chinese University of Hong Kong CSCI 3130: Formal languages and automata theory Nondeterminism Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. Example from last time • Construct a DFA over alphabet {0, 1} that accepts those strings that end in 101

  3. Would be easier if… • Suppose we could guess when the string we are reading has only 3 symbols left 1 0 1 3 symbols left 0 0 1 qdie This is not a DFA!

  4. Nondeterministic finite automaton • This is a machine that allows us to make guesses • Each state can have zero, one, or more outgoing transitions labeled by the same symbol 0, 1 1 0 1 q0 q1 q2 q3

  5. Choosing where to go • State q0 has two transitions labeled 1 • Upon reading 1, we have the choice of staying in q0 or moving to q1 0, 1 1 0 1 q0 q1 q2 q3

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

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

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

  9. How to run an NFA , 0 1 1 0 1 q0 q1 q2 q3 0 1 1 0 1 input: The NFA can have several active states at the same time It accepts if at the end, one of its active states is final

  10. Example • Construct an NFA over alphabet {0, 1} that accepts those strings that contain the pattern001 somewhere 11001010, 001001, 111001 should be accepted e, 000, 010101 should not

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

  12. 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

  13. Language of an NFA The NFA accepts string xÎS*if there is some path that, starting from q0, leads to an accepting state as the string is read left to right. The language of an NFA is the set of all strings that the NFA accepts.

  14. e-transitions • These can be taken for free: q1 accepts:  a, b, aab, bab, aabab, … b q0 a rejects: a q2 , aa, ba, bb, …

  15. Example 0 , 1  q0 q1 q2 0 table of transition function d: alphabet S= {0, 1} statesQ = {q0, q1, q2} initial stateq0 accepting statesF = {q2} inputs 0  1 q0 {q1} Æ {q1} q1 {q2} {q0, q1} Æ states q2 Æ Æ Æ

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

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

  18. Language of this NFA 0 , 1  q0 q1 q2 0 Can you guess the language of this NFA?

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

More Related