Slides 3
Slides 3
It’s a tie!
DFA NFA
Sanjit A. Seshia
EECS, UC Berkeley
S. A. Seshia 2
Recap: Closure
• If you perform an operation on one/more
regular languages, is the result also a
regular language?
S. A. Seshia 3
Operations on Regular Languages
Given: Two regular languages A and B
Union: A ∪ B = {w | w ∈ A or w ∈ B}
Intersection: A ∩ B = ?
Complementation: A = {w | w ∈ A}
• Reverse: AR = {w1w2…wk | wkwk-1…w1 ∈ A}
• Concatenation:
A · B = {vw | v ∈ A and w ∈ B}
• Star:
A* = {w1w2…wk | k ≥ 0 and each wi ∈ A}
S. A. Seshia 4
Closure under Reverse
• Reverse: AR = {w1w2…wk | wkwk-1…w1 ∈ A}
S. A. Seshia 6
Tree of Computations
Deterministic Non-Deterministic
Computation Computation
stuck
S. A. Seshia 7
Equivalence
• Two automata are equivalent if their
languages are the same
– For M1, M2, L(M1) = L(M2)
• DFAs and NFAs:
– For every NFA there is an equivalent DFA
(we’ll prove this) and vice-versa (this is easy,
why?)
S. A. Seshia 8
Theorem: Every NFA has an equivalent DFA
S. A. Seshia 9
From NFA to DFA
• Proof Hints:
– Proof by construction
Given an arbitrary NFA N, construct an
equivalent DFA M
– Proof by induction
N accepts a word w iff M accepts w
S. A. Seshia 10
FROM NFA TO DFA
Input: N = (Q, Σ, δ, q0, F)
Output: M = (Q′′, Σ, δ′, q0′, F′′)
Q′′ = ?
S. A. Seshia 11
From NFA to DFA
Input: N = (Q, Σ, δ, q0, F)
Output: M = (Q′′, Σ, δ′, q0′, F′′)
1 1 1
q0 q1 q2 q3
Run on 1110
S. A. Seshia 13
From NFA to DFA
Input: N = (Q, Σ, δ, q0, F) Idea:
Output: M = (Q′′, Σ, δ′, q0′, F′′) Q′′ = 2Q
0
ε a
1 2 What if we had ε-transitions?
a
ε
3 4
b ε b
6 7
5 b
8
c
c
reject ε
accept
S. A. Seshia 14
From NFA to DFA
Input: N = (Q, Σ, δ, q0, F) Idea:
Output: M = (Q′′, Σ, δ′, q0′, F′′) Q′′ = 2Q
0
ε a
1 2 What if we had ε-transitions?
a
ε
3 4 After reading an input symbol,
b ε b follow ε-transitions until you
6 7 can’t any more
5 b
8
c
c Given a set S in 2Q, E(S) is the
reject set of all states reached from S
ε
by following ε-transitions
- E(S) is called the ε-closure of S
accept
S. A. Seshia 15
NFA Example
0, 1 0,1
1 1,εε 1
q0 q1 q2 q3
Run on 1110
S. A. Seshia 16
From NFA to DFA
Input: N = (Q, Σ, δ, q0, F)
Output: M = (Q′′, Σ, δ′, q0′, F′′)
Q′′ = 2Q
δ′ : Q′′ × Σ → Q′′
δ′ σ) =
δ′(R,σ ∪ E( δ(r,σσ) )
r∈
∈R
q0′ = ?
F′′ = ?
S. A. Seshia 17
From NFA to DFA
Input: N = (Q, Σ, δ, q0, F)
Output: M = (Q′′, Σ, δ′, q0′, F′′)
Q′′ = 2Q
δ′ : Q′′ × Σ → Q′′
δ′ σ) =
δ′(R,σ ∪ E( δ(r,σσ) )
r∈
∈R
q0′ = E({q0})
F′′ = { R ∈ Q′′ | f ∈ R for some f ∈ F }
S. A. Seshia 19
Useful Definition
• Let w ∈ Σ*
• For an NFA N:
^
– δ(q, w) = set of states reached by executing
N on w starting from q
– Note that a state of N is in Q
• For the corresponding DFA M:
– ^δ’(q’, w) = state reached by executing M on w
starting from q’
– Note that a state of M is in 2Q
S. A. Seshia 20
NFA to DFA: Complexity
• If the original NFA N has n states, how
large can the corresponding DFA M be?
S. A. Seshia 21
NFA to DFA: Complexity
• If the original NFA N has n states, how
large can the corresponding DFA M be?
– Answer: 2n states
– Exercise: construct an example where N has
n states and M has Θ(2n) states
S. A. Seshia 22
Remaining Operations
Given: Two regular languages A and B
• Concatenation:
A · B = {vw | v ∈ A and w ∈ B}
• Star:
A* = {w1w2…wk | k ≥ 0 and each wi ∈ A}
S. A. Seshia 23
Closure under Concatenation
S. A. Seshia 24
Closure under Concatenation
S. A. Seshia 25
Closure under Star
Let L be a regular language and M be a DFA for L
ε
1
0
0,1
ε 1
0 0
1 ε
S. A. Seshia 26
Closure under Star
Why not the following?
ε 1
0
0,1
0 0
1 ε
S. A. Seshia 27
Formally:
Input: DFA M = (Q, Σ, δ, q1, F)
Output: NFA N = (Q′′, Σ, δ′, {q0}, F′′)
Q′′ = Q ∪ {q0}
F′′ = F ∪ {q0}
{δ
δ(q,a)} if q ∈ Q and a ≠ ε
{q1} if q ∈ F and a = ε
δ′′(q,a) = {q1} if q = q0 and a = ε
∅ if q = q0 and a ≠ ε
∅ else
S. A. Seshia 28
REGULAR LANGUAGES ARE CLOSED
UNDER REGULAR OPERATIONS
Union: A ∪ B = { w | w ∈ A or w ∈ B }
Intersection: A ∩ B = { w | w ∈ A and w ∈ B }
Complementation: A = { w | w ∉ A }
Concatenation: A ⋅ B = { vw | v ∈ A and w ∈ B }
S. A. Seshia 30
What does Language D look like?
S. A. Seshia 31
What does Language D look like?
1 ∪ 0 ∪ ε ∪ (0Σ*0) ∪ (1Σ*1)
Σ = {0,1}
S. A. Seshia 32
REGULAR EXPRESSIONS
σ is a regular expression representing {σ
σ}
(σ∈Σ)
ε is a regular expression representing {ε}
∅ is a regular expression representing ∅
If R1 and R2 are regular expressions
representing L1 and L2 then:
(R1R2) represents L1⋅L2
(R1 ∪ R2) represents L1 ∪ L2
(R1)* represents L1*
S. A. Seshia 33
Next Steps
• Read Sipser 1.3 in preparation for next
lecture
S. A. Seshia 34