Lecture 2 PDF
Lecture 2 PDF
______________________________________________________
GIMS- PMAS Arid Agriculture University, Gujrat Campus
1
Defining Languages
2
Example:
The language L of strings of odd length,
defined over Σ={a}, can be written as
L={a, aaa, aaaaa,…..}
Example:
The language L of strings that does not start
with a, defined over Σ={a,b,c}, can be written
as
L={b, c, ba, bb, bc, ca, cb, cc, …}
3
Example:
The language L of strings of length 2,
defined over Σ={0,1,2}, can be written as
L={00, 01, 02,10, 11,12,20,21,22}
Example:
The language L of strings ending in 0,
defined over Σ ={0,1}, can be written as
L={0,00,10,000,010,100,110,…}
4
Example: The language EQUAL, of strings with
number of a’s equal to number of b’s, defined
over Σ={a,b}, can be written as
{Λ ,ab,aabb,abab,baba,abba,…}
Example: The language EVEN-EVEN, of strings
with even number of a’s and even number of
b’s, defined over Σ={a,b}, can be written as
{Λ, aa, bb, aaaa,aabb,abab, abba, baab, baba,
bbaa, bbbb,…}
5
Example: The language INTEGER, of strings
defined over Σ={-,0,1,2,3,4,5,6,7,8,9}, can be
written as
INTEGER = {…,-2,-1,0,1,2,…}
Example: The language EVEN, of stings
defined over Σ={-,0,1,2,3,4,5,6,7,8,9}, can
be written as
EVEN = { …,-4,-2,0,2,4,…}
6
Example: The language {anbn }, of strings
defined over Σ={a,b}, as
{an bn : n=1,2,3,…}, can be written as
{ab, aabb, aaabbb,aaaabbbb,…}
Example: The language {anbnan }, of strings
defined over Σ={a,b}, as
{an bn an: n=1,2,3,…}, can be written as
{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,…}
7
Example: The language factorial, of strings
defined over Σ={1,2,3,4,5,6,7,8,9} i.e.
{1,2,6,24,120,…}
Example: The language FACTORIAL, of
strings defined over Σ={a}, as
{an! : n=1,2,3,…}, can be written as
{a,aa,aaaaaa,…}. It is to be noted that the
language FACTORIAL can be defined over
any single letter alphabet.
8
Example: The language DOUBLEFACTORIAL,
of strings defined over Σ={a, b}, as
{an!bn! : n=1,2,3,…}, can be written as
{ab, aabb, aaaaaabbbbbb,…}
Example: The language SQUARE, of strings
defined over Σ={a}, as
n2
{a : n=1,2,3,…}, can be written as
{a, aaaa, aaaaaaaaa,…}
9
Example: The language
DOUBLESQUARE, of strings defined
over Σ={a,b}, as
n2 n2
{a b : n=1,2,3,…}, can be written as
{ab, aaaabbbb, aaaaaaaaabbbbbbbbb,…}
10
Example: The language PRIME, of
strings defined over Σ={a}, as
p
{a : p is prime}, can be written as
{aa,aaa,aaaaa,aaaaaaa,aaaaaaaaaaa…}
11
An Important language
PALINDROME:
The language consisting of Λ and the
strings s defined over Σ such that
Rev(s)=s.
It is to be denoted that the words of
PALINDROME are called palindromes.
Example:For Σ={a,b},
PALINDROME={Λ , a, b, aa, bb, aaa, aba,
bab, bbb, ...}
12
Kleene Star Closure (*)
13
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, ….}
Λ* = ?
14
Note
16
Remark
17
Defining Languages Continued…
18
Example
20
Example
21
Defining the language PALINDROME,
defined over Σ = {a,b}
Step 1:
a and b are in PALINDROME
Step 2:
if x is palindrome, then s(x)Rev(s) will also
be palindrome, where s belongs to Σ*
Step 3:
No strings except those constructed in
above, are allowed to be in palindrome 22
3) Let S={a, bb, bab, abaab} be a set of strings. Are
abbabaabab and baabbbabbaabb in S*? Does any word
in S* have odd number of b’s?
Solution: since abbabaabab can be grouped as
(a)(bb)(abaab)ab , which shows that the last member of
the group does not belong to S, so abbabaabab is not in
S*, while baabbbabbaabb can not be grouped as
members of S, hence baabbbabbaabb is not in S*. Since
each string in S has even number of b’s so there is no
possiblity of any string with odd number of b’s to be in
S*.
23
Regular Expression
2.r1 r2
3.r1 + r2 and
4. r1*
are also regular expressions.
Step 3: Nothing else is a regular expression. 25
Defining Languages (continued)…
28
Remark
29
Example:
Consider the language, defined over
Σ={a , b} of words having at least one a,
may be expressed by a regular expression
(a+b)*a(a+b)*.
Consider the language, defined over
Σ = {a, b} of words having at least one a
and one b, may be expressed by a regular
expression
(a+b)*a(a+b)*b(a+b)*+ (a+b)*b(a+b)*a(a+b)*. 30
Consider the language, defined over
Σ={a, b}, of words starting with double a
and ending in double b then its regular
expression may be
aa(a+b)*bb
Consider the language, defined over
Σ={a, b} of words starting with a and
ending in b OR starting with b and ending
in a, then its regular expression may be
a(a+b)*b+b(a+b)*a 31
TASK
33