cs 374 algorithms models of computation
play

CS 374: Algorithms & Models of Computation Chandra Chekuri - PowerPoint PPT Presentation

CS 374: Algorithms & Models of Computation Chandra Chekuri University of Illinois, Urbana-Champaign Spring 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 34 CS 374: Algorithms & Models of Computation, Spring 2017


  1. CS 374: Algorithms & Models of Computation Chandra Chekuri University of Illinois, Urbana-Champaign Spring 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 34

  2. CS 374: Algorithms & Models of Computation, Spring 2017 Deterministic Finite Automata (DFAs) Lecture 3 January 24, 2017 Chandra Chekuri (UIUC) CS374 2 Spring 2017 2 / 34

  3. Part I DFA Introduction Chandra Chekuri (UIUC) CS374 3 Spring 2017 3 / 34

  4. DFAs also called Finite State Machines (FSMs) The “simplest” model for computers? State machines that are very common in practice. Vending machines Elevators Digital watches Simple network protocols Programs with fixed memory Chandra Chekuri (UIUC) CS374 4 Spring 2017 4 / 34

  5. A simple program Program to check if a given input string w has odd length int n = 0 While input is not finished read next character c n ← n + 1 endWhile If ( n is odd) output YES Else output NO Chandra Chekuri (UIUC) CS374 5 Spring 2017 5 / 34

  6. A simple program Program to check if a given input string w has odd length int n = 0 While input is not finished read next character c n ← n + 1 endWhile If ( n is odd) output YES Else output NO bit x = 0 While input is not finished read next character c x ← flip ( x ) endWhile If ( x = 1 ) output YES Else output NO Chandra Chekuri (UIUC) CS374 5 Spring 2017 5 / 34

  7. Another view Machine has input written on a read-only tape Start in specified start state Start at left, scan symbol, change state and move right Circled states are accepting Machine accepts input string if it is in an accepting state after scanning the last symbol. Chandra Chekuri (UIUC) CS374 6 Spring 2017 6 / 34

  8. Graphical Representation/State Machine 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Directed graph with nodes representing states and edge/arcs representing transitions labeled by symbols in Σ For each state (vertex) q and symbol a ∈ Σ there is exactly one outgoing edge labeled by a Initial/start state has a pointer (or labeled as s , q 0 or “start”) Some states with double circles labeled as accepting/final states Chandra Chekuri (UIUC) CS374 7 Spring 2017 7 / 34

  9. Graphical Representation 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Where does 001 lead? 10010 ? Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

  10. Graphical Representation 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Where does 001 lead? 10010 ? Which strings end up in accepting state? Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

  11. Graphical Representation 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Where does 001 lead? 10010 ? Which strings end up in accepting state? Can you prove it? Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

  12. Graphical Representation 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Where does 001 lead? 10010 ? Which strings end up in accepting state? Can you prove it? Every string w has a unique walk that it follows from a given state q by reading one letter of w from left to right. Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

  13. Graphical Representation 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Definition A DFA M accepts a string w iff the unique walk starting at the start state and spelling out w ends in an accepting state. Chandra Chekuri (UIUC) CS374 9 Spring 2017 9 / 34

  14. Graphical Representation 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Definition A DFA M accepts a string w iff the unique walk starting at the start state and spelling out w ends in an accepting state. Definition The language accepted (or recognized) by a DFA M is denote by L ( M ) and defined as: L ( M ) = { w | M accepts w } . Chandra Chekuri (UIUC) CS374 9 Spring 2017 9 / 34

  15. Warning “ M accepts language L ” does not mean simply that that M accepts each string in L . It means that M accepts each string in L and no others. Equivalently M accepts each string in L and does not accept/rejects strings in Σ ∗ \ L . Chandra Chekuri (UIUC) CS374 10 Spring 2017 10 / 34

  16. Warning “ M accepts language L ” does not mean simply that that M accepts each string in L . It means that M accepts each string in L and no others. Equivalently M accepts each string in L and does not accept/rejects strings in Σ ∗ \ L . M “recognizes” L is a better term but “accepts” is widely accepted (and recognized) (joke attributed to Lenny Pitt) Chandra Chekuri (UIUC) CS374 10 Spring 2017 10 / 34

  17. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  18. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  19. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  20. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q × Σ → Q is the transition function, Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  21. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q × Σ → Q is the transition function, s ∈ Q is the start state, Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  22. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q × Σ → Q is the transition function, s ∈ Q is the start state, A ⊆ Q is the set of accepting/final states. Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  23. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q × Σ → Q is the transition function, s ∈ Q is the start state, A ⊆ Q is the set of accepting/final states. Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  24. Formal Tuple Notation Definition A deterministic finite automata (DFA) M = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q × Σ → Q is the transition function, s ∈ Q is the start state, A ⊆ Q is the set of accepting/final states. Common alternate notation: q 0 for start state, F for final states. Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

  25. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  26. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  27. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  28. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = { 0 , 1 } Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  29. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = { 0 , 1 } δ Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  30. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = { 0 , 1 } δ s = Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  31. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = { 0 , 1 } δ s = q 0 Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  32. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = { 0 , 1 } δ s = q 0 A = Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  33. Example 0 q 0 q 3 1 1 0 0 1 q 1 q 2 0 , 1 Q = { q 0 , q 1 , q 1 , q 3 } Σ = { 0 , 1 } δ s = q 0 A = { q 0 } Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

  34. Extending the transition function to strings Given DFA M = ( Q , Σ , δ, s , A ) , δ ( q , a ) is the state that M goes to from q on reading letter a Useful to have notation to specify the unique state that M will reach from q on reading string w Chandra Chekuri (UIUC) CS374 13 Spring 2017 13 / 34

  35. Extending the transition function to strings Given DFA M = ( Q , Σ , δ, s , A ) , δ ( q , a ) is the state that M goes to from q on reading letter a Useful to have notation to specify the unique state that M will reach from q on reading string w Transition function δ ∗ : Q × Σ ∗ → Q defined inductively as follows: δ ∗ ( q , w ) = q if w = ǫ δ ∗ ( q , w ) = δ ∗ ( δ ( q , a ) , x ) if w = ax . Chandra Chekuri (UIUC) CS374 13 Spring 2017 13 / 34

  36. Formal definition of language accepted by M Definition The language L ( M ) accepted by a DFA M = ( Q , Σ , δ, s , A ) is { w ∈ Σ ∗ | δ ∗ ( s , w ) ∈ A } . Chandra Chekuri (UIUC) CS374 14 Spring 2017 14 / 34

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