nfas and dfascpennycu/2019-2020/spring...deterministic vs. nondeterministic finite automata...
TRANSCRIPT
![Page 1: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/1.jpg)
NFAs and DFAs
![Page 2: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/2.jpg)
Reminder: Regular OperationsLet A and B be languages. We define the regular
operations union, concatenation, and star as
follows:
● Union: A ∪ B = {x | x ∈ A or x ∈ B }.
● Concatenation: A ⚬ B = {xy | x ∈ A and y ∈ B }.
● Star: A* = {x
1
x
2
...x
k
| k ≥ 0 and each x
i
∈ A }.
![Page 3: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/3.jpg)
Proofs that Regular Languages Are Closed Under...● Union: A ∪ B = {x | x ∈ A or x ∈ B}.
○ Proof by Construction (last class)
But…
● Concatenation: A ⚬ B = {xy | x ∈ A and y ∈ B}.
● Star: A* = {x
1
x
2
...x
k
| k ≥ 0 and each x
i
∈ A}.
We Need Better Tools!
![Page 4: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/4.jpg)
Deterministicvs.
NondeterministicFinite Automata
Everything discussed thus far was
deterministic, thus a DFA
Now, we will expand DFAs to allow
multiple potential paths.
Two types of FSMs
![Page 5: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/5.jpg)
What is Determinism?
Are computers deterministic?
“If the current state is known, and the
current inputs are known, then the
future state is also known.”
● No Choices
● No Randomness
● No Oracles
● No Errors/Cheating
According to our previous definition,
FSM == DFA
![Page 6: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/6.jpg)
What is Nondeterminism?
“If the current state is known, and the
current inputs are known, there may be
multiple possible future states.”
● Random choice?
● Parallel choice and simultaneous execution?
![Page 7: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/7.jpg)
NFAs: Relaxing The Requirements
Multiple edges with the same label
ε (optional) edges
● ε is not in Σ● Does not consume input character
Only need one path to an accept state
What could go wrong?
How do we know which path to try?
● Try them all
● Always make the right choice
![Page 8: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/8.jpg)
NFA Formal Definition
A Nondeterministic Finite
Automaton is a 5-tuple
N = (Q, Σ, δ, q
0
, F )
where:
Q Set of states (finite)
Σ Alphabet of symbols (finite)
δ The transition function
δ: Q x Σε ➝ 𝓟(Q)
q
0
The starting (initial) state
q
0
∈ Q
F The set of “Accept” states
F ⊆ Q
![Page 9: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/9.jpg)
NFA Formal Definition Example
N = (Q, Σ, δ, q
0
, F )
Q {q
1
, q
2
, q
3
, q
4
}
Σ {0, 1}
δ
q
0
q
1
F {q
4
}N = ({q
1
, q
2
, q
3
, q
4
}, {0, 1}, δ, q
1
, {q
4
})
![Page 10: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/10.jpg)
NFA Formal Definition Example
N = (Q, Σ, δ, q
0
, F )
Q {q
1
, q
2
, q
3
, q
4
}
Σ {0, 1}
δ
q
0
q
1
F {q
4
}N = ({q
1
, q
2
, q
3
, q
4
}, {0, 1}, δ, q
1
, {q
4
})
![Page 11: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/11.jpg)
NFA Formal Definition of ComputationLet N = (Q, Σ, δ, q
0
, F )
Let y
1
y
2
...y
m
be a string w where y
i
∈ Σε
N accepts w if there is a sequence of
states r
0
, r
1
, r
2
...r
m
in Q such that:
1. r
0
= q
0
,
2. r
i+1
∈ δ(r
i
, y
i+1
) for 0 ≤ i < m, and
3. r
m
∈ F
N “recognizes”
language A if
A = {w | N accepts w}
We now have a
NONDETERMINISTIC tool that we
can use to understand Regular
Languages!
Wait… Can we say this?!?
![Page 12: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/12.jpg)
Proof of Equivalency
NFAs and DFAs
Proof by Construction:
A method to convert
N = (Q, Σ, δ, q
0
, F )
into
M = (Q ’, Σ, δ’, q ’
0
, F ’)
![Page 13: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/13.jpg)
What Were We Talking About Last Time???
http://cscrunch.com:8890
![Page 14: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/14.jpg)
Convert NFA to DFAProof by Construction. (ignoring ε for now)
Let N = (Q, Σ, δ, q
0
, F ) be a NFA that recognizes
some language A.
Construct a DFA M = (Q ’, Σ, δ’, q ’
0
, F ’) that
recognizes the same language A.
For ε, define E(R) = {q | q can be reached from R
by traveling along 0 or more ε arrows} where
R ⊆ Q and q ∈ Q.
q’
0
= E({q
0
})
δ’(R, a) = {q ∈ Q | q ∈ E(δ(r, a)) for some r ∈ R}
Q’ = 𝓟(Q)
ex: {{p
0
}, {p
0
, p
1
}, {p
0
, p
2
}, {p
0
, p
1
, p
2
}, …}
q ’
0
= {q
0
}
F ’ = {R ∈ Q ’ | R contains an accept state of N }
or, F ’ = {R ∈ Q ′ | R ∩ F ≠ ∅}
δ’(R, a) = {q ∈ Q | q ∈ δ(r, a) for some r ∈ R }
where R ∈ Q’ and a ∈ Σ.
![Page 15: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/15.jpg)
Practice: Convert this NFA to a DFA
![Page 16: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/16.jpg)
Practice: Convert this NFA to a DFA
![Page 17: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/17.jpg)
We defined DFAs.
We defined Computation using DFAs.
We defined Regular Languages using
DFAs.
We defined NFAs.
We defined Computation using NFAs.
We showed equivalence of NFAs to
DFAs.
Now What?
![Page 18: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/18.jpg)
Regular OperationsThey eat their fiber.
Union, Concatenation, and Star:
3 Proofs by Construction
![Page 19: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/19.jpg)
Regular Operations: UnionLet N
1
= (Q
1
, Σ, δ1
, q
1
, F
1
) recognize A
1
,
and N
2
= (Q
2
, Σ, δ2
, q
2
, F
2
) recognize A
2
.
Construct N = (Q, Σ, δ, q
0
, F ) to recognize A
1
∪A
2
.
Q = {q
0
} ∪ Q
1
∪ Q
2
F = F
1
∪ F
2
For q ∈ Q and any a ∈ Σε,
![Page 20: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/20.jpg)
Regular Operations: ConcatenationLet N
1
= (Q
1
, Σ, δ1
, q
1
, F
1
) recognize A
1
,
and N
2
= (Q
2
, Σ, δ2
, q
2
, F
2
) recognize A
2
.
Construct N = (Q, Σ, δ, q
1
, F
2
) to recognize A
1
○ A
2
.
Q = Q
1
∪ Q
2
For q ∈ Q and any a ∈ Σε,
![Page 21: NFAs and DFAscpennycu/2019-2020/Spring...Deterministic vs. Nondeterministic Finite Automata Everything discussed thus far was deterministic, thus a DFA Now, we will expand DFAs to](https://reader030.vdocument.in/reader030/viewer/2022040603/5ea03c1e63416007e80c3ee3/html5/thumbnails/21.jpg)
Regular Operations: StarLet N
1
= (Q
1
, Σ, δ1
, q
1
, F
1
) recognize A
1
.
Construct N = (Q, Σ, δ, q
0
, F ) to recognize A
1
*.
Q = {q
0
} ∪ Q
1
F = {q
0
} ∪ F
1
For q ∈ Q and any a ∈ Σε,