Beruflich Dokumente
Kultur Dokumente
com
Text search
n 2 s u
1
r e g
a f f l u e n t
a f e r l a r
a r
[^R]
DFA
differences
[ab]?, a+, (cat){3}
Implementation of grep
How do you handle expressions like:
[ab]? ()|[ab] zero or one R? e|R one or more R+ RR* {n} copies R{n} RR...R
n times
(cat)+ (cat)(cat)*
a{3}
aaa
[^aeiouy]
Closure properties
Example
The language L of strings that end in 101 is regular (0+1)*101 How about the language L of strings that do not end in 101?
Example
Hint: w does not end in 101 if and only if it ends in: 000, 001, 010, 011, 100, 110 or 111
or it has length 0, 1, or 2
Complement
The complement L of a language L is the set of all strings that are not in L Examples (S = {0, 1})
L1 = all strings that end in 101 L1 = all strings that do not end in 101 = all strings end in 000, , 111 or have length 0, 1, or 2 L2 = 1* = {e, 1, 11, 111, } L2 = all strings that contain at least one 0 = (0 + 1)*0(0 + 1)*
Example
The language L of strings that contain 101 is regular (0+1)*101(0+1)* How about the language L of strings that do not contain 101? You can write a regular expression, but it is a lot of work!
Now consider the DFA M with the accepting and rejecting states of M reversed
accepts strings not in L this is exactly L
NO!
(0+1)*10
0, 1 q0 1 q1 0 q2
(0+1)*
Intersection
The intersection L L is the set of strings that are in both L and L Examples:
L = (0 + 1)*11 L = (0 + 1)*10 L = 1* L = 1* L L = 1*11 L L =
Suppose L and L have DFAs, call them M and M Goal: Construct a DFA (or NFA) for L L
An example
M
r0 1 0 0 r1 1
M
s0
0 1 1 s1
L = even number of 0s
r0, s0
L = odd number of 1s
1 1
r0, s1
0 1 1
r1, s0
r1, s1
Whenever M is in state ri and M is in state sj, the DFA for L L will be in state (ri, sj)
DFA for L L in M in M
ri, si a rj, sj
Reversal
The reversal wR of a string w is w written backwards
w = cave wR = evac
The reversal LR of a language L is the language obtained by reversing all its strings
L = {cat, dog} LR = {tac, god}
How do we argue?
regular expression NFA DFA
e
a (alphabet symbol) E1 + E2 E1E2 E1*
e
a E1R + E2R E2RE1R (E1R)*
A question
LDUP = {ww: w L}
Ex.
regular expression
NFA
DFA
A question
Lets try with regular expression:
LDUP = LL
Lets try with NFA:
q0 e NFA for L e
NFA for L
q1
An example
L = 0*1 is regular LDUP = {1, 01, 001, 0001, ...} LDUP = {11, 0101, 001001, 00010001, ...} = {0n10n1: n 0}
An example
0 1 1 1 01 0 1 001 0 1 0001 0