1 / 14

DFAs and NFAs

DFAs and NFAs. Lecture No.4. Lesson Plan. DFAs continued.. NFAs Equivalence of DFAs and NFAs. DFAs contd. The set of all strings accepted by a DFA is the “ language accepted by the DFA ”. Thus, every automaton defines a language.

brandi
Download Presentation

DFAs and NFAs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DFAs and NFAs Lecture No.4

  2. Lesson Plan • DFAs continued.. • NFAs • Equivalence of DFAs and NFAs

  3. DFAs contd. • The set of all strings accepted by a DFA is the “language accepted by the DFA”. Thus, every automaton defines a language. • For our automaton, the accepted language is: { an, anb: n>=0}, that is, all strings of the form a….a and a….ab. • If we can construct a DFA for a given language then the language is called “regular”.

  4. DFAs contd. • Example: • { anbm: n,m>=1} • {anbn: n>=1} Are they regular?

  5. Nondeterministic Finite Acceptors a.k.a NFAs • Example: • It may have: • Multiple outgoing edges with the same letter • No outgoing edges for some letters • λ- transitions 1 a a 0 λ 2 3 b b 4 a a 5 6 b

  6. NFAs • When processing a string, NFA has choices, which edges to follow. • When following a λ-transition, NFA does not consume any symbol. • A string is accepted if some sequence of choices leads to a final state. • E.g: aab, bb, aaab; accepted or rejected? • In other words, a string is accepted if there is some walk from the initial to a final state that forms this string.

  7. NFAs • A “Transition Function”, δ is a mapping from a (state, symbol or λ) pair to a set of available states. • Note: the second argument is either a symbol or λ. • TASK: list down the transitions for the NFA under discussion.

  8. NFAs • An “Extended Transition Function”, δ* is a mapping from (stat, string) to the set of states that can be reached from “state” by a walk that forms “string”. • E.g: • δ* (0, λ)={0, 2} • δ* (0, aa)={1, 6} • δ* (2, ab)= Φ • Note: a string is accepted iff δ* (state, string) ∩ F ≠ Φ

  9. Equivalence of DFAs and NFAs • Automata are equivalent if they accept the same language. • Example 1: Both NFAs accept a common language. What is that language? a a 2 1 2 1 0 b b b λ b

  10. Equivalence of DFAs and NFAs (2) • For every NFA, there is an equivalent DFA. • Therefore, every language accepted by some NFA is “regular”.

  11. Equivalence of DFAs and NFAs (3) • Example 2: Constructing a DFA equivalent to an NFA. Idea: States in DFA correspond to set of states in NFA. 1 {0} a a b 0 2 λ a a b b a {0,2} Φ 3 {1,3} b a, b TRAP STATE

  12. Equivalence of DFAs and NFAs (4) • Both automata accept: {(ab)na: n>=0} • Construction Procedure: • Make the initial vertex{0}. • While some vertex {q1,q2,…,qm} has no outgoing edge for some symbol s, add this edge. • For every final state q of the NFA, all the states of the DFA that contain q are marked as final. • If the NFA accepts λ, then the initial state {0} is also marked as final.

  13. Equivalence of DFAs and NFAs (5) • Adding an outgoing edge: from {q1,…qm} for symbol s. • Determine all states of the NFA that can be reached from q1,q2,….,or qm along walks of the form “sλλ…..λ”. • If the DFA does not have a state {q1’,…,qn’}, add it. • Add an s arrow from {q1,….qm} to {q1’,…,qn’}.

  14. Equivalence of DFAs and NFAs (6) • Example: Construct an equivalent DFA. Note: If an NFA has n states, the corresponding DFA may have up to 2n states. b a 2 0 1 a,b a,b

More Related