ε ε Algorithms & Models of Computation CS/ECE 374, Fall 2017 Part I Non-deterministic Finite NFA Introduction Automata (NFAs) Lecture 4 Thursday, September 7, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 39 Sariel Har-Peled (UIUC) CS374 2 Fall 2017 2 / 39 Non-deterministic Finite State Automata ( NFA s) NFA behavior 0,1 0,1 0,1 0,1 0 0 0 1 0 1 q ε q 0 q 00 q p q ε q 0 q 00 q p Differences from DFA Machine on input string w from state q can lead to set of states (could be empty) From state q on same letter a ∈ Σ multiple possible states From q ε on 1 No transitions from q on some letters From q ε on 0 ε -transitions! From q 0 on ε Questions: From q ε on 01 Is this a “real” machine? From q 00 on 00 What does it do? Sariel Har-Peled (UIUC) CS374 3 Fall 2017 3 / 39 Sariel Har-Peled (UIUC) CS374 4 Fall 2017 4 / 39
ε ε NFA acceptance: informal NFA acceptance: example 0,1 0,1 0,1 0,1 0 0 0 1 0 1 q ε q 0 q 00 q p q ε q 0 q 00 q p Is 01 accepted? Informal definition: An NFA N accepts a string w iff some Is 001 accepted? accepting state is reached by N from the start state on input w . Is 100 accepted? The language accepted (or recognized) by a NFA N is denote by Are all strings in 1 ∗ 01 accepted? L ( N ) and defined as: L ( N ) = { w | N accepts w } . What is the language accepted by N ? Comment: Unlike DFA s, it is easier in NFA s to show that a string is accepted than to show that a string is not accepted. Sariel Har-Peled (UIUC) CS374 5 Fall 2017 5 / 39 Sariel Har-Peled (UIUC) CS374 6 Fall 2017 6 / 39 Simulating NFA Formal Tuple Notation Example the first a,b a,b Definition A non-deterministic finite automata ( NFA ) N = ( Q , Σ , δ, s , A ) is a five tuple where a b a b (N1) A B C D E Q is a finite set whose elements are called states, Run it on input ababa . Σ is a finite set called the input alphabet, Idea: Keep track of the states where the NFA might be at any given δ : Q × Σ ∪ { ε } → P ( Q ) is the transition function (here time. P ( Q ) is the power set of Q ), a,b a,b t = 0 : s ∈ Q is the start state, A ⊆ Q is the set of accepting/final states. a b a b A B C D E δ ( q , a ) for a ∈ Σ ∪ { ε } is a subset of Q — a set of states. Remaining input: ababa . a,b a,b t = 1 : a b a b A B C D E Sariel Har-Peled (UIUC) CS374 7 Fall 2017 7 / 39 Sariel Har-Peled (UIUC) CS374 8 Fall 2017 8 / 39 Remaining input: baba .
ε ε Reminder: Power set Example For a set Q its power set is: P ( Q ) = 2 Q = { X | X ⊆ Q } is the 0,1 0,1 set of all subsets of Q . 0 0 1 q ε q 0 q 00 q p Example Q = { 1 , 2 , 3 , 4 } Q = { q ε , q 0 , q 00 , q p } Σ = { 0 , 1 } { 1 , 2 , 3 , 4 } , δ { 2 , 3 , 4 } , { 1 , 3 , 4 } , { 1 , 2 , 4 } , { 1 , 2 , 3 } , s = q ε { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 2 , 3 } , { 2 , 4 } , { 3 , 4 } , P ( Q ) = { 1 } , { 2 } , { 3 } , { 4 } , A = { q p } {} Sariel Har-Peled (UIUC) CS374 9 Fall 2017 9 / 39 Sariel Har-Peled (UIUC) CS374 10 Fall 2017 10 / 39 Example Extending the transition function to strings Transition function in detail... NFA N = ( Q , Σ , δ, s , A ) 0,1 1 0,1 δ ( q , a ) : set of states that N can go to from q on reading 2 0 0 1 q ε q 0 q 00 q p a ∈ Σ ∪ { ε } . Want transition function δ ∗ : Q × Σ ∗ → P ( Q ) 3 δ ∗ ( q , w ) : set of states reachable on input w starting in state q . 4 δ ( q 0 , ε ) = { q 0 , q 00 } δ ( q ε , ε ) = { q ε } δ ( q 0 , 0) = { q 00 } δ ( q ε , 0) = { q ε , q 0 } δ ( q 0 , 1) = {} δ ( q ε , 1) = { q ε } δ ( q 00 , ε ) = { q 00 } δ ( q p , ε ) = { q p } δ ( q 00 , 0) = {} δ ( q p , 0) = { q p } δ ( q 00 , 1) = { q p } δ ( q p , 1) = { q p } Sariel Har-Peled (UIUC) CS374 11 Fall 2017 11 / 39 Sariel Har-Peled (UIUC) CS374 12 Fall 2017 12 / 39
Extending the transition function to strings Extending the transition function to strings Definition Definition For NFA N = ( Q , Σ , δ, s , A ) and q ∈ Q the ǫ reach ( q ) is the set For NFA N = ( Q , Σ , δ, s , A ) and q ∈ Q the ǫ reach ( q ) is the set of all states that q can reach using only ε -transitions. of all states that q can reach using only ε -transitions. Definition 0 0 a b c Inductive definition of δ ∗ : Q × Σ ∗ → P ( Q ) : ε ε if w = ε , δ ∗ ( q , w ) = ǫ reach ( q ) 1 , 0 s g 1 , 0 ε ε if w = a where a ∈ Σ ε ε d e f δ ∗ ( q , a ) = ∪ p ∈ ǫ reach ( q ) ( ∪ r ∈ δ ( p , a ) ǫ reach ( r )) 1 1 if w = ax , δ ∗ ( q , w ) = ∪ p ∈ ǫ reach ( q ) ( ∪ r ∈ δ ( p , a ) δ ∗ ( r , x )) Sariel Har-Peled (UIUC) CS374 13 Fall 2017 13 / 39 Sariel Har-Peled (UIUC) CS374 14 Fall 2017 14 / 39 Formal definition of language accepted by N Example 0 0 a b c Definition ε ε A string w is accepted by NFA N if δ ∗ N ( s , w ) ∩ A � = ∅ . 1 , 0 s g 1 , 0 ε ε ε ε Definition d e f 1 1 The language L ( N ) accepted by a NFA N = ( Q , Σ , δ, s , A ) is What is: { w ∈ Σ ∗ | δ ∗ ( s , w ) ∩ A � = ∅} . δ ∗ ( s , ǫ ) δ ∗ ( s , 0) Important: Formal definition of the language of NFA above uses δ ∗ δ ∗ ( c , 0) and not δ . As such, one does not need to include ε -transitions closure when specifying δ , since δ ∗ takes care of that. δ ∗ ( b , 00) Sariel Har-Peled (UIUC) CS374 15 Fall 2017 15 / 39 Sariel Har-Peled (UIUC) CS374 16 Fall 2017 16 / 39
Another definition of computation Why non-determinism? Definition Non-determinism adds power to the model; richer programming language and hence (much) easier to “design” programs w − → N p : State p of NFA N is reachable from q on w ⇐ ⇒ q Fundamental in theory to prove many theorems there exists a sequence of states r 0 , r 1 , . . . , r k and a sequence x 1 , x 2 , . . . , x k where x i ∈ Σ ∪ { ε } , for each i , such that: Very important in practice directly and indirectly r 0 = q , Many deep connections to various fields in Computer Science and Mathematics for each i , r i +1 ∈ δ ( r i , x i +1 ) , r k = p , and Many interpretations of non-determinism. Hard to understand at the outset. Get used to it and then you will appreciate it slowly. w = x 1 x 2 x 3 · · · x k . Definition � � � w δ ∗ N ( q , w ) = p ∈ Q − → N p � q . � Sariel Har-Peled (UIUC) CS374 17 Fall 2017 17 / 39 Sariel Har-Peled (UIUC) CS374 18 Fall 2017 18 / 39 DFA s and NFA s Every DFA is a NFA so NFA s are at least as powerful as DFA s. Part II NFA s prove ability to “guess and verify” which simplifies design and reduces number of states Easy proofs of some closure properties Constructing NFA s Sariel Har-Peled (UIUC) CS374 19 Fall 2017 19 / 39 Sariel Har-Peled (UIUC) CS374 20 Fall 2017 20 / 39
Example Example Strings that represent decimal numbers. { strings that contain CS374 as a substring } { strings that contain CS374 or CS473 as a substring } { strings that contain CS374 and CS473 as substrings } . ε, – 0,1,2,...,9 0 0 1 2 3 5 . 1,2,...,9 0,1,2,...,9 4 0,1,2,...,9 Sariel Har-Peled (UIUC) CS374 21 Fall 2017 21 / 39 Sariel Har-Peled (UIUC) CS374 22 Fall 2017 22 / 39 Example A simple transformation L k = { bitstrings that have a 1 k positions from the end } Theorem For every NFA N there is another NFA N ′ such that L ( N ) = L ( N ′ ) and such that N ′ has the following two properties: N ′ has single final state f that has no outgoing transitions The start state s of N is different from f Sariel Har-Peled (UIUC) CS374 23 Fall 2017 23 / 39 Sariel Har-Peled (UIUC) CS374 24 Fall 2017 24 / 39
Closure properties of NFA s Are the class of languages accepted by NFA s closed under the following operations? union Part III intersection concatenation Closure Properties of NFA s Kleene star complement Sariel Har-Peled (UIUC) CS374 25 Fall 2017 25 / 39 Sariel Har-Peled (UIUC) CS374 26 Fall 2017 26 / 39 Closure under union Closure under concatenation Theorem Theorem For any two NFA s N 1 and N 2 there is a NFA N such that For any two NFA s N 1 and N 2 there is a NFA N such that L ( N ) = L ( N 1 ) · L ( N 2 ) . L ( N ) = L ( N 1 ) ∪ L ( N 2 ) . q 1 f 1 N 1 q 1 q 2 f 2 f 1 N 1 N 2 q 2 f 2 N 2 Sariel Har-Peled (UIUC) CS374 27 Fall 2017 27 / 39 Sariel Har-Peled (UIUC) CS374 28 Fall 2017 28 / 39
Closure under Kleene star Closure under Kleene star Theorem Theorem For any NFA N 1 there is a NFA N such that L ( N ) = ( L ( N 1 )) ∗ . For any NFA N 1 there is a NFA N such that L ( N ) = ( L ( N 1 )) ∗ . ε q 1 f 1 N 1 q 1 f 1 N 1 Does not work! Why? Sariel Har-Peled (UIUC) CS374 29 Fall 2017 29 / 39 Sariel Har-Peled (UIUC) CS374 30 Fall 2017 30 / 39 Closure under Kleene star Theorem For any NFA N 1 there is a NFA N such that L ( N ) = ( L ( N 1 )) ∗ . Part IV NFA s capture Regular Languages ε q 0 q 1 f 1 N 1 ε Sariel Har-Peled (UIUC) CS374 31 Fall 2017 31 / 39 Sariel Har-Peled (UIUC) CS374 32 Fall 2017 32 / 39
Recommend
More recommend