140 likes | 475 Views
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.
E N D
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. • 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”.
DFAs contd. • Example: • { anbm: n,m>=1} • {anbn: n>=1} Are they regular?
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
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.
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.
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 ≠ Φ
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
Equivalence of DFAs and NFAs (2) • For every NFA, there is an equivalent DFA. • Therefore, every language accepted by some NFA is “regular”.
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
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.
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’}.
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