Handout 8.docx

5
Tahir Naseem/Handout 8 -1- Theory of Automata and Formal Languages Lecture 8 Objectives Regular Expression o omplex Example Example 1 ! Language "#$ a#$ aa#$ aaa#$ aaaa#$ aaaaa#$ %%& o'er ( ) " a #& Here a is repeating itself * to n times and then # appear at the and +o rule 1$ ,# and ,d ill #e exe.uted R E ) a0# Example 2 ! Language "a$ a#$ aa#$ aaa#$ aaaa#$ aaaaa#$ %%& o'er ( ) " a #& R E ) a aa0# Example 3 ! Language "#a$ #a#$ #aa#$ #aaa#$ #aaaa#$ #aaaaa#$ %%& o'er ( ) " a #& R E )#a #aa0# Example 4 ! Language ha'ing ords .ontaining at least t o a2s o'er ( ) " a #& R E )3a #40 a 3a #40 a 3a #40

Transcript of Handout 8.docx

Tahir Naseem/Handout 8-1-Theory of Automata and Formal LanguagesLecture 8

Objectives Regular Expression Complex ExampleExample 1:Language {b, ab, aab, aaab, aaaab, aaaaab, } over = { a b} Here a is repeating itself 0 to n times and then b appear at the and So rule 1, 2b and 2d will be executedR.E = a*bExample 2:Language {a, ab, aab, aaab, aaaab, aaaaab, } over = { a b}R.E = a+aa*bExample 3:Language {ba, bab, baab, baaab, baaaab, baaaaab, } over = { a b}R.E =ba+baa*bExample 4:Language having words containing at least two as over = { a b}R.E =(a+b)* a (a+b)* a (a+b)*

Example 5:Language having words containing exactly two as over = { a b}R.E =(b)* a (b)* a (b)*Example 6:Language having words containing only one substring ab over = { a b}R.E = a*b*Example 7:Language having words containing only one substring ba over = { a b}R.E = b*a*Example 8:Language having words does not containing any substring ba over = { a b}R.E = a*b*Example 9:Language having words does not containing any substring ab over = { a b}R.E = b*a*Example 10:Language having words containing at least one double aa over = { a b}R.E = (a + b)* aa (a + b)*

Example 11:Language having words containing at least one double bb over = { a b}R.E = (a + b)* bb (a + b)*Example 12:Language having words containing at least one double bb or one double aaover = { a b}R.E = (a + b)* (bb + aa) (a + b)*Example 13:Language having words ends on aaover = { a b}R.E = (a + b)* aaExample 14:Language having words ends on bbover = { a b}R.E = (a + b)* bbExample 15:Language having words starts with aaover = { a b}R.E = aa(a + b)* Example 16:Language having words starts with aa and ends with bbover = { a b}R.E = aa(a + b)*bb

Example 17:Language having words starts with aba and ends with babover = { a b}R.E = aba(a + b)*babExample 18:Language having words with even number of as and bsover = { a b}R.E = (aa + bb + (ab + ba)(aa + bb)* (ab + ba))*Example 19:Language having words of even lengthover = { a b}R.E = ((a + b)(a + b))* Example 20:Language having words of odd lengthover = { a b}R.E = (a +b) ((a + b)(a + b))* Example 21:Language having words containing at least one a and one bover = { a b}R.E =((a +b)*a(a + b)*) + ((a + b)* b (a + b)*) More Examples: Let us consider languages over an alphabet consisting of two letters: ={a, b}. Give the regular expressions corresponding to the informally defined languages below: - All words starting with aa. Solution: aa (a | b)* - All words containing aa. Solution: (a | b)* aa (a | b)* - All words containing an even number of letters. Solution: ((a | b)(a | b))* - All words containing an even number of letter a. Solution: (b*a b*a b*)* - All words which length is a multiple of 5. Solution: ((a | b)(a | b)(a | b)(a | b)(a | b))* - All words containing three consecutive a. Solution: (a | b)* aaa (a | b)* - All words which do not contain three consecutive a. Solution: (b* (ab+)* (aab+)* b*)* | (b* (ab+)* (aab+)* b*)* (a | aa)

Regular ExpressionRegular set

An expression built up from the previous rulesThe set of strings that the expression denotes

Let = {0,1}

00{00}

(0 + 1)*{, 0, 1, 00, 01, 10, 11, 000, , 111, }

(0 + 1)*00(0 + 1)*The set of binary strings containing 00{00, 000, 100, 001, 1001, 1100, 10100, }

(0 + 1)*011The set of binary strings ending with 011{011, 0011, 1011, 01011, 10011, }

Now, let = {0, 1, 2}

0*1*2*The set of strings consisting of an arbitrary number of 0s followed by an of 1s and finally byan of 2s.

{, 0, 1, 2, 011, 1112, 011222, }