Finite Automata (contd) - Cornell · PDF file 2014-10-23 · Non-deterministic...

Click here to load reader

  • date post

    12-Mar-2020
  • Category

    Documents

  • view

    3
  • download

    0

Embed Size (px)

Transcript of Finite Automata (contd) - Cornell · PDF file 2014-10-23 · Non-deterministic...

  • Finite Automata (contd)

    CS 2800: Discrete Structures, Fall 2014

    Sid Chaudhuri

  • Recap: Deterministic Finite Automaton ● A DFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states – Σ is a fnite input alphabet (e.g. {0, 1}) – δ is a transition function δ : Q × Σ → Q – q0 ∈ Q is the start/initial state

    – F ⊆ Q is the set of fnal/accepting states

    Yes No 1

    1 00

  • A non-deterministic fnite automaton

    q0 1 0,10,1 q1 0,1q2

  • A non-deterministic fnite automaton

    q0 1 0,10,1 q1 0,1q2

    Different transitions from q0 on input 1

  • A non-deterministic fnite automaton

    q0 1 0,10,1 q1 0,1q2

    An NFA accepts a string x if it can get to an accepting state on input x

    Different transitions from q0 on input 1

  • A non-deterministic fnite automaton

    q0 1 0,10,1 q1 0,1q2

    What language does this automaton accept?

  • A non-deterministic fnite automaton

    q0 1 0,10,1 q1 0,1q2

    Answer: All strings ending with 1

  • Another NFA

    q0 1 0,10,1 q2 0,1q3

    What language does this automaton accept?

    q1 0,1

  • Another NFA

    q0 1 0,10,1 q2 0,1q3

    Answer: All strings with 1 in the penultimate place

    q1 0,1

  • Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

  • Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states

    q0 q1 q2 q3

  • Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states – Σ is a fnite input alphabet (e.g. {0, 1})

    q0 q1 q2 q3

  • 0,1

    Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states – Σ is a fnite input alphabet (e.g. {0, 1}) – δ is a transition function δ : Q × Σ → 2Q

    q0 q1 1 0,10,1 q2 0,1q3

  • 0,1

    Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states – Σ is a fnite input alphabet (e.g. {0, 1}) – δ is a transition function δ : Q × Σ → 2Q

    q0 q1 1 0,10,1 q2 0,1q3

    Only change from DFAs

  • 0,1

    Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states – Σ is a fnite input alphabet (e.g. {0, 1}) – δ is a transition function δ : Q × Σ → 2Q

    – q0 ∈ Q is the start/initial state

    q0 q1 1 0,10,1 q2 0,1q3

    Only change from DFAs

  • 0,1

    Non-deterministic Finite Automaton ● An NFA is a 5-tuple M = (Q, Σ, δ, q0, F)

    – Q is a fnite set of states – Σ is a fnite input alphabet (e.g. {0, 1}) – δ is a transition function δ : Q × Σ → 2Q

    – q0 ∈ Q is the start/initial state

    – F ⊆ Q is the set of fnal/accepting states

    q0 q1 1 0,10,1 q2 0,1q3

    Only change from DFAs

  • Non-deterministic Finite Automaton

    ● An NFA accepts a string x if it can get to an accepting state on input x

  • Non-deterministic Finite Automaton

    ● An NFA accepts a string x if it can get to an accepting state on input x – Think of it as trying many options at once, and hoping

    one path gets lucky

  • Non-deterministic Finite Automaton

    ● An NFA accepts a string x if it can get to an accepting state on input x – Think of it as trying many options at once, and hoping

    one path gets lucky

    ● A transition f (state, symbol) ↦ ∅ (the empty set) is possible

  • Non-deterministic Finite Automaton

    ● An NFA accepts a string x if it can get to an accepting state on input x – Think of it as trying many options at once, and hoping

    one path gets lucky

    ● A transition f (state, symbol) ↦ ∅ (the empty set) is possible – … in this case, the NFA treats this as a rejecting path

    (the string may still reach an accepting state by another path)

  • Non-deterministic Finite Automaton

    ● An NFA accepts a string x if it can get to an accepting state on input x – Think of it as trying many options at once, and hoping

    one path gets lucky

    ● A transition f (state, symbol) ↦ ∅ (the empty set) is possible – … in this case, the NFA treats this as a rejecting path

    (the string may still reach an accepting state by another path)

    – A convenient shortcut for our “hell/black-hole” state

  • Non-deterministic Finite Automaton

    ● Every DFA is an NFA

  • Non-deterministic Finite Automaton

    ● Every DFA is an NFA – If we're strict with our notation, we need to replace the

    transition f (state1, symbol) ↦ state2 with f (state1, symbol) ↦ {state2}

  • Non-deterministic Finite Automaton

    ● Every DFA is an NFA – If we're strict with our notation, we need to replace the

    transition f (state1, symbol) ↦ state2 with f (state1, symbol) ↦ {state2}

    ● Every NFA can be simulated by a DFA

  • Non-deterministic Finite Automaton

    ● Every DFA is an NFA – If we're strict with our notation, we need to replace the

    transition f (state1, symbol) ↦ state2 with f (state1, symbol) ↦ {state2}

    ● Every NFA can be simulated by a DFA – … i.e. they accept exactly the same language

  • Non-deterministic Finite Automaton

    ● Every DFA is an NFA – If we're strict with our notation, we need to replace the

    transition f (state1, symbol) ↦ state2 with f (state1, symbol) ↦ {state2}

    ● Every NFA can be simulated by a DFA – … i.e. they accept exactly the same language – Exponential blowup: if the NFA has n states, the DFA

    can require up to 2n states

  • Thought for the Day #1

    Find an NFA with n states that can't be simulated by a DFA with less than 2n states

  • Every NFA can be simulated by a DFA

  • Every NFA can be simulated by a DFA

    p

    q

    r a

    a

    NFA (fragment)

  • Every NFA can be simulated by a DFA

    p

    q

    r a

    a

    {p} {q, r} a

    DFA (fragment)NFA (fragment)

  • Every NFA can be simulated by a DFA

    p

    q

    r a

    a

    {p} {q, r} a

    “Subset construction”

    NFA (fragment)

    DFA (fragment)

    (This is merely illustrative – formal construction on following slides)

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation

    States

    Alphabet

    Transition Function

    Initial State

    Accepting States

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'0, F')

    States

    Alphabet

    Transition Function

    Initial State

    Accepting States

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'0, F')

    States Q 2Q

    Alphabet

    Transition Function

    Initial State

    Accepting States

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'0, F')

    States Q 2Q

    Alphabet Σ Σ

    Transition Function

    Initial State

    Accepting States

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'0, F')

    States Q 2Q

    Alphabet Σ Σ

    Transition Function δ δ'(S, a) = ∪s ∈ S δ(s, a) Initial State

    Accepting States

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'0, F')

    States Q 2Q

    Alphabet Σ Σ

    Transition Function δ δ'(S, a) = ∪s ∈ S δ(s, a) Initial State q0 q'0 = {q0}

    Accepting States

  • Every NFA can be simulated by a DFA

    NFA Equivalent DFA

    Specifcation (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'0, F')

    States Q 2Q

    Alphabet Σ Σ

    Transition Function δ δ'(S, a) = ∪s ∈ S δ(s, a) Initial State q0 q'0 = {q0}

    Accepting States F F' = {S ∈ 2Q | S ∩ F ≠ ∅}

  • Why NFAs?

  • Why NFAs?

    ● They can be way more compact than DFAs

  • Why NFAs?

    ● They can be way more compact than DFAs

    0,1

    q0 q1 1

    0,1

    q3 q20,1

    NFA

  • Why NFAs?

    ● They can be way more compact than DFAs

    q000 q001 q010 q011

    q100 q101 q110 q111

    0 1 0

    00

    0 0

    0

    0

    1

    1

    1

    1

    1

    1

    1

    0,1

    q0 q1 1

    0,1

    q3 q20,1

    NFA Equivalent minimal DFA

  • Why NFAs?

    ● They can be way more compact than DFAs

    ● It's easier to directly convert regular expressions (“wildcard search”