m abba m take dfa m a b definition l m the language
play

( M ) { abba } = M Take DFA M a , b Definition: L M ( ) - PDF document

Review Languages and Grammars CS 301 - Lecture 2 Alphabets, strings, languages Deterministic Finite Automata (DFA) Regular Languages and Definition and Use Nondeterministic Finite Today: Automata Regular Languages


  1. Review • Languages and Grammars CS 301 - Lecture 2 – Alphabets, strings, languages • Deterministic Finite Automata (DFA) Regular Languages and – Definition and Use Nondeterministic Finite • Today: Automata – Regular Languages – Nondeterministic Finite State Automata Fall 2008 – Equivalence with DFA Example Languages Accepted by DFAs L ( M ) { abba } = M • Take DFA M a , b • Definition: L M ( ) – The language contains all input q M strings accepted by 5 a , b a b a b a a b b q q q q q L ( M ) M 0 1 2 3 4 – = { strings that drive to a final state} accept 1

  2. Formally Another Example L M , ab , abba ( ) { } = λ M Q , , , q , F • For a DFA ( ) = Σ δ 0 M a , b M • Language accepted by : L ( M ) { w * : * ( q , w ) F } = ∈ Σ δ ∈ 0 q 5 a , b a b a b a b b a w q q q q q 0 1 2 3 4 q q ′ q ∈ F ′ 0 accept accept accept Observation More Examples n L ( M ) { a b : n 0 } = ≥ M • Language rejected by : L M w * : * q , w F ( ) { ( ) } = ∈ Σ δ ∉ a , b a 0 w q q ′ q ∉ F ′ 0 a , b b q q q 0 1 2 trap state accept 2

  3. L M L M ( ) = { all strings with prefix } ab = { all strings without ( ) 001 substring } a , b 1 0 0 , 1 a b q q q 0 1 2 1 a accept b 0 1 0 00 001 λ q a , b 0 3 Examples of regular languages: Regular Languages { abba } , ab , abba { } λ L M • A language is regular if there is a DFA a n such that { b : n 0 } ≥ L = L ( M ) ab { all strings with prefix } 001 { all strings without substring } There exist automata that accept these • All regular languages form a language family Languages 3

  4. There exist languages which are not Regular: Another Example L { awa : w { a , b } * } = ∈ n n Example: L { a b : n 0 } a = ≥ b b There is no DFA that accepts such a language a q q q 0 2 3 b a (we will prove this later in the semester) q L = L ( M ) 4 a , b Nondeterministic Finite Accepter (NFA) Nondeterministic Finite Accepter (NFA) Alphabet = { a } Alphabet = { a } a Two choices a q q q q 1 2 1 2 a a q q 0 0 a a q q 3 3 4

  5. Nondeterministic Finite Accepter (NFA) First Choice Alphabet = { a } a a Two choices a a q q q q No transition 1 2 1 2 a a q q 0 0 a a q q No transition 3 3 First Choice First Choice a a a a a a q q q q 1 2 1 2 a a q q 0 0 a a q q 3 3 5

  6. First Choice Second Choice a a a a All input is consumed a a q q q q “accept” 1 2 1 2 a a q q 0 0 a a q q 3 3 Second Choice Second Choice a a a a a a q q q q 1 2 1 2 a a q q 0 0 a a No transition: q q 3 3 the automaton hangs 6

  7. Second Choice When To Accept a String a a An NFA accepts a string: when there is a computation of the NFA Input cannot be consumed that accepts the string a q q 1 2 AND a q 0 a all the input is consumed and the automaton q should we reject aa? is in a final state 3 Rejection example Example aa is accepted by the NFA: a “accept” a q q 1 2 a a q q a 1 2 q q 1 2 a q a 0 a q q 0 a 3 q 0 q a “reject??” 3 because this q But this only tells 3 computation us that choice accepts aa didn’t work…. 7

  8. First Choice First Choice a a “reject??” a a q q q q 1 2 1 2 a a q q 0 0 a a q q 3 3 Second Choice Second Choice a a a a q q q q 1 2 1 2 a a q q 0 0 a a q q 3 3 8

  9. Second Choice An NFA rejects a string: a when there is no computation of the NFA that accepts the string: a q q 1 2 • All the input is consumed and the a automaton is in a non final state q 0 a OR q “reject??” 3 • The input cannot be consumed Rejection example Example a is rejected by the NFA: a a a “reject??” a q q 1 2 a q q a a q q 1 2 1 2 a a q q q 0 a 0 0 a a q “reject??” q 3 3 q 3 All possible computations lead to rejection 9

  10. First Choice First Choice a a a a a a a a q q q q 1 2 1 2 a a q q No transition: 0 0 a a the automaton hangs q q 3 3 First Choice Second Choice a a a a a a Input cannot be consumed a a q q q q “reject??” 1 2 1 2 a a q q 0 0 a a q q 3 3 10

  11. Second Choice Second Choice a a a a a a a a q q q q 1 2 1 2 a a q q 0 0 a a No transition: q q 3 3 the automaton hangs Second Choice aaa is rejected by the NFA: a a a Input cannot be consumed “reject??” a q q 1 2 a a a q q q q 1 2 1 2 a a q q q 0 0 a a 0 a q q 3 3 q “reject??” “reject??” 3 All possible computations lead to rejection 11

  12. Lambda Transitions L = { aa } Language accepted: a q q 1 2 a q a a λ q q q q 0 a 0 1 2 3 q 3 a a a a a a a a λ λ q q q q q q q q 0 1 2 3 0 1 2 3 12

  13. (read head does not move) a a a a a a a a λ q λ q q q q q q q 0 1 2 3 0 1 2 3 Rejection Example all input is consumed a a a a a “accept” a a a a λ λ q q q q q q q q 0 1 2 3 0 1 2 3 String is accepted aa 13

  14. (read head doesn’t move) a a a a a a a a a a λ q λ q q q q q q q 0 1 2 3 0 1 2 3 Input cannot be consumed a a a a a a “reject??” a a a a λ λ q q q q q q q q 0 1 2 3 0 1 2 3 No transition: aaa the automaton hangs String is rejected 14

  15. Another NFA Example L = { aa } Language accepted: a a a b λ q q q q q q λ q q 0 1 2 3 1 2 3 0 λ a b a b a a b b q q λ q q q λ q q q 1 2 3 1 2 3 0 0 λ λ 15

  16. a b a b “accept” a a b b q q λ q q q λ q q q 1 2 3 1 2 3 0 0 λ λ Another String a b a b a b a b a a b b λ λ q q q q q q q q 0 1 2 3 0 1 2 3 λ λ 16

  17. a b a b a b a b a a b b λ λ q q q q q q q q 0 1 2 3 0 1 2 3 λ λ a b a b a b a b a a b b λ λ q q q q q q q q 0 1 2 3 0 1 2 3 λ λ 17

  18. a b a b a b a b “accept” a a b b λ λ q q q q q q q q 0 1 2 3 0 1 2 3 λ λ Language accepted Another NFA Example L ab , abab , ababab , ... { } = + ab { } = 0 0 , 1 q q a q b q q λ q 1 2 q 0 1 2 3 1 0 λ λ 18

  19. Remarks: Language accepted • The symbol never appears on the λ input tape • Simple automata: 0 M M 2 1 0 , 1 q q q 1 2 q q 0 1 (redundant 0 0 state) L ( M ) = {} λ 1 • NFAs are interesting because we can Formal Definition of NFAs express languages easier than DFAs M Q , , , q , F ( ) = Σ δ 0 • Q : Set of states, i.e. { q , q , q } 0 1 2 NFA a M M DFA 1 2 Input aplhabet, i.e. { a , b } : Σ q a 2 q q Transition function 0 1 : δ a a q : q q Initial state 0 0 1 F : Final states L ( M ) = { a } L ( M ) = { a } 1 2 19

  20. Transition Function δ q 0 1 , q ( ) { } ( q , 0 ) { q , q } δ = δ = 1 1 0 2 Note the function returns a set…. What did a DFA transition funciton return? 0 0 0 , 1 0 , 1 q q q q q q 0 1 2 0 1 2 1 1 λ λ ( q , ) { q , q } ( 2 q , 1 ) δ λ = δ = ∅ 0 0 2 0 0 0 , 1 0 , 1 q q q q q q 0 1 2 0 1 2 1 1 λ λ 20

  21. Extended Transition Function * q 0 , a q * q , aa q , q ( ) { } ( ) { } δ = δ = 1 0 4 5 q q q q 4 5 4 5 a a a a a a b b λ λ q q q q q q q q 0 3 0 3 1 2 1 2 λ λ Formally q * q , w q q ( ) : there is a walk from to ∈ δ j i i j with label w * q , ab q , q , q ( ) { } δ = 0 2 3 0 w q q i j q q 4 5 a a w  = σ σ σ 1 2 k a b λ q q q q 0 1 2 3 q σ σ σ q 1 2 k i j λ 21

  22. The Language of an NFA F = q 0 , q { } 5 q q q q 4 5 4 5 F = q 0 , q { } 5 a a a a a a b b λ λ q q q q q q q q 0 1 2 3 0 1 2 3 λ λ aa ∈ L ( M ) * q , aa ) { q , q } * q , ab ) { q , q , q } ab ∈ L M ( ( ( ) δ = δ = 0 4 5 0 2 3 0 F F ∈ ∈ F = q 0 , q F = q 0 , q { } { } 5 5 q q q q 4 5 4 5 a a a a a a b b q q q λ q q q q λ q 0 1 2 3 0 1 2 3 λ λ ) { } aba ∉ L M * ( q , abaa q , q * ( q 0 , aba ) { } q ( ) δ = δ = 0 4 5 1 F F ∉ ∈ 22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend