• 沒有找到結果。

The exercises of Chapter Two

N/A
N/A
Protected

Academic year: 2021

Share "The exercises of Chapter Two"

Copied!
35
0
0

加載中.... (立即查看全文)

全文

(1)

The exercises of Chapter Two

2.1 Write regular expression for the following character sets, or give reasons why no regular expression can be written:

a. All strings of lowercase letters that begin and end in a.

[Solution]

a[a-z]*a | a

b. All strings of lowercase letters that either begin or end in a ( or both) both: a(a|b|c|…|z)* a

c. All strings of digits that contain no leading zeros [Solution]

[1-9][0-9]*

d. All strings of digits that represent even numbers (0|1|2|…|9)*(0|2|4|6|8)

e. All strings of digits such that all the 2’s occur before all the 9’s [Solution]

a=(0|1|3|4|5|6|7|8) r=(2|a)*(9|a)

or

[^9]*[^2]*

or

[^9]*2(1|[3-8])*9[^2]*

g. All strings of a’s and b’s that contain an odd number of a’s or an odd number of b’s(or both)

[Solution]

r1=b*a(b|ab*a)*---odd number of a’s r2= a*b(a|ba*b)*---odd number of b’s r1|r2|r1r2|r2r1

or

b*a(b*ab*a)*b*|a*b(a*ba*b)*a*

i. All strings of a’s and b’s that contain exactly as many a’s as b’s [Solution]

No regular expression can be written, as regular expression can not count.

2.2 Write English descriptions for the languages generated by the following regular expressions:

a. (a|b)*a(a|b|ε) [Solution]

(2)

All the strings of a’s and b’s that end with a, ab or aa.

Or

All the strings of a’s and b’s that do not end with bb.

b. All words in the English alphabet of one or more letters, which start with one capital letter and don’t contain any other capital letters.

c. (aa|b)*(a|bb)* [Solution]

All the strings of a’s and b’s that can be divided into two sub-stings, where in the left substring, the even number of consecutive a’s are separated by b’s while in the right substring, the even number of consecutive b’ are separated by a’s.

d. All hexadecimal numbers of length one or more, using the numbers zero through nine and capital letters A through F, and they are denoted with a lower or uppercase “x” at the end of the number string.

2.12 a. Use Thompson’s construction to convert the regular expression (a|b)*a(a|b|ε) into an NFA.

b. Convert the NFA of part (a) into a DFA using the subset construction.

[Solution]

a. An NFA of the regular expression (a|b)*a(a|b|ε)

b. The subsets constructed as follows:

{ 7 } = { 7, 5,1,3,8,9}

{ 7 }a = {2, 10}

{ 7 }b= {4}

ε

ε b a b a

a

ε ε

ε

ε ε ε ε

ε ε

ε ε

ε

7 5

1 2

3 4

6 8 9

17

11 12

13 14

15 16

18

ε ε

ε

10

(3)

{2,10} = {2,6,5,1,3,8,9, 10,17,11,13,15,16,18}

{2,10}a = {2, 10, 12}

{2,10}b ={4, 14}

{2,10,12} = {2,6,5,1,3,8,9,12,18,10,17,11,13,15,16}

{2,10,12}a = {2,10,12}

{2,10,12}b = {4, 14}

{4,14} = {4,6,5,1,3,8,9,14,18}

{4,14}a = {2,10}

{4,14}b = {4}

{4} = {4,6,5,1,3,8,9}

{4}a ={2,10}

{4}

2.15

b ={4}

Assume we have r* and s* according to figure 1 and 2:

Consider r*s* as follow

This accepts, for example, rsrs which is not in r*s*. I. e., in this case we cannot eliminate the concatenating ε transition.

2.16 Apply the state minimization algorithm of section 2.4.4 to the following DFAs:

a.

b a a

1

2 3

5 4 a

a

a

b

b b

b

c c

1

2 4

3 5

a

b r

ε ε

Figure 1 r*

s

ε ε

Figure 2 s*

r

ε ε

s

ε ε

Figure 2 r*s*

(4)

[Solution]

a. Step 1: Divide the state set into two subsets:

{1, 2, 3}

{4, 5}

Step 2: Further divide the subset {1,2,3} into two new subsets:

{1}

{2, 3}

Step 3: Can not divide the subsets any more, finally obtains three subsets:

{1}

{2, 3}

{4, 5}

Therefore, the minimized DFA is:

[Solution]

b. Step 1: Divide the state set into two subsets:

{1, 2}

{3, 4, 5}

Step 2: Further divide the subset {1,2} into two new subsets:

{1}

{2}

Step 2: Further divide the subset {3,4,5} into two new subsets:

{3}

{4, 5}

Step 4: Can not divide the subsets any more, finally obtains three subsets:

{1}

{2}

{ 3}

{4, 5}

Therefore, the minimized DFA is:

c c

1

2 4

3 a

b

c c

1

2 4

3 5

a

b

(5)

(6)

(7)

(8)

(9)

(10)

(11)

(12)

(13)

(14)

(15)

(16)

(17)

(18)

(19)

(20)

(21)

(22)

(23)

(24)

(25)

(26)

(27)

(28)

(29)

(30)

(31)

(32)

(33)

(34)

(35)

參考文獻

相關文件

[This function is named after the electrical engineer Oliver Heaviside (1850–1925) and can be used to describe an electric current that is switched on at time t = 0.] Its graph

•In a stable structure the total strength of the bonds reaching an anion from all surrounding cations should be equal to the charge of the anion.. Pauling’ s rule-

6 《中論·觀因緣品》,《佛藏要籍選刊》第 9 冊,上海古籍出版社 1994 年版,第 1

‰ For example Competition Provisions in Hong Kong Chapter 106 Telecommunication Ordinances 7K : S.1 A licensee (entity) shall not engage in conduct which, in the opinion of

The case where all the ρ s are equal to identity shows that this is not true in general (in this case the irreducible representations are lines, and we have an infinity of ways

the composition presented by T101 〉, “ First, the style of writing: by and large, these s ū tras are translated into prose.. Even though there are some verse-like renderings,

• elearning pilot scheme (Four True Light Schools): WIFI construction, iPad procurement, elearning school visit and teacher training, English starts the elearning lesson.. 2012 •

 name common laboratory apparatus (e.g., beaker, test tube, test-tube rack, glass rod, dropper, spatula, measuring cylinder, Bunsen burner, tripod, wire gauze and heat-proof