Transcript 3
COSC 3340: Introduction to Theory of
Computation
University of Houston
Dr. Verma
Lecture 3
1
Lecture 3
UofH - COSC 3340 - Dr. Verma
Closure properties of Regular
Languages
Regular languages are closed under:
–
Union
–
2
Notation:
Intersection
Notation:
L1 L2 is regular if L1 and L2 are regular.
L1 L2 is regular if L1 and L2 are regular.
Lecture 3
UofH - COSC 3340 - Dr. Verma
Examples
Let = {a,b}.
Let L1 = { w in * | w has even number of a's}.
–
Is L1 regular?
L2 = { w in * | w has odd number of b's}.
–
Is L2 regular?
L1 L2 = ?
–
Ans: {w in * | w has even a's or odd b's}.
L1 L2 = ?
–
3
Ans: {w in * | w has even a's and odd b's}.
By closure properties, both these are regular.
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 = {w in {a,b}* | w has even
number of a's}.
4
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L2 = { w in {a,b}* | w has odd
number of b's}.
5
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's or odd b's}.
6
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's and odd b's}.
7
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's or odd b's}.
aba
8
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's or odd b's}.
aba
9
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's or odd b's}.
aba
10
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's or odd b's}.
aba
11
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's and odd b's}.
aba
12
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's and odd b's}.
aba
13
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's and odd b's}.
aba
14
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of L1 L2 = {w in {a,b}* | w has
even a's and odd b's}.
aba
15
Lecture 3
UofH - COSC 3340 - Dr. Verma
DFA of A = {w | w contains at least one 1 and
an even number of 0s follow the last 1}
16
Lecture 3
UofH - COSC 3340 - Dr. Verma
General Construction for and
Idea: Simulate two DFA's in parallel.
Let M1 = (Q1, , 1, s1, F1) and
M2 = (Q2, , 2, s2, F2)
M = (Q, , , s, F) where:
Q = Q1 X Q2
s = (s1, s2)
((q1, q2), ) = (1(q1, ), 2(q2, ))
For Union, F = ?
–
For Intersection, F = ?
–
17
Ans: (Q1 X F2) U (F1 X Q2)
Ans: F1 X F2
Lecture 3
UofH - COSC 3340 - Dr. Verma
Nondeterministic Finite Automaton
(NFA)
Generalization of DFA. Allows:
–
0 or more next states for the same (q, ).
–
Transitions labeled by the empty string.
Changing state without reading input
Motivation: Flexibility.
–
18
Guessing
Easier to prove many closure properties.
Lecture 3
UofH - COSC 3340 - Dr. Verma
How does an NFA work?
19
w is accepted by an NFA provided there is a
sequence of guesses that leads to a final
state.
Language accepted by NFA is the set of all
strings accepted by it.
Lecture 3
UofH - COSC 3340 - Dr. Verma
Example: {w in {0,1}* | the second last
symbol of w is a 1}
20
Lecture 3
UofH - COSC 3340 - Dr. Verma
NFA A = {w in {0,1}* | the second last
symbol of w is a 1}
110
21
Lecture 3
UofH - COSC 3340 - Dr. Verma
NFA A = {w in {0,1}* | the second last
symbol of w is a 1}
110
22
Lecture 3
UofH - COSC 3340 - Dr. Verma
NFA A = {w in {0,1}* | the second last
symbol of w is a 1}
110
23
Lecture 3
UofH - COSC 3340 - Dr. Verma
NFA A = {w in {0,1}* | the second last
symbol of w is a 1}
110
24
Lecture 3
UofH - COSC 3340 - Dr. Verma
Formal definition of NFA
Notation: e = U {e}.
NFA M = (Q, , , s, F) where:
–
–
–
–
–
25
Q - finite set of states
- input alphabet
s - initial state
F Q - set of final states
is a subset of Q X e X Q.
If (p, u, q) in , then NFA in state p can read u and
go to q.
Lecture 3
UofH - COSC 3340 - Dr. Verma