Xây dựng NFAε chấp nhận lớp ngôn ngữ được biểu diễn bởi biểu thức chính quy

Một phần của tài liệu Tài liệu ÔTÔMÁT HỮU HẠN VÀ BIỂU THỨC CHÍNH QUY docx (Trang 52 - 55)

III. st ng đ ng gi a otomat hu hn và bi uự ươ ươ ể

a. Xây dựng NFAε chấp nhận lớp ngôn ngữ được biểu diễn bởi biểu thức chính quy

được biểu diễn bởi biểu thức chính quy

r = (00 + 1)*

b. Xây dựng NFAε chấp nhận lớp ngôn ngữ được biểu diễn bởi biểu thức chính quy được biểu diễn bởi biểu thức chính quy

Exercise Questions on Regular Language and Regular Expression

 Ex. 1: Find the shortest string belong to alphabet (a,b) that is not in the language represented by (a,b) that is not in the language represented by the regular expression a*(ab)*b*.

 Solution: It can easily be seen that ε, a, b, which are strings in the language with length 1 or less. are strings in the language with length 1 or less. Of the strings with length 2 aa, bb and ab are in the language. However, ba is not in it. Thus the answer is ba.

 Ex. 2: For the two regular expressions given below,

 (a) find a string corresponding to r2 but not to r1 and

 (b) find a string corresponding to both r1 and r2.

 r1 = a* + b* r2 = ab* + ba* + b*a + (a*b)*

 Solution: (a) Any string consisting of only a's or only b's and the empty string are in r1. So we need to find strings of r2 which contain at least one a and at least one b. For example ab and ba are such strings.

 (b) A string corresponding to r1 consists of only a's or only b's or the empty string. The only strings

corresponding to r2 which consist of only a's or b's are a, b and the strings consiting of only b's (from (a*b)*).

 Ex3: Find a regular expression corresponding to the language L over the alphabet { a , b } defined recursively as follows:

 Basis Clause: ε ∈ L

 Inductive Clause: If x ∈ L , then aabx ∈ L and xbb ∈ L .

 Extremal Clause: Nothing is in L unless it can be obtained from the above two clauses.

 Solution: Let us see what kind of strings are in L. First of all ε ∈ L . Then starting with ε , strings of L are generated one by one by prepending aab or appending bb to any of the already generated strings. Hence a string of L consists of zero or more aab's in front and zero or more bb's following them. Thus (aab)*(bb)* is a

regular expression for L.

Một phần của tài liệu Tài liệu ÔTÔMÁT HỮU HẠN VÀ BIỂU THỨC CHÍNH QUY docx (Trang 52 - 55)