Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROGRAMMING LANGUAGES

Similar presentations


Presentation on theme: "PROGRAMMING LANGUAGES"— Presentation transcript:

1 PROGRAMMING LANGUAGES
CS 222 HW1 SOL PROGRAMMING LANGUAGES

2 There are 3 cases : (a ) + ( b )+( c )
The regular expression of the string over Σ={a,b,c} in which all the a’sprecede the b’swhich in turn precede the c’s, but without the empty string. Sol : String in R : a,b,c,ab,ac,bc,aa,bb,cc,aab,aac,bbc,aac,abbcc,bccc String not in R : ,ba,ca,cb,cab,acb,bbba,… There are 3 cases : (a ) + ( b )+( c ) R = ( aa*b*c*) + (a*b*bc*) + (a*b*cc*) R = (a+b*c*) + (a*b+c*) + (a*b*c+) a+ b+ c+

3 The string are combination of 1 and 01 such as 1 01 = 101
The regular expression of the string over ={0,1} in which the string end with 1 and does not contain the substring 00. Sol : String in R : 1,01,11,011,101,111,1011,010101, ,… String not in R : ,00,10,001,1001,1100,… The string are combination of 1 and 01 such as = 101 = 111 , = R = (1+01)+

4 We need odd-length strings , which is even-length + 1. So that ,
The regular expression of the string over ={a,b} consists of all odd-length strings Sol : String in R : a,b,aaa,bbb,aab,aba,abb,bba,abbba,… String not in R : ,ab,ba,aa,bb,abab,abba,aaaa,bbbb,… The even-length strings are the combination of aa,ab,ba,bb such as aa ba = aaba , ab ab = abab, bb aa = bbaa . (aa + ab + ba + bb)* We need odd-length strings , which is even-length + 1. So that , R = (aa + ab + ba + bb)*(a + b)

5 The pattern of string is a b b cc
The regular expression of the string over ={a,b,c} that begin with a, contain exactly two b's, and end with cc. Sol : String in R : abbcc,aaaabcaacbaaacacc,acccaacbacacbcacacc,… String not in R : ,ab,abc,abbc,babb,bacc,abcc,… The pattern of string is a b b cc R = a(a + c)*b(a + c)*b(a + c)*cc (a+c)* (a+c)* (a+c)*

6 Every “a” must be followed by b or c. R = (b + c + a(b + c))*(λ + a)
The regular expression of the string over ={a,b,c} that do not contain substring aa. Sol : String in R : ,a,b,c,ab,ac,ba,bc,ca,cb,aba,bbb,ccc,babbbac,… String not in R :,aab,baabc,bcaa,… Every “a” must be followed by b or c. R = (b + c + a(b + c))*(λ + a)

7 There are two cases : 1. even number of a’s or 2. odd number of b’s
The regular expression of the string over ={a,b} with an even number of a's or an odd number of b's. Sol : String in R : ,aa,b,ab,ba,bc,aba,bbb,abab,baba,babab,… String not in R : a,bab,bba,… There are two cases : 1. even number of a’s or odd number of b’s Even number of a’s : b* a b* a b* => (b*ab*ab*)* Odd number of b’s : (a*ba*ba*)* a*ba* => (a*ba*ba*)*a*ba* R = ((b*ab*ab*)* + (a*ba*ba*)*a*ba*) Even # b

8 The string pattern is : (ba+ca+ab+ac)
The regular expression of the string over ={a,b,c} with an even length and contain exactly one a. Sol : String in R : ba,ab,ac,ca,cbac,bcab,bcba,abbbcccb, … String not in R : ,a,b,c,bab,bba,… The string pattern is : (ba+ca+ab+ac) E(b+c) = (bb+bc+cb+cc)* = ((b+c)(b+c))* R = ((b+c)(b+c))*(b+c)a((b+c)(b+c))* (b+c)a+a(b+c) E(b+c) E(b+c)

9 There are four cases : 1. ab b 2. ba b 3. b ab 4. b ba
The regular expression of the string over ={a,b} with an odd length and contain exactly two b’s. Sol : String in R : abb,bab,bba,aababaa,aabaaba,abaabaa,abaaba,ababa… String not in R : ,a,abab,bbaa,ab,bbb,… There are four cases : ab b ba b b ab b ba E(a) = (aa)* , O(a) = (aa)*a R = (aa)*((ab+ba)(aa)*b+(bb+(ab+ba)(aa)*ab)a)(aa)* E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a)


Download ppt "PROGRAMMING LANGUAGES"

Similar presentations


Ads by Google