36
• The definition of an automaton requires the transition
function to be a function
• On the other hand, in an NFA the transition function should
get mapped to a set of values
• An NFA accepts a string if a sequence of possible states
leads to a final state.
• Only if no such sequence exists will the NFA reject the input
string
• E.g. the previous NFA accepts the string 010110 because
it can be processed as follows
(q0, 010110) (q0, 10110) (q1, 0110)
(q2, 110) (q3,10) (q3, 0) (q3, )
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
37
0, 1
0 1 01 10
q0
1
0, 1
q1
0,
q2
1
q3
• On the other hand, we can end up in a rejecting state:
(q0, 010110) (q0, 10110) (q0, 0110)
(q0, 110) (q0, 10) (q1, 0) (q2, )
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
1
38
Definition of an NFA
• Let P(A) = { B | B A } denote the power set of the set A
and for an alphabet
=
{ }
• A nondeterministic finite automaton is a 5-tuple
N = (Q, , , q0, F)
• Q is a finite set of states,
• is a finite alphabet,
• :Q×
P(Q) is the (set-valued) transition function,
that also allows -transitions
• q0 Q is the start state, and
• F Q is the set of (accepting) final states
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
39
• The transition function of the previous automaton is
0
1
q0
{q0}
{q0 q1 }
Ø
q1
{q2}
Ø
{q2}
q2
Ø
{q3}
Ø
q3
{q3}
{q3}
Ø
• Now we can easily express the error state as an empty
set of possible next states
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
2
40
• An NFA N = (Q,
, q0, F) accepts the string w,
m and
• If we can write it as w = y1y2…ym
a sequence of states r0, r1, …, rm exists in Q s.t.
• r0 = q0,
• ri+1
(ri, yi+1), i = 0, …, m-1, and
• rm F.
• DFAs are a special case of NFAs
all languages that can be recognized using the former can
also be recognized using the latter
• Also the other way around: DFAs and NFAs recognize the
same set of languages
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
41
Theorem 1.39 Let A = L(N) be the language recognized by some
NFA N. There exists a DFA M such that L(M) = A
Proof. Let N = (Q,
, q0, F). We construct a DFA
M = (Q’,
’, q0’, F’) that simulates the computation of N in parallel in
all its possible states at all times. Let us first consider the easier
situation where N has no arrows.
Every state of M is a set of states of N
Q' = P(Q)
q0' = { q0 }
F' = { R Q’ | R contains an accept state r
'(R, a) = r R (r, a)
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
F}
15.9.2011
3
42
Without arrows
0, 1
1
q0
0
{q0}
0, 1
0,
q1
1
1
q3
1
0
{q0, q1}
1
q2
1
{q0, q2}
1
{q0, q1, q3}
0
{q0, q2, q3}
0
0
1
{q0, q3}
Department of Software Systems
0
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
43
After Minimization
0
R0
0, 1
1
1
R1
0
R2
1
R3
0
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
4
44
Let us check that L(M) = L(N). The equivalence of the languages
follows when we prove for all x
* and r Q that
(q0, x) N (r, ) ({q0}, x) M (R, ) and r R,
where the notation (q0, x) N (r, ) means that in automaton N we
can process the string x starting from state q0 so that we end up
in state r and there are no more symbols to process ( ).
We prove it using induction over the length of the string x :
1. Basis: |x| = 0: (q0, ) N (r, ) r = q0.
Similarly ({q0}, ) M (R, ) R = {q0}
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
45
2. Induction hypothesis: the claim holds when |x| k
3. |x| = k+1: Then x = ya for some y, |y| = k, for which the claim
holds by the induction hypothesis. Now,
(q0, x) = (q0, ya) N (r, )
r' Q s.t. (q0, ya)
)
= in one transition
r' Q s.t. (q0, y) N (r', ) and (r', a) N (r, )
By induction hypothesis we get
r’ Q s.t. ({q0}, y) M (R', ) and r' R’ and r
(r', a)
Rearranging yields
({q0}, y) M (R', ) and r' R' s.t. r
(r', a)
By the definition of the transition function '
Department of Software Systems
N (r', a)
and (r', a)
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
N (r,
15.9.2011
5
46
({q0}, y)
(r', a) = '(R', a)
Let us return a and name '(R', a)
({q0}, ya) M (R', a) and r
'(R', a) = R
({q0}, ya) M (R', a) and (R', a) M (R, ) and r R
Concluding
({q0}, x) = ({q0}, ya) M (R, ) and r R
Which completes the proof of the claim
Department of Software Systems
M (R',
) and r
r'
R'
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
47
• In order to take the arrows into account, we compute for each
state R Q of M the collection of states that can be reached from
R by going only along arrows:
E(R) = { q | q can be reached from R by traveling along
0 or more arrows }
• It is enough to modify the transition function of M and start state
to take the arrows into account:
'(R, a) = r R E (r, a))
q0' = E({q0})
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
6
48
With arrows
0, 1
0, 1
1
q0
0,
q1
q3
1
0
{q0}
1
q2
1
{q0, q1,q2}
1
{q0 – q3}
0
0
1
1
{q0, q2, q3}
0
0
1
{q0, q2}
{q0, q3}
0
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
49
After Minimization
0
R0
0, 1
1
1
R1
0
R2
1
R3
0
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
7
50
Theorem 1.45
The class of regular languages is closed
under the union operation.
Proof. Let the languages A1 and A2 be regular. Then, there exists
(nondeterministic) finite automata N1 = (Q1,
1, q1, F1) and
N2 = (Q2,
2, q2, F2), which recognize these two languages.
Let us construct an automaton N = (Q,
, q0, F) for recognizing
the language A1 A2.
• Q = { q0 } Q1 Q2,
• The start state of N is q0,
q Q1
1 (q, a ),
• F = F1 F2 and
q Q2
2(q, a ),
(q, a )
{q1 , q 2 }, q q 0 and a
Ø,
q q 0 and a
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
51
q1
N1
q0
q2
N2
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
8
52
The class of regular languages is closed under
the concatenation operation.
Theorem 1.47
Proof. Let the languages A1 and A2 be regular. Then, there exists
(nondeterministic) finite automata N1 = (Q1,
1, q1, F1) and
N2 = (Q2,
2, q2, F2), which recognize these two languages.
Let us construct an automaton N = (Q,
, q1, F2) for recognizing
A1 A2.
• Q = Q 1 Q 2,
• The start state of N is q1,
• The final states of N are those in F2 and
1
( q, a)
1
(q, a ),
( q, a),
q Q1 and q
q F1 and a
F1
( q, a) {q2 }, q F1 and a
q Q2
2 ( q, a),
1
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
53
q1
q2
N1
Department of Software Systems
N2
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
9
54
Theorem 1.49. The class of regular languages is closed under
the star operation.
Proof. Let the language A be regular. Then, there exists a
(nondeterministic) finite automaton N1 = (Q1, , 1, q1, F1), which
recognizes the language.
Let us construct an automaton N = (Q, , , q0, F) for recognizing A*.
• Q = { q 0 } Q 1,
• The new start state of N is q0,
• F = { q0 } F1 and
q Q1 and q
(q, a),
q F1 and a
1 (q , a ),
{q1}, q F1 and a
1 (q , a )
1
(q , a )
{ q1 }
Ø,
Department of Software Systems
F1
q q0 and a
q q0 and a
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
55
q0
q1
N1
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
10
56
1.3 Regular Expressions
• These have an important role in describing patterns in
searching for strings in many applications (e.g. awk, grep,
Perl, ...)
All regular expressions of alphabet are
1. Ø and are regular expressions,
2. a is a regular expression of for all a
,
3. if R1 and R2 are regular expressions, then also
• (R1 R2),
• (R1 R2) and
• R1 *
are regular expressions
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
57
Each regular expression R of represents a language L(R)
1. L(Ø) = Ø,
2. L ) = { },
3. L(a) = {a} a
,
4. L((R1 R2)) = L(R1) L(R2),
5. L((R1 R2)) = L(R1) L(R2) and
6. L(R1*) = (L(R1))*
Proper closure: R+ is a shorthand for RR* (Kleene plus)
Observe: R+
= R*
• Let Rk be shorthand for the concatenation of k R’s with each
other.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
11
58
Examples
0*10* = { w | w contains a single 1 }
*001 * = { w | w contains the string 001 as a substring }
1*(01+)* = { w | every 0 in w is followed by at least one 1 }
)* = { w | w is a string of even length }
01 10 = { 01,10 }
*0
*1 0 1 = { w | w starts and ends with the same symbol }
(0
)1* = 01* 1*
(0
)(1
) = { , 0, 1, 01 }
1*Ø = Ø
Ø* = { }
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
59
• For any regular expression R
• R Ø = R and
• R =R
• However, it may hold that
• R
R and
• R
R
For example, the unsigned real numbers that can be recognized
using the previous automaton can be expressed with the regular
expression
d+( .d+
)( E (+ –
) d+
),
where d = ( 0
Department of Software Systems
…
9)
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
12
60
d
q0
d
d
.
q1
d
q2
q3
E
E
d
d
q4
q6
+, q5
Department of Software Systems
d
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
61
Theorem 1.54 A language is regular if and only if some
regular expression describes it.
We state and prove both directions of this theorem separately.
Lemma 1.55 If a language is described by a regular
expression, then it is regular.
Proof. Any regular expression can be converted into a finite
automaton, which recognizes the same language as that
described by the regular expression.
There are only six rules by which regular expressions can be
composed. The following pictures illustrate the NFA for each of
these cases.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
13
62
r=Ø
r=
a
r=a
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
63
r=s
t
Ns
Nt
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
14
64
r = st
Ns
Department of Software Systems
Nt
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
65
r = s*
Ns
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
15
66
r = (a(b
bb))*
b
a
b
b
b
a
b
b
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
67
Lemma 1.60 If a language is regular, then it is described by a
regular expression.
Proof. By definition a regular language can be recognized with a
(nondeterministic) finite automaton, which can be converted into
a generalized nondeterministic finite automaton (GNFA). The
GNFA finally yields a regular expression that is equivalent with
the original automaton.
Let RE denote the set of regular expressions over
• In a GNFA the transition function is a finite mapping
: Q × RE
P(Q)
• (q, w) (q', w') if q’
(q, r) for some r RE s.t. w = zw', z
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
L(r)
15.9.2011
16
68
A GNFA M can be reduced into a regular expression which
describes the language recognized by M
1. We compress M into a GNFA with only 2 states (so that the
language recognized remains equivalent)
1. The accept states of M are replaced by a single one (
arrows)
2. We remove all other states q except the start state and final
state.
Let qi and qj be the predecessor and successor of q on some
route passing through q.
Now we can remove q and rename the arrow between qi and
qj with a new expression.
2. Eventually the GNFA contains at most two states. It is easy to
convert the language recognized into a regular expression.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
69
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
17
70
r
qi
s
q
qj
rs
qi
qj
t
r
qi
s
q
qj
rt*s
qi
Department of Software Systems
qj
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
71
r
qi
qj
s
qi
r
s
qj
r
r*
r
s
t
u
Department of Software Systems
r*s(t*
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
ur*s)*
15.9.2011
18
72
a
a
b
ab
bb
aa
bb
a
b
ba
a
b
Department of Software Systems
b
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
15.9.2011
73
ab
aa
(aa
ba
b
bb a
b)(ba)*(bb
a)
(ab
Department of Software Systems
(aa
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2011
b)(ba)*(bb
a))*
15.9.2011
19
© Copyright 2026 Paperzz