CSC 3130: Automata theory and formal languages - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

CSC 3130: Automata theory and formal languages

Description:

... the concatenation ss...s n times. s = abb, t = cba st ... Similarly, we write Ln for LL...L (n times) The union of languages L1 L2 is the set of all strings ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 35
Provided by: andr52
Category:

less

Transcript and Presenter's Notes

Title: CSC 3130: Automata theory and formal languages


1
Fall 2009
The Chinese University of Hong Kong
CSC 3130 Automata theory and formal languages
NFA to DFA conversionand regular expressions
Andrej Bogdanov http//www.cse.cuhk.edu.hk/andrej
b/csc3130
2
NFAs are as powerful as DFAs
  • Obviously, an NFA can do everything a DFA can do
  • But can it do more?
  • Theorem

NO!
If a language L is accepted by some NFA, thenit
is also accepted by some DFA.
3
Proof of theorem
  • We will show a general way to convert every NFA
    into an equivalent DFA
  • Step 1 Simplify NFA by eliminating e-transitions
  • Step 2 Convert simplified NFA (without es)

We do this first
4
NFA to DFA conversion intuition
0, 1
1
0
NFA
q0
q1
q2
0
0
1
0
DFA
q0 or q1
q0 or q2
q0
1
1
5
NFA to DFA conversion intuition
0, 1
1
0
NFA
q0
q1
q2
0
0
1
0
DFA
q0, q1
q0, q2
q0
1
1
6
General method
7
Why the method works
  • At the end, the DFA accepts when it is in a state
    that contains some accepting state of NFA
  • So the DFA accepts only when the NFA accepts too

After reading n symbols, the DFA is in state
qi1,,qik if and only if the NFA is in one of
the states qi1,,qik
8
Converting via the general method
0, 1
1
0
NFA
q0
q1
q2
DFA
9
Converting via the general method
After eliminating the dead states and
transitions, we end up with the same picture
0
1
1
q0, q1
q0
1
0, 1
0
0
1
0
1
q0, q2
q0, q1, q2
Æ
q1
0
0, 1
0
q1, q2
q2
1
10
Proof of theorem
  • We will show a general way to convert every NFA
    into an equivalent DFA
  • Step 1 Simplify NFA by eliminating e-transitions
  • Step 2 Convert simplified NFA (without es)

11
Eliminating e-transitions
0
?, 1
?
q0
q1
q2
eNFA
0
Transition table of corresponding NFA
inputs
0
1
q0
q1, q2
q0, q1, q2
q1
q0, q1, q2
Æ
states
q2
Æ
Æ
q0, q1, q2
Accepting states of NFA
12
Eliminating e-transitions
0
?, 1
?
q0
q1
q2
NFA
0
0
0
0, 1
0
NFA without es
q0
q1
q2
0
0, 1
13
Eliminating e-transitions General method
  • For every state qi and every symbol a ÃŽ S,
    replace every path out of qi like
  • For every accept state qf, make accepting all
    states connected to it via es

q4
14
Regular expressions
15
Operations on strings
  • Given two strings s a1an and t b1bm, we
    define their concatenation st a1anb1bm
  • We define sn as the concatenation sss n times

s abb, t cba st abbcba
s 011 s3 011011011
16
Operations on languages
  • The concatenation of languages L1 and L2 is
  • Similarly, we write Ln for LLL (n times)
  • The union of languages L1 ? L2 is the set of all
    strings that are in L1 or in L2
  • Example L1 01, 0, L2 e, 1, 11, 111, .
    What is L1L2 and L1 ? L2?

L1L2 st s ? L1, t ? L2
17
Operations on languages
  • The star (Kleene closure) of L are all strings
    made up of zero or more chunks from L
  • This is always infinite, and always contains e
  • Example L1 01, 0, L2 e, 1, 11, 111, .
    What is L1 and L2?

L L0 ? L1 ? L2 ?
18
Constructing languages with operations
  • Lets fix an alphabet, say S 0, 1
  • We can construct languages by starting with
    simple ones, like 0, 1 and combining them

0(0?1)all strings that start with 0
0(01)
(01)?(10)
0110
19
Regular expressions
  • A regular expression over S is an expression
    formed using the following rules
  • The symbol Æ is a regular expression
  • The symbol e is a regular expression
  • For every a ? S, the symbol a is a regular
    expression
  • If R and S are regular expressions, so are RS,
    RS and R.

A language is regular if it is represented by a
regular expression
20
Examples
S 0, 1
01
0(1)
0, 01, 011, 0111,
0 followed by any number of 1s
(01)(01)
001, 0101, 01101, 011101,
0 followed by any number of 1s and then 01
21
Examples
strings of length 1
01
0, 1
(01)
e, 0, 1, 00, 01, 10, 11,
any string
(01)010
any string that ends in 010
(01)01(01)
any string that contatins the pattern 01
22
Examples
((01)(01))((01)(01)(01))
all strings whose length is even or divisible by
3 strings of length 0, 2, 3, 4, 6, 8, 9, 10,
12, ...
((01)(01))
strings of even length
(01)(01)
strings of length 2
((01)(01)(01))
strings of length divisible by 3
(01)(01)(01)
strings of length 3
23
Examples
((01)(01)(01)(01)(01))
strings that can be broken in blocks, where each
block has length 2 or 3
(01)(01)(01)(01)(01)
strings of length 2 or 3
(01)(01)
strings of length 2
(01)(01)(01)
strings of length 3
24
Examples
((01)(01)(01)(01)(01))
strings that can be broken in blocks, where each
block has length 2 or 3
00110
10
011
e
1
011010110
?
?
?
?
?
?
this includes all strings except those of length 1
((01)(01)(01)(01)(01))
all strings except 0 and 1
25
Examples
(101001)(?000)
ends in at most two 0s
there can be at most two 0s betweenconsecutive 1s
there are never three consecutive 0s
Guess (101001)(?000) x x does not
contain 000
0110010110
0010010
00
e
26
Examples
  • Write a regular expression forall strings with
    two consecutive 0s.

S 0, 1
(anything) 00 (anything else)
(01)00(01)
27
Examples
  • Write a regular expression forall strings that
    do not contain two consecutive 0s.

S 0, 1
0110101101010
blocks ending in 1
last block
(1 01)
... at most one 0 in every block ending in 1
(e 0)
... and at most one 0 in the last block
(1 01)(e 0)
28
Examples
  • Write a regular expression forall strings with
    an even number of 0s.

S 0, 1
even number of zeros (two zeros)
two zeros 10101
(10101)
29
Main theorem for regular languages
  • Theorem

A language is regular if and only if it is the
language of some DFA
NFA
regularexpression
DFA
regular languages
30
Road map
?
?
NFA
regularexpression
NFAwithout e
DFA
31
Examples regular expression ? NFA
  • R1 0
  • R2 0 1
  • R3 (0 1)

M2
32
General method
NFA
regular expr
Æ
q0
q0
e
a
q0
q1
symbol a
?
?
?
RS
q0
q1
MS
MR
33
General method continued
NFA
regular expr
MR
?
?
q0
q1
R S
?
?
MS
?
?
?
?
R
q0
q1
MR
34
Road map
?
?
?
NFA
regularexpression
NFAwithout e
DFA
Write a Comment
User Comments (0)
About PowerShow.com