0% found this document useful (0 votes)
11 views23 pages

Lec 04

The document discusses three equivalent ways to represent regular languages: regular expressions, deterministic finite automata (DFAs), and nondeterministic finite automata (NFAs). It then provides examples and methods for converting between regular expressions and NFAs, including a general state elimination procedure to obtain a regular expression from a generalized NFA (GNFA).

Uploaded by

Cyrus Li
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views23 pages

Lec 04

The document discusses three equivalent ways to represent regular languages: regular expressions, deterministic finite automata (DFAs), and nondeterministic finite automata (NFAs). It then provides examples and methods for converting between regular expressions and NFAs, including a general state elimination procedure to obtain a regular expression from a generalized NFA (GNFA).

Uploaded by

Cyrus Li
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Equivalence of DFA and Regular Expressions

CSCI 3130 Formal Languages and Automata Theory

Siu On CHAN
Fall 2018
Chinese University of Hong Kong

1/18
Three ways of doing it

L = {x ∈ Σ∗ | x ends in 01} Σ = {0, 1}

q0 1 q0 0,1

0 0

1 q1 0 q1 (0+1) 01

0 1 1
q2 q2
regular
DFA NFA
expressions

2/18
They are equally powerful

regular
DFA NFA
expressions

regular languages

3/18
Examples: regular expression → NFA

q0 0 q1
R1 = 0

q0 0 q1 1 q2
R2 = 01

4/18
Examples: regular expression → NFA

NFA3
q1 q02 q2
ε ε

R3 = 0+01 q0 q6
ε ε
q3 0 q4 1 q5

ε
ε
R4 = (0+01)

ε ε
q00 NFA3 q10

5/18
Regular expressions

In general, how do we convert a regular expression to an NFA?

A regular expression over Σ is an expression formed by the following


rules

• The symbols ∅ and ε are regular expressions


• Every symbol in Σ is a regular expression
• If Σ = {0, 1}, then 0 and 1 are both regular expressions
• If R asd S are regular expressions, so are R + S, RS and R∗

6/18
General method when Σ = {0, 1}

regular
=⇒ NFA
expression

∅ q0

ε q0

q0 0 q
0 1

q0 1 q
1 1

7/18
General method

regular
=⇒ NFA
expression

q0 ε ε ε q1
RS NFAR NFAS

ε NFAR ε
R+S q0 q1
ε NFAS ε

R∗ ε
q0 ε ε q1
NFAR

8/18
Roadmap

regular
NFA
expressions
2-state
GNFA
GNFA

9/18
Simplify the NFA

First we simplify the NFA so that

• It has exactly one accepting state


• No arrows come into the start state
• No arrows go out of the accepting state

q3

q1 q5

q4

10/18
Simplify the NFA

First we simplify the NFA so that

• It has exactly one accepting state


• No arrows come into the start state
• No arrows go out of the accepting state

q3
ε
q0 ε q1 q5
ε
q4

10/18
Simplify the NFA

0 1
1
q1 q2
0

11/18
Simplify the NFA

0 1

ε 1 ε
q0 q1 q2 q3
0

• It has exactly one accepting state 3


• No arrows come into the start state 3
• No arrows go out of the accepting state 3

11/18
Generalized NFAs

A generalized NFA is an NFA whose transitions are labeled by regular


expressions, like

0∗ 1

ε + 10∗ 0∗ 11
q0 q1 q2

01

12/18
GNFA state elimination

regular
NFA
expressions
2-state
GNFA
GNFA

We will eliminate every state but the start and accepting states

13/18
State elimination

0∗ 1

ε + 10∗ 0∗ 11
q0 q1 q2

01


(ε + 10∗ )(0∗ 1)∗ 0∗ 11
q0 q1 q2
01


(ε + 10∗ )(0∗ 1)∗ 0∗ 11 + 01
q0 q1 q2

14/18
State elimination: general method

To eliminate state q, for every pair of states (u, v) such that


u→q→v

R2
R1 R3
u q v
Replace
R4

R1 R2∗ R3 + R4
u q v
by

Remember to do this even when u = v

15/18
Roadmap

regular
NFA
expressions
3 2-state 3 3
GNFA
GNFA

R A 2-state GNFA is the same as a


q0 q1
regular expression R

16/18
Conversion example

0 1

ε 1 ε
q0 q1 q2 q3
0

After eliminating q1 :

17/18
Conversion example

0 1

ε 1 ε
q0 q1 q2 q3
0

00∗ 1 + 1

After eliminating q1 : q0 0q∗ 1 q2 ε q3


1

0∗ 1(00∗ 1 + 1)∗
q0 q1 q2 q3
After eliminating q2 :

17/18
Conversion example

0 1

ε 1 ε
q0 q1 q2 q3
0

00∗ 1 + 1

After eliminating q1 : q0 0q∗ 1 q2 ε q3


1

0∗ 1(00∗ 1 + 1)∗
q0 q1 q2 q3
After eliminating q2 :
0 1
1
q1 q2
?
Check: 0∗ 1(00∗ 1 + 1)∗ =
0

17/18
Check your answer!

0 1
1 All strings ending in 1
q1 q2 ∗
0 (0+1) 1

18/18
Check your answer!

0 1
1 All strings ending in 1
q1 q2 ∗
0 (0+1) 1

0∗ 1(00∗ 1 + 1)∗ Always ends in 1

Does every string ending in 1


= 0∗ 1(0∗ 1)∗ have this form?
Yes

18/18

You might also like