Reguler Language and Reguler Expression
Reguler Language and Reguler Expression
1. The union of two languages ~ and L.;., denoted ~ U L.;., is the set of string that are 1. The co,
in either ~ or L.;., or both. languag
For example, if ~={OOI,lO,lII} and L.;.={E,OOI} then ~uL.;.={E,lO,OOI,III). That is
2. The concatenation of languages ~ and L.;. is a set of strings that can be formed by 2. If a is ~
taking any string in L" and concatenation it with any strings in L.;.. We denote {a}. Tt
concatenation of languages either with a dot. 3. A vari,
For example, if ~ ={OOI,lO,II}andL.;. ={E,OOI} then languag
1. The constants E (null string) and ¢ (empty set) are regular expression, denoting the
languages {E} ¢, respecti vely.
That is, L(E ) = {E}, and L(¢) =¢
2. If a is any symbol, then a is regular expression . This expression denotes the language
(a}. That is L(a) = (a} .
3. A variable , usually capitalized and italic such as L is a variable , representing any
language.
it should be I, rest 9 places from the right are either 0 or 1. Similarly positions 11th
from right and may be either 0 to 1.
So regular expression is
, == (0 + 1)*1 (0 + 1) (0 + I) (0 + 1) (0 + 1) (0 + 1) (0 + 1) (0 + 1) (0 + 1) (0 + 1)
Discrete Structures and Automata Theory
-
Sc
Example 3. Write the regular expression for the set of strings of an equal number o/O s
s
and 1:S such that in every prefix, the number of O's differs from the number of 1 by al /IIosl Exampl,
1.
SOlution:
Solution: Clearly the set of strings is having strings like 01010101, 10101010,0110,1001....
So regular expression will be r == (OJ + 10)' Cas
Cas
Example 4. Write a regular expression for the set of strings of O:S and 1:S not conta;/lill~
101 as a substring. Let
Solution : When we analyse the set of strings the it becomes clear that string may start witb
'0' and O's may be repeated, whenever one is encoute.Ied then no single 0 must folio", it
so strings ~Iike 0000010, 00000111111, 1001001.. ....... . Let J
Example ~ Write the regular expression over alphabet (a, b), for the set of slrillgs "'I~ Let n
even nuJ;i~r of a's followed by odd number of b:S that for the language
Example 6. Write the regular expression for the language L = (WE (0,1)* : HI has no POll
of consecutive zeros}.
Solution: Clearly whenever a 0 occurs it must be followed by a 1. Such a substring JIll}
be preceded and followed by any number of 1's, that is (1*011*)*. But strings ending ioU
or consisting of all 1 's are un accounted here, that is 1* (O+E).
So regular expression is ~ So/utio,,:
r2 = (1 + 01)* (0+ E)
Although the two expression look different, both anwers are correct, as they deoOfttl
same language. Generally, there are an unlimited number of regular expression for any~.
language. SOlutiol/ :
So
E~le 7. Write the regular expression for the language L={a/l blllll~ 4, m~3}.
Solution:Language contain the set of strings such that every string start with at fest 4
and end with at the most 3 b's.
Regular Expression and Languages
r2 = (aa)* a (bb)' b
Let regular expression for language L is r then r = 'i + r2
lumpl. ~e the "g .Ia, expms'on /0' the lang .age L ={ab" w, n >3, WE Ca, b)'},
Sollll;on : Clearl y every string of language L starts with a followed by at least three b's
rollowed by at least one a or one b that is strings are like a b 3 a, abbbbba,··· ···
So regular expression is :
r=ab 3 b*(a+bt
Here + is positive closure i.e. (a+bt =(a+b)*-E
Exampl~ Write the regular expression/or the language L = {w:1 wi mod 3 = o}, WE (a, b)'
Solulion: Let us first understand are meaning of 1 W I mod 3 = O. When length of string
belongs to the language L, is di vided by 3 then reminder should be 0 that is length of w must
be 0, 3, 6, 9... ... Clearl y multiple of three.
SOlulioll: /I" (w) mod 3 = 0 means , number of a's in string should be 0, 3, 6, 9 ......
So regular expression is :