Lesson 03
Lesson 03
1
Note
• It is to be noted that in TG there may exist more
than one paths for certain string, while there may
not exist any path for certain string as well. If there
exists at least one path for a certain string, starting
from initial state and ending in a final state, the
string is supposed to be accepted by the TG,
otherwise the string is supposed to be rejected.
Obviously collection of accepted strings is the
language accepted by the TG.
2
Example
• Consider the Language L , defined over
Σ = {a, b} of all strings including Λ. The language L
may be accepted by the following TG
a,b
a,b
- Λ
+
3
Example Continued …
TG1 a,b
a,b
a,b
+
TG2
4
Example
• Consider the following TGs
TG1 -
a,b
TG2 - 1
a,b
a,b
TG3 - 1
5
Example Continued …
• It may be observed that in the first TG, no transition
has been shown. Hence this TG does not accept any
string, defined over any alphabet. In TG2 there are
transitions for a and b at initial state but there is no
transition at state 1. This TG still does not accept any
string. In TG3 there are transitions at both initial state
and state 1, but it does not accept any string.
6
Example Continued …
Thus none of TG1, TG2 and TG3 accepts any string, i.e.
these TGs accept empty language. It may be noted
that TG1 and TG2 are TGs but not FA, while TG3 is both
TG and FA as well.
It may be noted that every FA is a TG as well, but the
converse may not be true, i.e. every TG may not be
an FA.
7
Example
Consider the language L of strings, defined over Σ={a,
b}, starting with b. The language L may be expressed
by RE b(a + b)* , may be accepted by the following TG
a,b
–– b +
8
Example
• Consider the language L of strings, defined over Σ={a,
b}, not ending in b. The language L may be expressed
by RE Λ + (a + b)*a , may be accepted by the following
TG
a,b
––
a +
9
Example
Consider the Language L of strings, defined
over Σ = {a, b}, containing double a.
The language L may be expressed by the
following regular expression
(a+b)* (aa) (a+b)*. This
language may be accepted by the following TG
10
Example
11
Example continued …
x
a
a
a,b a,b
–– +
b
b
y
12
OR
a,b a,b
aa,bb
- +
13
OR
a,b a,b
aa
1- 2+
a,b a,b
bb
3- 4+
14
Note
• In the above TG if the states are not labeled then it
may not be considered to be a single TG
15
Task Solution
• Build a TG accepting the language L of strings,
defined over Σ={a, b}, ending in b.
• Solution The language L may be expressed by RE (a
+ b)*b, may be accepted by the following TG
a,b
––
b +
16
Example
Consider the language L of strings, defined over
Σ={a, b}, having triple a or triple b. The language
L may be expressed by RE
(a+b)* (aaa + bbb) (a+b)*
This language may be accepted by the following TG
17
Example Continued …
2 a 4
a
a
a,b a,b
1– 6+
b
b
b 5
3
18
OR
a,b a,b
aaa,bbb
- +
19
OR
a,b a,b
aaa
1- 2+
a,b a,b
bbb
3- 4+
20
Example
Consider the language L of strings, defined over Σ =
{a, b}, beginning and ending in different letters.
The language L may be expressed by RE
a(a + b)*b + b(a + b)*a
The language L may be accepted by the following
TG
21
Example continued …
a, b
2 b 4+
a
1-
a,b
b
3 a
5+
22
Example
• Consider the Language L of strings of length two or
more, defined over Σ = {a, b}, beginning with and
ending in same letters.
The language L may be expressed by the following
regular expression
a(a + b)*a + b(a + b)*b
This language may be accepted by the following TG
23
Example Continued …
a, b
2 a 4+
a
1-
a,b
b
b
3 5+
24
Example
• Consider the EVEN-EVEN language, defined over
Σ={a, b}. As discussed earlier that EVEN-EVEN
language can be expressed by a regular
expression (aa+bb+(ab+ba)(aa+bb)*(ab+ba))*
The language EVEN-EVEN may be accepted by the
following TG
25
Example continued …
aa,bb aa,bb
ab,ba
1 2
ab,ba
26
Example
• Consider the language L, defined over Σ={a, b}, in which
a’s occur only in even clumps and that ends in three or
more b’s. The language L can be expressed by its regular
expression
(aa)*b(b*+(aa(aa)*b)*) bb
OR
(aa)*b(b*+( (aa)+b)*) bb
The language L may be accepted by the following TG
27
Example Continued …
aa b
b
b 2 b +
- 1
aa
28
Generalized Transition
Graphs
A generalized transition graph (GTG) is a collection of
three things
1) Finite number of states, at least one of which
is start state and some (maybe none) final
states.
2) Finite set of input letters (Σ) from which input
strings are formed.
3) Directed edges connecting some pair of states
labeled with regular expression.
It may be noted that in GTG, the labels of
transition edges are corresponding regular
expressions
29
Task Solution …
30
Task Solution
.b a a
b
b a
2- 4+ 1- 3+
b a
a b
5 a 6 b
31
Generalized Transition
Graphs
A generalized transition graph (GTG) is a collection of
three things
1) Finite number of states, at least one of which
is start state and some (maybe none) final
states.
2) Finite set of input letters (Σ) from which input
strings are formed.
3) Directed edges connecting some pair of states
labeled with regular expression.
It may be noted that in GTG, the labels of
transition edges are corresponding regular
expressions
32
Example
Consider the language L of strings, defined over
Σ={a,b}, containing double a or double b. The
language L can be expressed by the following
regular expression
(a+b)* (aa + bb) (a+b)*
33
Example continued …
a+b a+b
aa+bb
- +
34
Example
• Consider the Language L of strings, defined over Σ =
{a, b}, beginning with and ending in same letters.
The language L may be expressed by the following
regular expression
(a+b)+ a(a + b)*a + b(a + b)*b
This language may be accepted by the following
GTG
35
Example
a+
b+
+ +
a+ b+
–
b+ b+
a+
+ +
a+
36
Example
Consider the language L of strings of, defined over Σ
= {a, b}, beginning and ending in different letters.
The language L may be expressed by RE
a(a + b)*b + b(a + b)*a
The language L may be accepted by the following
GTG
37
Example Continued …
+
b(a+b)*a
-
a( a+b)* b
b(a+b)*a + a( a+b)* b
- +
39
Example
Consider the language L of strings, defined over Σ={a,
b}, having triple a or triple b. The language L may
be expressed by RE
(a+b)* (aaa + bbb) (a+b)*
This language may be accepted by the following
GTG
40
Example Continued …
a+b a+b
aaa+bbb
- +
OR
(a+b)*(aaa+bbb)(a+b)*
- +
41
Nondeterminism
• TGs and GTGs provide certain relaxations i.e. there
may exist more than one path for a certain string or
there may not be any path for a certain string, this
property creates nondeterminism and it can also
help in differentiating TGs or GTGs from FAs. Hence
an FA is also called a Deterministic Finite
Automaton (DFA).
42
Kleene’s Theorem
• If a language can be expressed by
1. FA or
2. TG or
3. RE
then it can also be expressed by other two as
well.
It may be noted that the theorem is proved,
proving the following three parts
43
Kleene’s Theorem
continued …
Kleene’s Theorem Part I
If a language can be accepted by an FA then it can
be accepted by a TG as well.
Kleene’s Theorem Part II
If a language can be accepted by a TG then it can
be expressed by an RE as well.
Kleene’s Theorem Part III
If a language can be expressed by a RE then it can
be accepted by an FA as well.
44
Kleene’s Theorem
continued …
Proof(Kleene’s Theorem Part I)
Since every FA can be considered to be a TG as well,
therefore there is nothing to prove.
45
Kleene’s Theorem
continued …
Proof(Kleene’s Theorem Part II)
To prove part II of the theorem, an algorithm
consisting of different steps, is explained showing
how a RE can be obtained corresponding to the given
TG. For this purpose the notion of TG is changed to
that of GTG i.e. the labels of transitions are
corresponding REs.
46
Kleene’s Theorem part II
continued …
Basically this algorithm converts the given TG to GTG
with one initial state along with a single loop, or one
initial state connected with one final state by a single
transition edge. The label of the loop or the transition
edge will be the required RE.
Step 1 If a TG has more than one start states, then
introduce a new start state connecting the new state
to the old start states by the transitions labeled by Λ
and make the old start states the non-start states. This
step can be shown by the following example
47
Example
b
b
1- 3+
aa
a
a
2- 4+
bb
48
Example Continued ...
b
b
1 3+
Λ aa
- a
Λ a
2 4+
bb
49
Kleene’s Theorem part II
continued …
Step 2:
If a TG has more than one final states, then
introduce a new final state, connecting the old final
states to the new final state by the transitions
labeled by Λ.
This step can be shown by the previous example of
TG, where the step 1 has already been processed
50
Example
b
b
1 3+
Λ aa
- a
Λ a
2 4+
bb
51
Example continued …
b
b
1 3
Λ Λ
aa
- a +
Λ a Λ
2 4
bb
52
Kleene’s Theorem part II
continued …
Step 3:
If a state has two (more than one) incoming
transition edges labeled by the corresponding REs,
from the same state (including the possibility of
loops at a state), then replace all these transition
edges with a single transition edge labeled by the
sum of corresponding REs.
This step can be shown by a part of TG in the
following example
53
Example
r3
r1
…. 4 5 ….
r2
r4
r3+r4
r1+r2
…. 4 5 ….
54
Note
• The step 3 can be generalized to any finite number of
transitions as shown below
r1
r2
…. 5 ….
….
rn
…. 5 ….
55
Kleene’s Theorem part II
continued …
Step 4 (bypass and state elimination)
If three states in a TG, are connected in sequence
then eliminate the middle state and connect the
first state with the third by a single transition
(include the possibility of circuit as well) labeled by
the RE which is the concatenation of corresponding
two REs in the existing sequence. This step can be
shown by a part of TG in the following example
56
Example
r3
r2 r4
…. 4 5 6 ….
r1
…. 2 ….
3 r4
4
r 1 r 2 *r 3
…. 2 4 ….
58
Example
Consider a part of the following TG
r2
r1 r3 r7 r9
r5
…. 4 ….
2 r4 3 r8
r6
59
Example continued ...
r1 +r3 r5* r4 r2 +r3 r5 r7
* r9 + r8r5*r7
…. ….
2 4
r6 + r8r5*r4
(r1 +r3 r5* r4 )+(r2 +r3 r5* r7 )(r9 +r8 r5* r7 )*(r6 +r8 r5* r4 )
…. ….
2 60
Note
• It is to be noted that to determine the RE
corresponding to a certain TG, four steps have
been discussed. This process can be explained by
the following particular examples of TGs
61
Example
• Consider the following TG
aa,b
2+
aaa
ab,ba
- 1
bba
3+
62
Example continued …
aa+b
2 Λ
aaa
ab+ba
- 1
4+
bba Λ
(ab+ba)(aa+b)*(aaa+bba)
- +
64
Example
• Consider the following TG
b
b
1- 3+
aa
a
a
2- 4+
bb
1 3
Λ Λ
aa
- a +
Λ a Λ
2 4
bb
66
Example continued …
(b+aa)b*
- +
(a+bb)a*
To connect the initial state with the final state by single
transition edge, the above TG can be reduced to the
following
- (b+aa)b*+(a+bb)a* +
Hence the required RE is (b+aa)b*+(a+bb)a*
67
Example
aa,bb aa,bb
ab,ba
-+1 2
ab,ba
68
Example continued ...
It is to be noted that since the initial state of this TG
is final as well and there is no other final state, so
to obtain a TG with single initial and single final
state, an additional initial and a final state are
introduced as shown in the following TG
69
Example continued ...
aa+bb aa+bb
ab+ba
Λ
3- 1 2
ab+ba
Λ
4+
Λ
3- 1 (ab+ba)(aa+bb)*(ab+ba)
4+
71
Example continued ...
(aa+bb)+(ab+ba)(aa+bb)*(ab+ba)
Λ
3- 1
Λ
4+
72
Example continued ...
Λ(aa+bb+(ab+ba)(aa+bb)*(ab+ba))*Λ
3- 4+
73
Kleene’s Theorem Part III
Statement:
If the language can be expressed by a RE then there
exists an FA accepting the language.
A) As the regular expression is obtained applying
addition, concatenation and closure on the letters
of an alphabet and the Null string, so while building
the RE, sometimes, the corresponding FA may be
built easily, as shown in the following examples
74
Example
• Consider the language, defined over Σ={a,b},
consisting of only b, then this language may be
accepted by the following FA
a,b
a b
1 - +
a, b
± a, b
76
Kleene’s Theorem Part III
Continued …
B) As, if r1 and r2 are regular expressions then their
sum, concatenation and closure are also regular
expressions, so an FA can be built for any regular
expression if the methods can be developed for
building the FAs corresponding to the sum,
concatenation and closure of the regular
expressions along with their FAs. These three
methods are explained in the following
discussions
77
Kleene’s Theorem Part III
Continued …
• Method1 (Union of two FAs): Using the FAs
corresponding to r1 and r2 an FA can be built,
corresponding to r1+ r2. This method can be
developed considering the following examples
78
Example
Let r1=(a+b)*b defines L1 and the FA1 be
a b b
X1 – X2 +
b a,b
a
y2 a
y1 - y3+
b 79
Sum of two FAs Continued
…
Let FA3 be an FA corresponding to r1+ r2, then the
initial state of FA3 must correspond to the initial
state of FA1 or the initial state of FA2.
Since the language corresponding to r1+ r2 is the
union of corresponding languages L1 and L2,
consists of the strings belonging to L1or L2 or
both, therefore a final state of FA3 must
correspond to a final state of FA1 or FA2 or both.
80
Sum of two FAs Continued
…
Since, in general, FA3 will be different from both FA1
and FA2, so the labels of the states of FA3 may be
supposed to be z1,z2, z3, …, where z1 is supposed to
be the initial state. Since z1 corresponds to the
states x1 or y1, so there will be two transitions
separately for each letter read at z1. It will give two
possibilities of states either z1 or different from z1.
This process may be expressed in the following
transition table for all possible states of FA3.
81
Example continued …
a b b
X1 – X2 +
b a a,b
a
y2 a
y1 – y3+
83
Example continued …
Z2
a a b
a
b
Z1- a b Z4 + Z5 +
a
b
Z3+ b