# Nondeterministic Finite Automata NFA Definition of an NFA

- Slides: 20

Nondeterministic Finite Automata (NFA) Definition of an NFA Testing string acceptance by NFA Construction of an equivalent DFA 1

Fundamental differences between NFA and DFA All FAs are a finite collection of states For DFAs, a unique state is occupied at any one time. For NFAs more one state can be occupied at one time. For DFA, d(q, a) is the unique state that become occupied when q is occupied and input a is processed For NFA, d(q, a) is a set of states that become occupied when q is occupied and input a is processed. Since the NFA may be in more than one state when input a is processed, we must get the union of d(qk, a) for all qk that are occupied when input a is processed. 2

Meaning of d(q, a)=nil Transition function d(q, a) defines a set of states, that may be empty and denoted by nil. d(q, a)=nil means “terminate thread” that led to the current set of states, which includes q, occupied in the NFA when input a is processed. Any one of the occupied states for which d(q, a)=nil is sufficient to terminate thread. When a thread is terminated, occupied states with d(q, a) not equal to nil will create a new thread when input a is processed. 3

NFA that accepts strings ending in 01 01 0 A Start A 0 A B 1 B 0 A 1 C A B 0 A 1 A B *C 0 1 {A, B} nil A C nil A B C C accepts Every 0 creates a path that could lead to acceptance if followed by a 1 that terminates the string; hence this NFA accepts strings that end in 01. 4

Thread termination in processing 00101 01 0 A Start A 0 A B 1 B 0 A 1 C A B 0 A 1 A B *C 0 1 {A, B} nil A C nil A B C C accepts First 0 puts NFA in {A, B} due to d(A, 0). On processing the 2 nd 0, d(B, 0)=nil terminates thread and d(A, 0)={A, B} starts a new thread, which continues using d(A, 1)=A and d(B, 1)=C. On processing the 3 rd 0, d(C, 0)=nil terminates the thread and d(A, 0)={A, B} starts a new thread. The 2 nd 1 repeats the processing of the first 1 but accepts because it is the last character in the string. 5

Formal definition of NFA={Q, S, d, q 0, F} • Q = finite set of states • Σ = input alphabet • d = transition function is a set of states • Arguments are state in Q and symbol in S • Returns subset of Q (could be empty) • q 0 = unique start state in Q • F ⊆ Q set of final states. 6

Extended Transition Function of NFA In δ(q, a), q is a state and a is a symbol but δ(q, a) is a set of states. Recursive definition delta hat Basis: d˄ (q, e) = {q}, d˄ (q, a) = δ(q, a) Induction: d˄ (q, xa) = the union of all states to which states in d˄ (q, x) go upon receipt of input a. 7

Language of an NFA 8

NFA accepting input strings ending in 01 01 A Start 0 B 1 C S 0 1 A A, B A B nil C * C nil 9

Test acceptance of string 00101 by NFA b S 0 1 A A, B A B nil C * C nil Note correspondence with diagram below A 0 A B 0 A 1 A B C C accepts 10

The normal use of nil in union of sets takes care of thread termination. Another example S 0 1 A A, B A B nil C * C nil Test acceptance of string 011 by the method of all prefixes d˄ (A, e)=A d˄ (A, 0)=d(A, 0)=A d˄ (A, 01)=d(A, 1)Ud(B, 1)=AUC={A, C} d˄ (A, 011)=d(A, 1)Ud(B, 1)=AUnil=A 11

From DFA to equivalent NFA Equivalence means defines the same language A DFA can be easily turned into an equivalent NFA. If δD(q, a) = p, let the equivalent NFA have δN(q, a) = {p}. Equivalent NFA is always in a set that containing exactly one state – the state the DFA is in after reading the same input. 12

From NFA to equivalent DFA • For any NFA there is an equivalent DFA that defines the same language. • Proof is by subset construction. We build the states and transition function of the equivalent DFA out of subsets of the states of the NFA. • If |QN|=n, then there are 2 n possible subsets of QN • Many of these subsets cannot be reached from the start state of the DFA, which is the same as the unique start state of the NFA. • Lazy subset construction just involves the reachable subsets of QN 13

Formal definition of equivalent DFA Given an NFA with states QN, alphabet Σ, transition function δN, start state q 0, and final states FN, construct equivalent DFA with the following rules: • States are among the subsets of QN • Same alphabet Σ as NFA • Same start state {q 0} • Final states = all subsets with a member in FN 14

Lazy subset construction of DFAeq • The “start” state of NFA is unique. Make it the singleton “start” subset of DFA. • Since DFA and NFA have the same “start” state, the 1 st rows of their respective transition tables must also be the same. • Add the subsets in the 1 st row of the DFA transition table to the states of the DFA and find where they go under transitions. • Every time δD({q 1, …, qk}, a) is a new subset, add it as a row in the d. D transition table. • δD({q 1, …, qk}, a) is the union over all i=1, …, k of δN(qi, a), where δN(qi, a) is the set of states that NFA goes to if it is in state qi and processes input character a. 15

Example: find equivalent DFA by lazy subset construction 01 A Start 0 B 1 S C * A B C 0 1 A, B A nil C nil 16

Example of “lazy” construction 1 st row DFA transition table same as NFA transition table. Add {A, B} to the states of DFA Find where {A, B} goes when DFA processes 0 AND 1 S subsets 0 1 A A, B * Growing transition table of DFAeq A B C 0 1 A, B A nil C nil Transition table of NFA d. D({A, B}, 0)= d. N(A, 0) U d. N(B, 0)={A, B} U nil={A, B} d. D({A, B}, 1)= d. N(A, 1) U d. N(B, 1)={A} U {C}={A, C} Add {A, C} to the states of DFA with * to denote final state 17

Example of “lazy” construction subsets 0 1 A A, B A, C * A, C Growing transition table of DFAeq S * A B C 0 1 A, B A nil C nil Transition table of NFA Find out where {A, C} goes under 0 and 1 d. D({A, C}, 0)= d. N(A, 0) U d. N(C, 0)={A, B} U nil={A, B} d. D({A, C}, 1)= d. N(A, 1) U d. N(C, 1)={A} U nil={A} No new subsets. We can complete DFA transition table 18

Example of “lazy” construction subsets 0 1 A A, B A, C * A, C A, B A We can rename the states of DFAeq q 0 =A q 1 ={A, B} q 2 ={A, C} Transition table of DFAeq States q 0 q 1 * q 2 0 q 1 q 1 1 q 0 q 2 q 0 Transition table of DFAeq with new state names. Graph and test acceptance of 101 by the definition of delta-hat 19

0 1 A 0 B 0 C Start Assignment 3 Construct the transition table of the NFA graphed above. Derive the transition table of the equivalent DFA by lazy subset construction. Show all algebra used in the derivation. Graph the equivalent DFA without renaming the subsets of QN that are its states. 20

- Nondeterministic means choice of moves for automata *
- Automata
- Non deterministic finite automata
- Dtm turing machine
- Dfa ndfa
- Nondeterministic
- Finite and non finite subordinate clauses
- What is finite verb
- Learning objectives of non finite verbs
- Finite and nonfinite verbs examples
- Finite and non finite
- Contoh soal finite state automata
- String matching with finite automata
- Diagram fsa
- Lexical analysis finite automata
- Transition diagram in automata
- Finite state automata didefinisikan dengan?
- Csc3130
- Kleene theorem part 2 example
- Contoh moore machine
- Automata calculator