Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Similar presentations


Presentation on theme: "Cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual."— Presentation transcript:

1 cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A A AAA A AAAAAA AAA A PS1 is due now!

2 Adding Nondeterminism 1 2 Deterministic machine: at every step, there is only one choice Nondeterministic machine: at some steps, there may be more than one choice. a a, b b b

3 Nondeterminism in Practice

4 Nondeterminism in Theory Omnipotent: Machine splits into a new machine for each choice; if any machine accepts, accept. Omniscient: Whenever it has to make a choice, machine always guesses right.

5 Example NFA 12 3 ab a, b

6 Defining DFAs A deterministic finite automaton is a 5-tuple: Q finite set (“states”)  finite set (“alphabet”)  : Q    Q transition function q 0  Q start state F  Q set of accepting states How do we need to change this to support nondeterminism?

7 Defining NFAs A nondeterministic finite automaton is a 5-tuple: Q finite set (“states”)  finite set (“alphabet”) transition function q 0  Q start state F  Q set of accepting states Output of transition function is a set of states, not just one state.

8 Computation Model of NFA

9

10 Is an NFA more powerful than a DFA?

11 Power of Machines Languages that can be recognized by an A Languages that can be recognized by a B A and B are non-comparable.

12 Power of Machines Languages that can be recognized by an A Languages that can be recognized by a B B is less powerful than A: (1)Some A can recognize every language a B can recognize. (2)There is some language that can be recognized by an A but not by any B.

13 Power of Machines Languages that can be recognized by an A Languages that can be recognized by a B A and B are equal: (1)every language that can be recognized by an A can be recognized by some B (2)every language that can be recognized by a B can be recognized by some A

14 Power of NFA/DFA Easy part: is there any language a DFA can recognize that cannot be recognized by an NFA? Hard part: is there any language an NFA can recognized that cannot be recognized by a DFA?

15 L(NFA)  L(DFA) A nondeterministic finite automaton is a 5-tuple: Q finite set (“states”)  finite set (“alphabet”) q 0  Q start state F  Q set of accepting states Proof by construction: Construct the NFA N corresponding to any DFA A = (Q, , , q 0,F): N = (Q, ,  ’, q 0,F) where  q  Q,  ’(q,  ) = reject  a  ,  ’(q, a) = {  (q, a) } Proof by construction: Construct the NFA N corresponding to any DFA A = (Q, , , q 0,F): N = (Q, ,  ’, q 0,F) where  q  Q,  ’(q,  ) = reject  a  ,  ’(q, a) = {  (q, a) }

16 Power of NFA/DFA Easy part: is there any language a DFA can recognize that cannot be recognized by an NFA? Hard part: is there any language an NFA can recognized that cannot be recognized by a DFA? No: NFAs are at least as powerful as DFAs.

17 L(DFA)  L(NFA)

18

19 Example Conversion 12 3 ab a, b

20 12 3 ab {1} {2} {1, 2} {1, 3} {2, 3} {1,2, 3} {3} {}

21 12 3 ab a, b {1} {2} {1, 2} {1, 3} {2, 3} {1,2, 3} {3} {} a a b b b a b

22 Converting NFAs to DFAs How many states may be needed for the DFA corresponding to and NFA with N states? How much bigger is the transition function for the DFA corresponding to and NFA with N states?

23 Regular Expressions

24 “something formatted like an [email] address” address@domain [A-Za-z0-9]*@[A-Za-z0-9]*(. [A-Za-z0-9]*)* This matches most email addresses. Matching the full spec of all possible email addresses is left as exercise.

25 Regular Expression Base: Language a   { a }  {  }  { } Induction: R 1, R 2 are regular expressions R 1  R 2 L(R 1 )  L(R 2 ) R 1  R 2 { xy | x  L(R 1 ) and y  L(R 2 ) } R 1 * { x n | x  L(R 1 ) and n ≥ 0 }

26 How powerful are Regular Expressions? Is there a Regular Expression that describes the same language as any NFA? Is there some NFA that describes the same language as any Regular Expression?

27 L(RE)  L(NFA) Base: Language a   { a }  {  }  { } Induction: R 1, R 2 are regular expressions R 1  R 2 L(R 1 )  L(R 2 ) R 1  R 2 { xy | x  L(R 1 ) and y  L(R 2 ) } R 1 * { x n | x  L(R 1 ) and n ≥ 0 } Proof by construction. Trivial to draw NFAs for Each of these languages.

28 L(RE)  L(NFA) Base: Language a   { a }  {  }  { } Proof by construction. Trivial to draw NFAs for Each of these languages. Proof by construction. Trivial to draw NFAs for Each of these languages.

29 L(RE)  L(NFA) Induction: R 1, R 2 are regular expressions R 1  R 2 L(R 1 )  L(R 2 ) R 1  R 2 { xy | x  L(R 1 ) and y  L(R 2 ) } R 1 * { x n | x  L(R 1 ) and n ≥ 0 } Proof by induction and construction. Assume there are NFAs A 1 and A 2 that recognize the languages L(R 1 ) and L(R 2 ). Show how to construct an NFA that recognizes the produced language for each part. Proof by induction and construction. Assume there are NFAs A 1 and A 2 that recognize the languages L(R 1 ) and L(R 2 ). Show how to construct an NFA that recognizes the produced language for each part.

30 Proving: R 1  R 2

31 Charge PS2 will be posted by tomorrow Finish reading Chapter 1 Thursday: how to prove a language is non- regular


Download ppt "Cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual."

Similar presentations


Ads by Google