Professional Documents
Culture Documents
Lec 05 - TG
Lec 05 - TG
1
Defining Languages
• Using Transition Graph
2
FA Vs TG
FA Relaxing inputs on FA = TG
• No multiple paths exist for an • May exist more than one path for
input on a state a string
• No missing paths exist for an • Allows missing paths for certain
input on a state string
• A certain string to be accepted • A certain string to be accepted by
by an FA must start from Initial an FA must start from Initial state
state and end on some Final and end on some Final state
state otherwise its rejected
• No regular expression is • Null is allowed as transition label
allowed to be labelled as • Regular expression can be
transition of a state. labelled in TG
• Collection of accepted strings is
the language accepted by the TG.
3
Example
• Consider the Language L , defined over Σ = {a, b} of
all strings including Λ.
a,b
• TG1 a,b
- Λ
+
• TG2 a,b
a,b
a,b
• TG3 + 4
Example Continued …
• It may be noted that TG1 are TGs but not FA
• while TG2 and TG3 is both TG and FA as well.
• Every FA is a TG
• but every TG may not be an FA.
5
Example
• TG that does not accept any string defined over any alphabet.
• In this TG, no transition has been shown.
TG1 -
• In TG2 there are transitions for a and b at initial state but there
a,b
is no transition at state 1. TG2 - 1
• In TG3 there are transitions at both initial state and state 1, but
a,b
it does not accept any string.
a,b
TG3 - 1
Thus none of TG1, TG2 and TG3 accepts any string, i.e. these
6
a,b
a,b
TG: b
–– +
7
Example
• Consider the language L of strings, defined over Σ={a, b},
not ending in b.
• RE Λ + (a + b)*a
• TG a,b
–
a +
8
Class Activity
• Build a TG accepting the language L of strings, defined
over Σ={a, b}, ending in b.
• RE: (a + b)*b
• TG
a,b
–
b +
9
Example
• Consider the Language L of strings, defined over Σ = {a, b},
containing double a.
• RE: (a+b)* (aa) (a+b)*.
• TG
b,a b,a
1- aa 2+
10
Example
• Consider the language L of strings, defined over Σ={a, b},
having double a or double b.
• RE: (a+b)* (aa + bb) (a+b)*.
• TG a
a
a,b a,b
– +
b
b
11
Example - having double a or double b
• In the TG if the states are not labeled then it may not be
considered to be a single TG
a,b a,b
aa
- +
a,b a,b
bb
- +
a,b a,b
aa, bb
- +
12
Example
• Consider the language L of strings, defined over Σ={a,
b}, having triple a or triple b.
• RE: (a+b)* (aaa + bbb) (a+b)*
• TG a
2 4
a
a,b a a,b
1– 6+
b b
b
3 5 13
Example - having triple a or double b
• In the TG if the states are not labeled then it may not be
considered to be a single TG
a,b a,b
aaa
1- 2+
a,b a,b
bbb
3- 4+
a,b a,b
aaa,bbb
- + 14
Example
• Consider the language L of strings, defined over Σ = {a, b},
beginning and ending in different letters.
• RE: a(a + b)*b + b(a + b)*a
• TG
a, b
2 b 4+
a
1-
a,b
b
3 a
5+
15
Example
• Consider the Language L of strings of length two or more,
defined over Σ = {a, b}, beginning with and ending in same
letters.
• RE: a(a + b)*a + b(a + b)*b
• TG : a, b
2 a 4+
a
1-
a,b
b
b
3 5+
16
Task
• Build a TG accepting the language L of strings, defined
over Σ={a, b}, beginning with and ending in the
same letters.
• RE: a+b+a(a + b)*a + b(a + b)*b
• TG
.b b a a a
b
- + - +
b a a b
a b
17
Example
• Consider the EVEN-EVEN language, defined over
Σ={a, b}.
• EVEN-EVEN RE: (aa+bb+(ab+ba)(aa+bb)*(ab+ba))*
• TG
aa,bb aa,bb
ab,ba
ab,ba
18
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.
• RE: (aa)* b (b*+(aa (aa) *b)* ) bb OR
• (aa)* b (b*+( (aa) + b)* ) bb
TG
aa b
b
- b b +
aa
19
Nondeterminism
20
Determinism vs Nondeterminism
Determinism Nondeterminism
• Machines determine itself to • Machimnes can have multiple
change from previous state to paths at once for given input
next state based on Previous
State and Input string
• Path is not determined by
machine based on input string,
• Example: FA BUT Human Choice becomes a
• FA has labeled transitions for factor of selecting a path
each input for each state • Selection is not made by
• Fa has one and clear path for machine’s own determination,
each input transition hence call no- determinism
machines
• These paths are determined 21
bbb
a a a
ab
bbb
1 b 3
a
bb 2 bb 22
Example: trace abbbabbbabba
• The string abbbabbbabba could have three paths, (using
the states)
1) (a)(b) (b) (b) (ab) (bb) (a) (bb) (a)
(-)(4)(4)(+)(+)(3)(2)(2)(1)(+)
2) (a)(b) ((b)(b)) (ab) (bb) (a) (bb) (a)
(-)(4)(+)(+)(+)(3)(2)(2)(1)(+)
3) (a) ((b) (b)) (b) (ab) (bb) (a) (bb) (a)
(-) (4)(4)(4)(+) (3)(2)(2)(1)(+)
23