Presentation is loading. Please wait.

Presentation is loading. Please wait.

Part Two : Nondeterministic Finite Automata

Similar presentations


Presentation on theme: "Part Two : Nondeterministic Finite Automata"— Presentation transcript:

1 Part Two : Nondeterministic Finite Automata

2 Example 1 A C B accept all strings of 0 and 1 ending in 11
Given the word "1111", for the first '1' do we stay in state A or go to state B? A machine cannot determine that. A string is accepted by an NFA if there is any sequence of transitions that ends in a favorable state. A C B 1 Start with a few examples that are accepted: 1111 11 Easy fail example: Two different ways to fail :

3 DFA v. NFA Both: one start state one or more accepting states DFA:
every state indicates how to process each character of the input alphabet in exactly one way NFA: states may have more than one possible transition for an input just try them all states may not indicate how to process a particular input indicates the word is not accepted

4 Example 2 - Epsilon Transitions
ε - change state without consuming an input character This NFA accepts words of 0 and 1 that contain either 11 or 101. Example words: > A A A A - rejected > A B C e E - accepted > several possible transitions, none reach a favorable state A B C E D ε 1 0,1

5 FA Theory Two FAs are equivalent if they accept the same language.
For each NFA, there is an equivalent DFA. We will skip the boring proof.

6 NFA to DFA algorithm Start the DFA with the start state of the NFA.
For each new state in the DFA for each character in the alphabet if there is more than one choice of transitions, create a new state that is the union of those two states if that character does not lead out of this state, create transition to a new dead state Favorable states are any states that reference a favorable state from the NFA.

7 NFA to DFA Example 1 Again, accept all words of 0 and 1 that end with 11. NFA in table format: > A {A} {A,B} B ф {C} C ф ф A C B 1 new DFA - step one > A A AB state A is already defined state AB is new new DFA - step two > A A AB AB A ABC state AB is the union of states A and B 0: {A} U ф = A 1: {A,B} U {C} = ABC Final DFA > A A AB AB A ABC ABC A ABC

8 NFA to DFA Example 1 continued
Accept all words of 0 and 1 that end with 11. Final DFA > A A AB AB A ABC ABC A ABC A C B 1 1 1 1 A AB ABC

9 NFA to DFA example 2 accept all binary words that start with zero A B
NFA in Table Format: 0 1 >A B ф B B B A B 0,1 new DFA: 0 1 >A B C B B B C C C C is a trap state. A B 0,1 1 C 0,1

10 Practice Draw an NFA that accepts strings of {0,1} that contain "11".
Convert that NFA to a DFA.

11 Epsilon NFA to DFA example
Again, this NFA accepts words of 0 and 1 that contain either 11 or 101. 1 1 A B C ε 0,1 1 0,1 e-NFA: e* >A A A,B A B D C B C C,E D E D E E E E D E states reachable by using zero or more epsilon moves These cells are pointers to the correct row. Use the e* values from those rows.

12 e-NFA to DFA example continued
>A A A,B A B D C B C C,E D E D E E E E DFA: >A A AB AB AD ABCE AD A ABE ABCE ADE ABCE ADE AE ABE ABE ADE ABE AE AE ABE

13 e-NFA to DFA continued 0 1 >A A AB AB AD ABCE AD A ABE
>A A AB AB AD ABCE AD A ABE ABCE ADE ABCE ADE AE ABE ABE ADE ABE AE AE ABE e-NFA to DFA continued accept words of 0 and 1 that contain either 11 or 101 1 A AB 1 AD ABE 1 1 1 1 ABCE ADE AE 1

14 Practice The following eNFA accepts strings of {a,b} that start with a single 'a', followed by zero or more 'b's, and ending with a single 'a'. ab*a b b a e a a A B C D D


Download ppt "Part Two : Nondeterministic Finite Automata"

Similar presentations


Ads by Google