0% found this document useful (0 votes)
33 views

Slides 3

This document discusses the equivalence of deterministic finite automata (DFAs) and non-deterministic finite automata (NFAs). It proves that DFAs and NFAs are equally expressive by constructing a DFA equivalent to any given NFA. This establishes closure properties for regular operations like reverse, union and concatenation. The document outlines the construction of a DFA from an NFA by tracking sets of states, and proves by induction that the NFA accepts a word if and only if the corresponding DFA accepts it. Finally, it discusses closure under concatenation and the star operation.

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Slides 3

This document discusses the equivalence of deterministic finite automata (DFAs) and non-deterministic finite automata (NFAs). It proves that DFAs and NFAs are equally expressive by constructing a DFA equivalent to any given NFA. This establishes closure properties for regular operations like reverse, union and concatenation. The document outlines the construction of a DFA from an NFA by tracking sets of states, and proves by induction that the NFA accepts a word if and only if the corresponding DFA accepts it. Finally, it discusses closure under concatenation and the star operation.

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

CS 172: Computability and Complexity

Equivalence of DFAs and NFAs

It’s a tie!

DFA NFA

Sanjit A. Seshia
EECS, UC Berkeley

Acknowledgments: L.von Ahn, L. Blum, M. Blum


What we’ll do today
• Prove that DFAs and NFAs are equally
expressive
• Use that to prove closure of other regular
operations
• Introduction to regular expressions

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}

• Regular languages are closed under


reverse. Here’s an attempt to prove it:
– Given M that recognizes A
– What if you could “run it backwards”?
– Construct MR as M with all arrows reversed &
accept state interchanged with start state
– MR is an NFA
S. A. Seshia 5
A non-deterministic finite automaton (NFA) is also
a 5-tuple M = (Q, Σ, δ, q0, F)

Q is the set of states


Σ is the alphabet
δ : Q × Σε → 2Q is the transition function
q0 ∈ Q is the start state
F ⊆ Q is the set of accept states
2Q is the set of subsets of Q and Σε = Σ ∪ {ε}

S. A. Seshia 6
Tree of Computations
Deterministic Non-Deterministic
Computation Computation

stuck

accept or reject accept reject

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

Corollary: A language is regular iff


it is recognized by an NFA

Corollary: L is regular iff LR is regular


(need to also prove that MR recognizes LR)

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′′)

Idea: Assume (for now) that there are


no ε-transitions
Q′′ = 2Q
Each non-stuck path in the
computation tree is of equal
length

Do a BFS (breadth-first search) on


reject accept this tree, tracking the “set of
states” transitioned to
S. A. Seshia 12
NFA Example
0, 1 0,1

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 (read details of the construction in Sipser) 18


From NFA N to DFA M
• Construction is complete
• But the proof isn’t: Need to prove
N accepts a word w iff M accepts w

• Use structural induction on the length of w,


|w|
– Base case: |w| = 0
– Induction step: Assume for |w| = n, prove for
|w| = n+1

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

Given DFAs M1 and M2, how can we


construct an NFA N for L(M1) · L(M2) ?

S. A. Seshia 24
Closure under Concatenation

Given DFAs M1 and M2, construct NFA N by


connecting all accept states in M1 to start
states in M2
• What are accept states of N?

S. A. Seshia 25
Closure under Star
Let L be a regular language and M be a DFA for L

How do we construct an NFA N that recognizes 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 }

Reverse: AR = { w1 …wk | wk …w1 ∈ A }

Complementation: A = { w | w ∉ A }

Concatenation: A ⋅ B = { vw | v ∈ A and w ∈ B }

Star: A* = { w1 …wk | k ≥ 0 and each wi ∈ A }


S. A. Seshia 29
Regular Expressions

S. A. Seshia 30
What does Language D look like?

D = { w | w has equal number of


occurrences of 01 and 10}

w should “toggle” between 0 and 1 an equal


number of times

How about: 0, 1, 011, 0110, ε -- are they in D?

S. A. Seshia 31
What does Language D look like?

D = { w | w has equal number of


occurrences of 01 and 10}
= { w | w = 1, w = 0, w = ε or
w starts with a 0 and ends with a 0 or
w starts with a 1 and ends with a 1 }

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

You might also like