TOA Lecture 03
TOA Lecture 03
TOA Lecture 03
1
Kleene Star Closure
2
Examples
If Σ = {x}, Then Σ* = {Λ, x, xx, xxx, xxxx, ….}
If Σ = {0,1}, Then Σ* = {Λ, 0, 1, 00, 01, 10, 11, ….}
If Σ = {aaB, c}, Then Σ* = {Λ, aaB, c, aaBaaB, aaBc,
caaB, cc, ….}
3
PLUS Operation (+)
Plus Operation is same as Kleene Star Closure except that it
does not generate Λ (null string), automatically.
Example
If Σ = {0,1}, Then Σ+ = {0, 1, 00, 01, 10, 11, ….}
If Σ = {aab, c}, Then Σ+ = {aab, c, aabaab, aabc, caab, cc,
….}
4
Recursive definition of languages
5
Defining language of INTEGER
Step 1: 1 is in INTEGER.
Step 2: If x is in INTEGER then x+1 and x-1 are also in
INTEGER.
Step 3: No strings except those constructed in above, are
allowed to be in INTEGER.
6
Defining language of EVEN
Step 1: 2 is in EVEN.
Step 2: If x is in EVEN then x+2 and x-2 are also in EVEN.
Step 3: No strings except those constructed in above, are
allowed to be in EVEN.
7
Defining the language factorial
8
Defining the language PALINDROME
Σ = {a,b}
9
Defining the language {� � � � }
Σ={a,b}, as {� � � � : n=1,2,3,…}
Step 1: ab is in {� � � � }
Step 2: if x is in {� � � � }, then a x b is in {� � � � }
Step 3: No strings except those constructed in above, are
allowed to be in {� � � � }
10
Defining the language L
Σ={a,b}, of strings ending in a
Step 1: a is in L
Step 2: if x is in L then s(x) is also in L, where s belongs to
Σ*
Step 3: No strings except those constructed in above, are
allowed to be in L
11
Defining the language L
12
Defining the language L
Σ={a,b}, strings containing aa or bb
Step 1: a and b is in L
Step 2: s(aa)s and s(bb)s are also in L, where s belongs to
Σ*
Step 3: No strings except those constructed in above, are
allowed to be in L
13
Defining the language L
Step 1: a is in L
Step 2: s(a)s is also in L, where s belongs to b*
Step 3: No strings except those constructed in above, are
allowed to be in L
14
15
• Regular Expression is one of the language defining
method
• In this method, language is represented in terms of
strings
• It as an expression of strings and operators.
• Operators:
• * (kleene closure) [a*]
• + (kleene plus) [a+]
• . (concatenation) [ab]
• + (union) [a+b]
16
Kleene Closure/ Kleene star/ Kleene
operator:
• It is undetermined power, represent infinite number of terms can be
made including empty string.
• Denoted by * (star or asterisk)
• * means (zero or more)
• Example:
• ∑∗= {a}∗ = {^,a,aa,aaa,aaaa,aaaaa……}
• ∑∗= {a,b}∗ = {^,a,b,aa,ab,ba,bb,aaa,aab,aba,bbb,aabb,abab……}
• (ab*a) = {aa,aba,abba,abbba,abbbba,…….}
• (a*bba*) = {bb, abb, bba, abba, aabb, bbaa, aabba, abbaa, aabbaa,….. }
17
Kleene Plus/ Kleene Positive/ Positive
closure:
• It is also undetermined power, represent infinite number of terms
can be made except empty string.
• Denoted by + (plus/ positive)
• + means (one or more)
• Examples:
• ∑+= {a}+ = {a,aa,aaa,aaaa,aaaaa……}
• ∑+= {a,b}+ = {a,b,aa,ab,ba,bb,aaa,aab,aba,bbb,aabb,abab……}
• (ab+a) = {aba,abba,abbba,abbbba,…….}
• (a+bba+= {abba, abbaa, aabba, aabbaa, aaabbaa….. }
18
Extended Regular Exp Notations
19
Example
• String contains any number of ‘a’ letters
• L = { ^, a, aa, aaa, aaaa, …..}
R.E = ( a*)
20
Example
• Every String starts with ‘a’ and contains any no of b’s. if ∑ = {a,b}
21
Example
• Every String contains ‘a’ or ‘b’, if ∑ = {a,b}
• L = { a, b}
• R.E = ( a + b)
• R.E = ( a + b)*
22
Example
• Every string contains any number of “a’s” followed by bb, if ∑ = {a,b}
R.E = (a*bb)
23
Example
• Every string contains any number of “ab”, if ∑ = {a,b}
R.E = (ab)*
24
Example
• Every string contains any number of “a’s” followed by any no of “b’s”,
if ∑ = {a,b}
25
Example
• Every string contains even number of a’s , if ∑ = {a}
R.E = (aa)*
26
Regular Expressions
27
Examples
A regular expression: � + �. � ∗ . (� + �)
Not a regular expression: � + � +
28
Languages of Regular Expressions
Example
�((� + �. �)∗ ) = {�, �, ��, ��, ���, ���, … }
29
Definition
30
Definition (continued)
31
Example
Regular expression: (� + �). �∗
� � + � . �∗
= � � + � � �∗
= � � + � � �∗
= (�(�) � �(�))(� � )∗
= � � � � ∗
= �, � �, �, ��, ���, . .
= �, ��, ���, . . , �, ��, ��� …
32
Example
Regular expression � = � + � ∗
� + ��
33
Example
Regular expression � = �� ∗
�� ∗�
� � = {� 2� � 2� �: �, � ≥ 0}
34
Example
35
Example
36
Equivalent Regular Expressions
37
Example
38
39
��������� �������
��������� �� = ��������
������� ����������
40
By definition of regular expressions:
For regular expressions �1and �2
�(�1∗) = (�(�1))∗
� �1 = �( �1 )
41
42
Definition
A Finite automaton (FA), is a collection of the followings
Finite number of states, having one initial and some (maybe
none) final states.
Finite set of input letters (Σ) from which input strings are
formed.
Finite set of transitions i.e. for each state and for each input
letter there is a transition showing how to move from one state to
another.
43
Example
Σ = {a,b}
States: x, y, z where x is an initial state and z is final state.
Transitions:
At state x reading a go to state z,
At state x reading b go to state y,
At state y reading a, b go to state y
At state z reading a, b go to state z
44
Example Continued …
These transitions can be expressed by the following table
called transition table
Old States New States
Reading a Reading b
x- z y
y y y
z+ z z
45
Example Continued …
It may be noted that the information of an FA, given in the
previous table, can also be depicted by the following
diagram, called the transition diagram, of the given FA
a, b
y
b
x– a, b
a
Z+
46
Example Continued …
47
Example
Σ = {a,b}
States: x, y, where x is both initial and final state.
Transitions:
At state x reading a or b go to state y.
At state y reading a or b go to state x.
48
Example Continued …
These transitions can be expressed by the following
transition table
Old States New States
Reading Reading
a b
x y y
y x x
49
Example Continued …
It may be noted that the previous transition table may be
depicted by the following transition diagram.
a, b
x y
a, b
50
Example Continued …
The previous transition diagram is an FA accepting the
language of strings, defined over Σ={a, b} of even length.
It may be noted that this language may be expressed by
the regular expression
((a+ b) (a + b))*
51
TASK
52
Solution of Task
a,b
– +
a,b
53
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 FA a,b
––
b +
a,b
a
1
54
Example:
Consider the language L of strings, defined over Σ={a, b},
ending in a. The language L may be expressed by RE
(a+b)*a
This language may be accepted by the following FA
b a a
– +
55
Example continued …
a
a +
––
a b
b
56
Note
57
FA1 Corresponding to L1
a,b
––
a
+
b a,b
58
FA2 Corresponding to L2
a,b
a +
a,b
b
59
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
It is to be noted that if the condition on the length of string is not
imposed in the above language then the strings a and b will then
belong to the language.
This language L may be accepted by the following FA
60
Example Continued …
b a a
+
a b
–
a b
b
b
+
a
61
Task
62
Thank you !
63