草庐IT

【编译原理】第二章部分课后题答案

不牌不改 2023-07-13 原文

《编译原理(第三版)》陈意云著

第 二 章 课 后 习 题

T 2.3

叙述由下列正规式描述的语言

  1.    0    (    0    ∣    1    )   ∗    0 \space\space0\space\space(\space\space 0\space\space |\space\space 1\space\space)^{\space*\space\space}0   0  (  0    1  )   0

    正规式规定开头和结尾必须包括0,中间由0或1的闭包构成,可以看出该正规式描述的语言包含的串长度至少为2,所以总结为:以0开头和结尾的长度至少是2的串01.

  2.    (    (    ε    ∣    0    )    1   ∗    )   ∗ \space\space(\space\space (\space\space \varepsilon\space\space|\space\space0\space\space)\space\space1^{\space*\space\space}) ^{\space*}   (  (  ε    0  )  1   ) 

    内层括号中是对空和0的选择,再与外面的1的闭包相连接,可能构成的串有: ε \varepsilon ε 1 1 1 1...1 1...1 1...1 0 0 0 01 01 01 01...1 01...1 01...1,再加上外层的闭包,可以让 0 0 0 的个数变成任意多且可以为空串的闭包,所以总结为:所有的01串(包含空串).

  3.    (    0    ∣    1    )   ∗    0    (    0    ∣    1    )    (    0    ∣    1    ) \space\space(\space\space0\space\space|\space\space1\space\space)^{\space*\space\space}0\space\space(\space\space0\space\space|\space\space1\space\space)\space\space(\space\space0\space\space|\space\space1\space\space)   (  0    1  )   0  (  0    1  )  (  0    1  )

    0    (    0    ∣    1    )    (    0    ∣    1    ) 0\space\space(\space\space0\space\space|\space\space1\space\space)\space\space(\space\space0\space\space|\space\space1\space\space) 0  (  0    1  )  (  0    1  )描述了长度为3,第一位为0的01串,在前面加上0或1的闭包使得串可以以任意二进制或空开头,所以结论为:至少包括三位且倒数第三位是0的01串.

  4.    0   ∗   10   ∗   10   ∗   10   ∗ \space\space0\space^*\space10\space^*\space10\space^*\space10\space^*   0  10  10  10 

    三个1是必然存在于串中的,而剩下0的闭包则说明0的个数为任意多,所以结论为:含有三个1的01串.

  5.    (    00    ∣    11    )   ∗    (    (    01    ∣    10    )    (    00    ∣    11    )   ∗    (    01    ∣    10    )    (    00    ∣    11    )   ∗    )   ∗ \space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space(\space\space(\space\space01\space\space|\space\space10\space\space)\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space(\space\space01\space\space|\space\space10\space\space)\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space)\space^*   (  00    11  )   (  (  01    10  )  (  00    11  )   (  01    10  )  (  00    11  )   ) 

    第一个闭包可以选择00或11,后面的两个内层闭包所描述的语言与第一个闭包相同,外层闭包让其内部的串可以出现任意次。由于该正规式过于复杂,所以可以将其描述的语言简单概括为:含有偶数(含0个)个0和偶数(含0个)个1的01串.


T 2.4

为下列语言写出正规定义

  1. 包含5个元音的所有字母串,其中每个元音只出现一次且按顺序排列。

    不含五个元音的任意字符: [ B − D F − H J − N P − T V − Z b − d f − h j − n p − t v − z ] [B-DF-HJ-NP-TV-Zb-df-hj-np-tv-z] [BDFHJNPTVZbdfhjnptvz],记为 α \alpha α

    故, α   ∗    (    a    ∣    A    )    α   ∗    (    e    ∣    E    )    α   ∗    (    i    ∣    I    )    α   ∗    (    o    ∣    O )    α   ∗    (    u    ∣    U    )    α   ∗ \alpha\space^*\space\space(\space\space a\space\space|\space\space A\space\space)\space\space\alpha\space^*\space\space(\space\space e\space\space|\space\space E\space\space)\space\space\alpha\space^*\space\space(\space\space i\space\space|\space\space I\space\space)\space\space\alpha\space^*\space\space(\space\space o\space\space|\space\space O)\space\space\alpha\space^*\space\space(\space\space u\space\space|\space\space U\space\space)\space\space \alpha\space^* α   (  a    A  )  α   (  e    E  )  α   (  i    I  )  α   (  o    O)  α   (  u    U  )  α 

  2. 按词典序排列的所有字母串。

    A   ∗    a   ∗    B   ∗    b   ∗    . . .    Z   ∗    z   ∗ A\space^*\space\space a\space^*\space\space B\space^*\space\space b\space^*\space\space...\space\space Z\space^*\space\space z\space^* A   a   B   b   ...  Z   z 

  3. 某语言的注释,它是以 / ∗ /* /开始并以 ∗ / */ /结束的任意字符串,但它的任何前缀(本身除外)不以 ∗ / */ /结尾。

    不含 / / / ∗ * 的任意字符记为 α \alpha α

    不含 ∗ / */ /的任意字符串可以表示为 ( ∗ ∗ α + / ∗ ) ∗ (*^*\alpha^+/^*)^* (α+/)

    故, / ∗ ( ∗ ∗ α + / ∗ ) ∗ ∗ / /*(*^*\alpha^+/^*)^**/ /(α+/)/

  4. 相邻数字都不相同的所有数字串。

  5. 最多只有一处相邻数字相同的所有数字串。

  6. 由偶数个0和偶数个1组成的所有01串。

    (    00    ∣    11    )   ∗    (    (    01    ∣    10    )    (    00    ∣    11    )   ∗    (    01    ∣    10    )    (    00    ∣    11    )   ∗    )   ∗ (\space\space00\space\space|\space\space11\space\space)\space^*\space\space(\space\space(\space\space01\space\space|\space\space10\space\space)\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space(\space\space01\space\space|\space\space10\space\space)\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space)\space^* (  00    11  )   (  (  01    10  )  (  00    11  )   (  01    10  )  (  00    11  )   ) 

  7. 由偶数个0和奇数个1组成的所有01串。

    1    (    00    ∣    11    )   ∗    (    (    01    ∣    10    )    (    00    ∣    11    )   ∗    (    01    ∣    10    )    (    00    ∣    11    )   ∗    )   ∗ 1\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space(\space\space(\space\space01\space\space|\space\space10\space\space)\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space(\space\space01\space\space|\space\space10\space\space)\space\space(\space\space00\space\space|\space\space11\space\space)\space^*\space\space)\space^* 1  (  00    11  )   (  (  01    10  )  (  00    11  )   (  01    10  )  (  00    11  )   ) 

  8. 不含字串011的01串。

    (    1   ∗    (    0   +    1    )   ∗    )    0   ∗ (\space\space1\space^*\space\space(\space\space 0\space^+\space\space1\space\space)\space^*\space\space)\space\space0\space^* (  1   (  0 +  1  )   )  0 

  9. 字母表 { a , b } \{a, b\} {a,b}上, a a a不会相邻出现的所有串。

    b   ∗    (    a   ?    b   +    )   ∗    a   ? b\space^*\space\space(\space\space a\space?\space\space b\space^+\space\space)\space^*\space\space a\space? b   (  a ?  b +  )   a ?


T 2.7

用算法 2.4 为下列正规式构造不确定有限自动机,给出它们处理输入串 a b a b b a b ababbab ababbab 的状态转化序列

  1. (    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  ) 

方式一:(算法 2.4)

a b a b b a b    :    s → 0 → 1 → 3 → 5 → 0 → 2 → 4 → 5 → 0 → 1 → 3 → 5 → 0 → 2                               → 4 → 5 → 0 → 2 → 4 → 5 → 0 → 1 → 3 → 5 → 0 → 2 → 4 → 5 → f ababbab\space\space :\space\space s\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\rightarrow2\rightarrow4\rightarrow5\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\rightarrow2\\\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\rightarrow4\rightarrow5\rightarrow0\rightarrow2\rightarrow4\rightarrow5\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\rightarrow2\rightarrow4\rightarrow5\rightarrow f ababbab  :  s01350245013502                             45024501350245f

方式二:(分裂法)

a b a b b a b    :    s → 0 → 1 → 0 → 1 → 0 → 1 → 0 → 1 → 0 → 1 → 0 → 1 → 0 → 1 → f ababbab\space\space :\space\space s\rightarrow0\rightarrow1\rightarrow0\rightarrow1\rightarrow0\rightarrow1\rightarrow0\rightarrow1\rightarrow0\rightarrow1\rightarrow0\rightarrow1\rightarrow0\rightarrow1\rightarrow f ababbab  :  s01010101010101f

方式三:

a b a b b a b    :    s → 0 → 0 → 0 → 0 → 0 → 0 → 0 → 0 → f ababbab\space\space :\space\space s\rightarrow0\rightarrow0\rightarrow0\rightarrow0\rightarrow0\rightarrow0\rightarrow0\rightarrow0\rightarrow f ababbab  :  s00000000f

  1. (    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   ) 

a b a b b a b    :    s → 0 → 1 → 3 → 5 → 0 → 2 → 4 → 5 → 0 → 1 → 3 → 5 → 0                                → 2 → 4 → 2 → 4 → 5 → 0 → 1 → 3 → 5 → 0 → 2 → 4 → 4 → f ababbab\space\space :\space\space s\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\rightarrow2\rightarrow4\rightarrow5\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\\\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\rightarrow2\rightarrow4\rightarrow2\rightarrow4\rightarrow5\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\rightarrow2\rightarrow4\rightarrow4\rightarrow f ababbab  :  s0135024501350                              2424501350244f

  1. (    (    ε    ∣    a    )    b   ∗    )   ∗ (\space\space(\space\space \varepsilon\space\space |\space\space a\space\space)\space\space b\space^*\space\space)\space^* (  (  ε    a  )  b   ) 

a b a b b a b    :    s → 0 → 1 → 3 → 5 → 6 → 7 → 8 → 0 → 1 → 3 → 5 → 6                        → 7 → 6 → 7 → 8 → 0 → 1 → 3 → 5 → 6 → 7 → 8 → f ababbab\space\space :\space\space s\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow6\rightarrow7\rightarrow8\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow6\\\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\rightarrow7\rightarrow6\rightarrow7\rightarrow8\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow6\rightarrow7\rightarrow8\rightarrow f ababbab  :  s013567801356                      76780135678f

  1. (    a    ∣    b    )   ∗    a    b    b    (    a    ∣    b    )   ∗ (\space\space a \space\space | \space\space b\space\space) \space^*\space\space a\space\space b\space\space b\space\space(\space\space a \space\space | \space\space b \space\space)\space^* (  a    b  )   a  b  b  (  a    b  ) 

a b a b b a b    :    s → 0 → 1 → 3 → 5 → 0 → 2 → 4 → 5 → 6 → 7 → 8 → 9 → 10 → 11 → 13 → 15 → 10 → 12 → 14 → 15 → f ababbab\space\space :\space\space s\rightarrow0\rightarrow1\rightarrow3\rightarrow5\rightarrow0\rightarrow2\rightarrow4\rightarrow5\rightarrow6\rightarrow7\rightarrow8\rightarrow9\rightarrow10\rightarrow11\rightarrow13\rightarrow15\rightarrow10\rightarrow12\rightarrow14\rightarrow15\rightarrow f ababbab  :  s0135024567891011131510121415f


T 2.8

用算法2.2把习题2.7中的第三问的NFA变换成DFA。给出它们处理输入串 a b a b b a b ababbab ababbab 的状态转换序列

为了书写的方便,将上面 NFA 中的状态重新编号,得到下图:

上图的 NFA 等价的 DFA 的开始状态是 ε − c l o s u r e ( 0 ) \varepsilon-closure(0) εclosure(0),记为 A = { 0 , 1 , 2 , 4 , 5 , 6 , 7 , 9 , 10 } A=\{0,1,2,4,5,6,7,9,10\} A={0,1,2,4,5,6,7,9,10}

输入字母表是 { a , b } \{a,b\} {a,b} ,计算 ε − c l o s u r e ( m o v e ( A , a ) ) \varepsilon-closure(move(A,a)) εclosure(move(A,a)),由于只有状态 2 2 2 能发生 a a a 转换,所以 m o v e ( A , a ) = { 3 } move (A, a)=\{3\} move(A,a)={3},故 ε − c l o s u r e ( m o v e ( A , a ) ) = ε − c l o s u r e ( { 3 } ) = ε − c l o s u r e ( 3 ) = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 } \varepsilon-closure(move(A,a))=\varepsilon-closure(\{3\})=\varepsilon-closure(3)=\{1,2,3,4,5,6,7,9,10\} εclosure(move(A,a))=εclosure({3})=εclosure(3)={1,2,3,4,5,6,7,9,10},称该集合为 B B B

计算 ε − c l o s u r e ( m o v e ( A , b ) ) \varepsilon-closure(move(A,b)) εclosure(move(A,b)),由于只有状态 7 7 7 能发生 b b b 转换,所以 m o v e ( A , b ) = 8 move(A, b)={8} move(A,b)=8,故 ε − c l o s u r e ( m o v e ( A , b ) ) = ε − c l o s u r e ( { 8 } ) = ε − c l o s u r e ( 8 ) = { 1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } \varepsilon-closure(move(A,b))=\varepsilon-closure(\{8\})=\varepsilon-closure(8)=\{1,2,4,5,6,7,8,9,10\} εclosure(move(A,b))=εclosure({8})=εclosure(8)={1,2,4,5,6,7,8,9,10},称该集合为 C C C

对新集合 B B B C C C 重复上面的过程可以得到完整的转换表如下:

状态输入符号
ab
ABC
BBC
CBC

根据转换表得到等价的 DFA 如下:

a b a b b a b    :    A → B → C → B → C → C → B → C ababbab\space\space :\space\space A\rightarrow B \rightarrow C \rightarrow B \rightarrow C \rightarrow C \rightarrow B \rightarrow C ababbab  :  ABCBCCBC


T 2.11

可以从正规式的最简 DFA 同构来证明两个正规式等价。使用这种计数,证明正规式 (    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  (    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   )  (    (    ε    ∣    a    )    b   ∗    )   ∗ (\space\space(\space\space \varepsilon\space\space |\space\space a\space\space)\space\space b\space^*\space\space)\space^* (  (  ε    a  )  b   )  等价

与 T 2.8 类似,先将上面的 NFA 中的状态重新编号便于计算。

(    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  对应的 NFA:

(    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  对应的状态转换表:

A = { 0 , 1 , 2 , 4 , 7 } A=\{0,1,2,4,7\} A={0,1,2,4,7}

B = { 1 , 2 , 3 , 4 , 6 , 7 } B=\{1,2,3,4,6,7\} B={1,2,3,4,6,7}

C = { 1 , 2 , 4 , 5 , 6 , 7 } C=\{1,2,4,5,6,7\} C={1,2,4,5,6,7}

状态输入符号
ab
ABC
BBC
CBC

(    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  对应的 DFA:

(    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  对应的最简 DFA:

初始划分两个子集:接受状态子集 { B ,   C } \{B,\space C\} {B, C} 和非接受状态 { A } \{A\} {A}

{ A } \{A\} {A} 不可进一步划分,所以对 { B ,   C } \{B,\space C\} {B, C} 进一步划分;

m o v e ( { B ,   C } ,   a ) = { B } move(\{B, \space C\},\space a)=\{B\} move({B, C}, a)={B}

m o v e ( { B ,   C } ,   b ) = { C } move(\{B, \space C\},\space b)=\{C\} move({B, C}, b)={C}

这说明 { B ,   C } \{B,\space C\} {B, C} 是不可区分的子集,故无需进一步划分。

最终上图即为最简 DFA。


(    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   )  对应的 NFA:

(    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   )  对应的状态转换表:

A = { 0 , 1 , 2 , 4 , 7 } A=\{0,1,2,4,7\} A={0,1,2,4,7}

B = { 1 , 2 , 3 , 4 , 6 , 7 } B=\{1,2,3,4,6,7\} B={1,2,3,4,6,7}

C = { 1 , 2 , 4 , 5 , 6 , 7 } C=\{1,2,4,5,6,7\} C={1,2,4,5,6,7}

状态输入符号
ab
ABC
BBC
CBC

(    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   )  对应的 DFA:

(    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   )  对应的最简 DFA:

由于 (    a   ∗    ∣    b   ∗    )   ∗ (\space\space a\space^*\space\space|\space\space b\space^*\space\space)\space^* (  a     b   )  对应的 DFA 与 (    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  对应的 DFA 完全一致,所以最终化简得到的 DFA 也是一样的,即上图。


(    (    ε    ∣    a    )    b   ∗    )   ∗ (\space\space(\space\space \varepsilon\space\space |\space\space a\space\space)\space\space b\space^*\space\space)\space^* (  (  ε    a  )  b   )  的 DFA 在 T 2.8 中已经得到,由于其与 (    a    ∣    b    )   ∗ (\space\space a\space\space|\space\space b\space\space)\space^* (  a    b  )  对应的 DFA 完全一致,所以最终化简得到的 DFA 也是一样的,即:

由于已知“最简 DFA 同构的正规式等价”可知,三者的最简 DFA 同构,所以三个正规式等价。


T 2.12

为下列正规式构造最简的 DFA

  1.    (    a    ∣    b    )   ∗    a    (    a    ∣    b    ) \space\space(\space\space a\space\space | \space\space b\space\space)\space^*\space\space a\space\space (\space\space a \space\space |\space\space b\space\space)   (  a    b  )   a  (  a    b  )

对应的 NFA 如下:

对应的转换表如下:

A = { 0 , 1 , 2 , 4 , 7 } A=\{0,1,2,4,7\} A={0,1,2,4,7}

B = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 } B=\{1,2,3,4,6,7,8,9,11\} B={1,2,3,4,6,7,8,9,11}

C = { 1 , 2 , 4 , 5 , 6 , 7 } C=\{1,2,4,5,6,7\} C={1,2,4,5,6,7}

D = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 } D = \{1,2,3,4,6,7,8,9,10,11,13,14\} D={1,2,3,4,6,7,8,9,10,11,13,14}

E = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 } E=\{1,2,4,5,6,7,12,13,14\} E={1,2,4,5,6,7,12,13,14}

状态输入符号
ab
ABC
BDE
CBC
DDE
EBC

对应的 DFA 如下:

对应的最简 DFA 如下:

初始划分两个子集:接受状态子集 { D , E } \{D,E\} {D,E} 和非接受状态子集 { A , B , C } \{A,B,C\} {A,B,C}

对于接受状态子集,输入字符 a a a,状态 D D D 和状态 E E E 分别变换到状态 D D D 和状态 B B B,二者不在同一子集中,所以需要划分成 { D } \{D\} {D} { E } \{E\} {E}

对于非接受状态子集,输入字符 a a a,状态 A A A 和状态 C C C 均变换到状态 B B B,而状态 B B B 变换到状态 D D D,属于另一个子集,所以初步划分为 { A , C } \{A,C\} {A,C} { B } \{B\} {B};输入字符 b b b,状态 A A A 和状态 C C C 均变换到状态 C C C,所以两个状态不可区分,无需进一步划分。

故,最终状态子集为 { A , C } \{A,C\} {A,C} { B } \{B\} {B} { D } \{D\} {D} { E } \{E\} {E}

为了绘制 DFA 方便,令 { A , C } \{A,C\} {A,C} 为状态 0 0 0 { B } \{B\} {B} 为状态 1 1 1 { D } \{D\} {D} 为状态 2 2 2 { E } \{E\} {E} 为状态 3 3 3


  1.    (    a    ∣    b    )   ∗    a    (    a    ∣    b    )    (    a    ∣    b    ) \space\space(\space\space a\space\space | \space\space b\space\space)\space^*\space\space a\space\space (\space\space a \space\space |\space\space b\space\space)\space\space(\space\space a \space\space |\space\space b\space\space)   (  a    b  )   a  (  a    b  )  (  a    b  )

方法一: 子集构造法得到的 NFA 如下:

对应的转换表如下:

A = { 0 , 1 , 2 , 4 , 7 } A=\{0,1,2,4,7\} A={0,1,2,4,7}

B = ε − c l o s u r e ( { 3 , 8 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 } B=\varepsilon-closure(\{3,8\})=\{1,2,3,4,6,7,8,9,11\} B=εclosure({3,8})={1,2,3,4,6,7,8,9,11}

C = ε − c l o s u r e ( { 5 } ) = { 1 , 2 , 4 , 5 , 6 , 7 } C=\varepsilon-closure(\{5\})=\{1,2,4,5,6,7\} C=εclosure({5})={1,2,4,5,6,7}

D = ε − c l o s u r e ( { 3 , 8 , 10 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 16 } D=\varepsilon-closure(\{3,8,10\})=\{1,2,3,4,6,7,8,9,10,11,13,14,16\} D=εclosure({3,8,10})={1,2,3,4,6,7,8,9,10,11,13,14,16}

E = ε − c l o s u r e ( { 5 , 12 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 , 16 } E=\varepsilon-closure(\{5,12\})=\{1,2,4,5,6,7,12,13,14,16\} E=εclosure({5,12})={1,2,4,5,6,7,12,13,14,16}

F = ε − c l o s u r e ( { 3 , 8 , 10 , 15 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 15 , 16 , 18 , 19 } F=\varepsilon-closure(\{3,8,10,15\})=\{1,2,3,4,6,7,8,9,10,11,13,14,15,16,18,19\} F=εclosure({3,8,10,15})={1,2,3,4,6,7,8,9,10,11,13,14,15,16,18,19}

G = ε − c l o s u r e ( { 5 , 12 , 17 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 , 16 , 17 , 18 , 19 } G=\varepsilon-closure(\{5,12,17\})=\{1,2,4,5,6,7,12,13,14,16,17,18,19\} G=εclosure({5,12,17})={1,2,4,5,6,7,12,13,14,16,17,18,19}

H = ε − c l o s u r e ( { 3 , 8 , 15 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 , 15 , 18 , 19 } H=\varepsilon-closure(\{3,8,15\})=\{1,2,3,4,6,7,8,9,11,15,18,19\} H=εclosure({3,8,15})={1,2,3,4,6,7,8,9,11,15,18,19}

I = ε − c l o s u r e ( { 5 , 17 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 17 , 18 , 19 } I=\varepsilon-closure(\{5,17\})=\{1,2,4,5,6,7,17,18,19\} I=εclosure({5,17})={1,2,4,5,6,7,17,18,19}

状态输入符号
ab
ABC
BDE
CBC
DFG
EHI
FFG
GHI
HDE
IBC

方法二: 分裂法得到的 NFA 如下:

对应的转换表如下:

A = { 0 , 1 , 3 } A=\{0,1,3\} A={0,1,3}

B = ε − c l o s u r e ( { 2 , 4 } ) = { 1 , 2 , 3 , 4 } B=\varepsilon-closure(\{2,4\})=\{1,2,3,4\} B=εclosure({2,4})={1,2,3,4}

C = ε − c l o s u r e ( { 2 } ) = { 1 , 2 , 3 } C=\varepsilon-closure(\{2\})=\{1,2,3\} C=εclosure({2})={1,2,3}

D = ε − c l o s u r e ( { 2 , 4 , 5 } ) = B ∪ { 5 } = { 1 , 2 , 3 , 4 , 5 } D=\varepsilon-closure(\{2,4,5\})=B∪\{5\}=\{1,2,3,4,5\} D=εclosure({2,4,5})=B{5}={1,2,3,4,5}

E = ε − c l o s u r e ( { 2 , 5 } ) = C ∪ { 5 } = { 1 , 2 , 3 , 5 } E=\varepsilon-closure(\{2,5\})=C∪\{5\}=\{1,2,3,5\} E=εclosure({2,5})=C{5}={1,2,3,5}

F = ε − c l o s u r e ( { 2 , 4 , 5 , 6 } ) = D ∪ { 6 } = { 1 , 2 , 3 , 4 , 5 , 6 } F=\varepsilon-closure(\{2,4,5,6\})=D∪\{6\}=\{1,2,3,4,5,6\} F=εclosure({2,4,5,6})=D{6}={1,2,3,4,5,6}

G = ε − c l o s u r e ( { 2 , 5 , 6 } ) = E ∪ { 6 } = { 1 , 2 , 3 , 5 , 6 } G=\varepsilon-closure(\{2,5,6\})=E∪\{6\}=\{1,2,3,5,6\} G=εclosure({2,5,6})=E{6}={1,2,3,5,6}

H = ε − c l o s u r e ( { 2 , 4 , 6 } ) = B ∪ { 6 } = { 1 , 2 , 3 , 4 , 6 } H=\varepsilon-closure(\{2,4,6\})=B∪\{6\}=\{1,2,3,4,6\} H=εclosure({2,4,6})=B{6}={1,2,3,4,6}

I = ε − c l o s u r e ( { 2 , 6 } ) = C ∪ { 6 } = { 1 , 2 , 3 , 6 } I=\varepsilon-closure(\{2,6\})=C∪\{6\}=\{1,2,3,6\} I=εclosure({2,6})=C{6}={1,2,3,6}

状态输入符号
ab
ABC
BDE
CBC
DFG
EHI
FFG
GHI
HDE
IBC

可以看出“子集构造法”和“分裂法”得到的状态转换表一样,所以化出的DFA也一致。

对应的 DFA 如下:

对应的最简 DFA 如下:

初始划分两个子集:接受状态子集 { F , G , H , I } \{F,G,H,I\} {F,G,H,I} 和非接受状态子集 { A , B , C , D , E } \{A,B,C,D,E\} {A,B,C,D,E}

对于接受状态子集,分别输入字符 a a a 和字符 b b b,可将原集合划分为 { F , G } \{F,G\} {F,G} { H , I } \{H,I\} {H,I}

对于非接受状态子集,分别输入字符 a a a 和字符 b b b,可将原集合划分为 { A , B , C } \{A,B,C\} {A,B,C} { D , E } \{D,E\} {D,E}

{ F , G } \{F,G\} {F,G} 集合进一步划分成 { F } \{F\} {F} { G } \{G\} {G}

{ H , I } \{H,I\} {H,I} 集合进一步划分成 { H } \{H\} {H} { I } \{I\} {I}

{ A , B , C } \{A,B,C\} {A,B,C} 集合进一步划分成 { A , C } \{A, C\} {A,C} { B } \{B\} {B}

{ D , E } \{D,E\} {D,E} 集合进一步划分成 { D } \{D\} {D} { E } \{E\} {E}

故,最终状态子集为 { A , C } \{A,C\} {A,C} { B } \{B\} {B} { D } \{D\} {D} { E } \{E\} {E} { F } \{F\} {F} { G } \{G\} {G} { H } \{H\} {H} { I } \{I\} {I}

为了绘制 DFA 方便,令 { A , C } \{A,C\} {A,C} 为状态 0 0 0 { B } \{B\} {B} 为状态 1 1 1 { D } \{D\} {D} 为状态 2 2 2 { E } \{E\} {E} 为状态 3 3 3 { F } \{F\} {F} 为状态 4 4 4 { G } \{G\} {G} 为状态 5 5 5 { H } \{H\} {H} 为状态 6 6 6 { I } \{I\} {I} 为状态 7 7 7


  1.    (    a    ∣    b    )   ∗    a    (    a    ∣    b    )    (    a    ∣    b    )    (    a    ∣    b    ) \space\space(\space\space a\space\space | \space\space b\space\space)\space^*\space\space a\space\space (\space\space a \space\space |\space\space b\space\space)\space\space(\space\space a \space\space |\space\space b\space\space)\space\space(\space\space a \space\space |\space\space b\space\space)   (  a    b  )   a  (  a    b  )  (  a    b  )  (  a    b  )

方法一: 子集构造法得到的 NFA 如下:

对应的转换表如下:

A = { 0 , 1 , 2 , 4 , 7 } A=\{0,1,2,4,7\} A={0,1,2,4,7}

B = ε − c l o s u r e ( { 3 , 8 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 } B=\varepsilon-closure(\{3,8\})=\{1,2,3,4,6,7,8,9,11\} B=εclosure({3,8})={1,2,3,4,6,7,8,9,11}

C = ε − c l o s u r e ( { 5 } ) = { 1 , 2 , 4 , 5 , 6 , 7 } C=\varepsilon-closure(\{5\})=\{1,2,4,5,6,7\} C=εclosure({5})={1,2,4,5,6,7}

D = ε − c l o s u r e ( { 3 , 8 , 10 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 16 } D=\varepsilon-closure(\{3,8,10\})=\{1,2,3,4,6,7,8,9,10,11,13,14,16\} D=εclosure({3,8,10})={1,2,3,4,6,7,8,9,10,11,13,14,16}

E = ε − c l o s u r e ( { 5 , 12 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 , 16 } E=\varepsilon-closure(\{5,12\})=\{1,2,4,5,6,7,12,13,14,16\} E=εclosure({5,12})={1,2,4,5,6,7,12,13,14,16}

F = ε − c l o s u r e ( { 3 , 8 , 10 , 15 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 15 , 16 , 18 , 19 , 21 } F=\varepsilon-closure(\{3,8,10,15\})=\{1,2,3,4,6,7,8,9,10,11,13,14,15,16,18,19,21\} F=εclosure({3,8,10,15})={1,2,3,4,6,7,8,9,10,11,13,14,15,16,18,19,21}

G = ε − c l o s u r e ( { 5 , 12 , 17 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 , 16 , 17 , 18 , 19 , 21 } G=\varepsilon-closure(\{5,12,17\})=\{1,2,4,5,6,7,12,13,14,16,17,18,19,21\} G=εclosure({5,12,17})={1,2,4,5,6,7,12,13,14,16,17,18,19,21}

H = ε − c l o s u r e ( { 3 , 8 , 15 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 , 15 , 18 , 19 , 21 } H=\varepsilon-closure(\{3,8,15\})=\{1,2,3,4,6,7,8,9,11,15,18,19,21\} H=εclosure({3,8,15})={1,2,3,4,6,7,8,9,11,15,18,19,21}

I = ε − c l o s u r e ( { 5 , 17 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 17 , 18 , 19 , 21 } I=\varepsilon-closure(\{5,17\})=\{1,2,4,5,6,7,17,18,19,21\} I=εclosure({5,17})={1,2,4,5,6,7,17,18,19,21}

J = ε − c l o s u r e ( { 3 , 8 , 10 , 15 , 20 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 15 , 16 , 18 , 19 , 20 , 21 , 23 , 24 } J=\varepsilon-closure(\{3,8,10,15,20\})=\{1,2,3,4,6,7,8,9,10,11,13,14,15,16,18,19,20,21,23,24\} J=εclosure({3,8,10,15,20})={1,2,3,4,6,7,8,9,10,11,13,14,15,16,18,19,20,21,23,24}

K = ε − c l o s u r e ( { 5 , 12 , 17 , 22 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 , 16 , 17 , 18 , 19 , 21 , 22 , 23 , 24 } K=\varepsilon-closure(\{5,12,17,22\})=\{1,2,4,5,6,7,12,13,14,16,17,18,19,21,22,23,24\} K=εclosure({5,12,17,22})={1,2,4,5,6,7,12,13,14,16,17,18,19,21,22,23,24}

L = ε − c l o s u r e ( { 3 , 8 , 15 , 20 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 , 15 , 18 , 19 , 20 , 21 , 23 , 24 } L=\varepsilon-closure(\{3,8,15,20\})=\{1,2,3,4,6,7,8,9,11,15,18,19,20,21,23,24\} L=εclosure({3,8,15,20})={1,2,3,4,6,7,8,9,11,15,18,19,20,21,23,24}

M = ε − c l o s u r e ( { 5 , 17 , 22 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 17 , 18 , 19 , 21 , 22 , 23 , 24 } M=\varepsilon-closure(\{5,17,22\})=\{1,2,4,5,6,7,17,18,19,21,22,23,24\} M=εclosure({5,17,22})={1,2,4,5,6,7,17,18,19,21,22,23,24}

N = ε − c l o s u r e ( { 3 , 8 , 10 , 20 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 16 , 20 , 23 , 24 } N=\varepsilon-closure(\{3,8,10,20\})=\{1,2,3,4,6,7,8,9,10,11,13,14,16,20,23,24\} N=εclosure({3,8,10,20})={1,2,3,4,6,7,8,9,10,11,13,14,16,20,23,24}

O = ε − c l o s u r e ( { 5 , 12 , 22 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 12 , 13 , 14 , 16 , 22 , 23 , 24 } O=\varepsilon-closure(\{5,12,22\})=\{1,2,4,5,6,7,12,13,14,16,22,23,24\} O=εclosure({5,12,22})={1,2,4,5,6,7,12,13,14,16,22,23,24}

P = ε − c l o s u r e ( { 3 , 8 , 20 } ) = { 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 11 , 23 , 24 } P=\varepsilon-closure(\{3,8,20\})=\{1,2,3,4,6,7,8,9,11,23,24\} P=εclosure({3,8,20})={1,2,3,4,6,7,8,9,11,23,24}

Q = ε − c l o s u r e ( { 5 , 22 } ) = { 1 , 2 , 4 , 5 , 6 , 7 , 22 , 23 , 24 } Q=\varepsilon-closure(\{5,22\})=\{1,2,4,5,6,7,22,23,24\} Q=εclosure({5,22})={1,2,4,5,6,7,22,23,24}

状态输入符号
ab
ABC
BDE
CBC
DFG
EHI
FJK
GLM
HNO
IPQ
JJK
KLM
LNO
MPQ
NFG
OHI
PDE
QBC

可以看出“子集构造法”和“分裂法”得到的状态转换表一样,所以化出的DFA也一致。

方法二: 分裂法得到的 NFA 如下:

对应的转换表如下:

A = { 0 , 1 , 3 } A=\{0,1,3\} A={0,1,3}

B = ε − c l o s u r e ( { 2 , 4 } ) = { 1 , 2 , 3 , 4 } B=\varepsilon-closure(\{2,4\})=\{1,2,3,4\} B=εclosure({2,4})={1,2,3,4}

C = ε − c l o s u r e ( { 2 } ) = { 1 , 2 , 3 } C=\varepsilon-closure(\{2\})=\{1,2,3\} C=εclosure({2})={1,2,3}

D = ε − c l o s u r e ( { 2 , 4 , 5 } ) = B ∪ { 5 } = { 1 , 2 , 3 , 4 , 5 } D=\varepsilon-closure(\{2,4,5\})=B∪\{5\}=\{1,2,3,4,5\} D=εclosure({2,4,5})=B{5}={1,2,3,4,5}

E = ε − c l o s u r e ( { 2 , 5 } ) = C ∪ { 5 } = { 1 , 2 , 3 , 5 } E=\varepsilon-closure(\{2,5\})=C∪\{5\}=\{1,2,3,5\} E=εclosure({2,5})=C{5}={1,2,3,5}

F = ε − c l o s u r e ( { 2 , 4 , 5 , 6 } ) = D ∪ { 6 } = { 1 , 2 , 3 , 4 , 5 , 6 } F=\varepsilon-closure(\{2,4,5,6\})=D∪\{6\}=\{1,2,3,4,5,6\} F=εclosure({2,4,5,6})=D{6}={1,2,3,4,5,6}

G = ε − c l o s u r e ( { 2 , 5 , 6 } ) = E ∪ { 6 } = { 1 , 2 , 3 , 5 , 6 } G=\varepsilon-closure(\{2,5,6\})=E∪\{6\}=\{1,2,3,5,6\} G=εclosure({2,5,6})=E{6}={1,2,3,5,6}

H = ε − c l o s u r e ( { 2 , 4 , 6 } ) = B ∪ { 6 } = { 1 , 2 , 3 , 4 , 6 } H=\varepsilon-closure(\{2,4,6\})=B∪\{6\}=\{1,2,3,4,6\} H=εclosure({2,4,6})=B{6}={1,2,3,4,6}

I = ε − c l o s u r e ( { 2 , 6 } ) = C ∪ { 6 } = { 1 , 2 , 3 , 6 } I=\varepsilon-closure(\{2,6\})=C∪\{6\}=\{1,2,3,6\} I=εclosure({2,6})=C{6}={1,2,3,6}

J = ε − c l o s u r e ( { 2 , 4 , 5 , 6 , 7 } ) = F ∪ { 7 } = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } J=\varepsilon-closure(\{2,4,5,6,7\})=F∪\{7\}=\{1,2,3,4,5,6,7\} J=εclosure({2,4,5,6,7})=F{7}={1,2,3,4,5,6,7}

K = ε − c l o s u r e ( { 2 , 5 , 6 , 7 } ) = G ∪ { 6 } = { 1 , 2 , 3 , 5 , 6 , 7 } K=\varepsilon-closure(\{2,5,6,7\})=G∪\{6\}=\{1,2,3,5,6,7\} K=εclosure({2,5,6,7})=G{6}={1,2,3,5,6,7}

L = ε − c l o s u r e ( { 2 , 4 , 6 , 7 } ) = H ∪ { 7 } = { 1 , 2 , 3 , 4 , 6 , 7 } L=\varepsilon-closure(\{2,4,6,7\})=H∪\{7\}=\{1,2,3,4,6,7\} L=εclosure({2,4,6,7})=H{7}={1,2,3,4,6,7}

M = ε − c l o s u r e ( { 2 , 6 , 7 } ) = I ∪ { 7 } = { 1 , 2 , 3 , 6 , 7 } M=\varepsilon-closure(\{2,6,7\})=I∪\{7\}=\{1,2,3,6,7\} M=εclosure({2,6,7})=I{7}={1,2,3,6,7}

N = ε − c l o s u r e ( { 2 , 4 , 5 , 7 } ) = D ∪ { 7 } = { 1 , 2 , 3 , 4 , 5 , 7 } N=\varepsilon-closure(\{2,4,5,7\})=D∪\{7\}=\{1,2,3,4,5,7\} N=εclosure({2,4,5,7})=D{7}={1,2,3,4,5,7}

O = ε − c l o s u r e ( { 2 , 5 , 7 } ) = E ∪ { 7 } = { 1 , 2 , 3 , 5 , 7 } O=\varepsilon-closure(\{2,5,7\})=E∪\{7\}=\{1,2,3,5,7\} O=εclosure({2,5,7})=E{7}={1,2,3,5,7}

P = ε − c l o s u r e ( { 2 , 4 , 7 } ) = B ∪ { 7 } = { 1 , 2 , 3 , 4 , 7 } P=\varepsilon-closure(\{2,4,7\})=B∪\{7\}=\{1,2,3,4,7\} P=εclosure({2,4,7})=B{7}={1,2,3,4,7}

Q = ε − c l o s u r e ( { 2 , 7 } ) = C ∪ { 7 } = { 1 , 2 , 3 , 7 } Q=\varepsilon-closure(\{2,7\})=C∪\{7\}=\{1,2,3,7\} Q=εclosure({2,7})=C{7}={1,2,3,7}

状态输入符号
ab
ABC
BDE
CBC
DFG
EHI
FJK
GLM
HNO
IPQ
JJK
KLM
LNO
MPQ
NFG
OHI
PDE
QBC

对应的 DFA 如下:

对应的最简 DFA 如下:

初次划分: { A , B , C , D , E , F , G , H , I } \{A,B,C,D,E,F,G,H,I\} {A,B,C,D,E,F,G,H,I} { J , K , L , M , N , O , P , Q } \{J,K,L,M,N,O,P,Q\} {J,K,L,M,N,O,P,Q}

第二次划分: { A , B , C , D , E } \{A,B,C,D,E\} {A,B,C,D,E} { F , G , H , I } \{F,G,H,I\} {F,G,H,I} { J , K , L , M } \{J,K,L,M\} {J,K,L,M} { N , O , P , Q } \{N,O,P,Q\} {N,O,P,Q}

第三次划分: { A , B , C } \{A,B,C\} {A,B,C} { D , E } \{D,E\} {D,E} { F , G } \{F,G\} {F,G} { H , I } \{H,I\} {H,I} { J , K } \{J,K\} {J,K} { L , M } \{L,M\} {L,M} { N , O } \{N,O\} {N,O} { P , Q } \{P,Q\} {P,Q}

第四次划分: { A , C } \{A,C\} {A,C} { B } \{B\} {B} { D } \{D\} {D} { E } \{E\} {E} { F } \{F\} {F} { G } \{G\} {G} { H } \{H\} {H} { I } \{I\} {I} { J } \{J\} {J} { K } \{K\} {K} { L } \{L\} {L} { M } \{M\} {M} { N } \{N\} {N} { O } \{O\} {O} { P } \{P\} {P} { Q } \{Q\} {Q}

最终划分结果为: { A , C } \{A,C\} {A,C} { B } \{B\} {B} { D } \{D\} {D} { E } \{E\} {E} { F } \{F\} {F} { G } \{G\} {G} { H } \{H\} {H} { I } \{I\} {I} { J } \{J\} {J} { K } \{K\} {K} { L } \{L\} {L} { M } \{M\} {M} { N } \{N\} {N} { O } \{O\} {O} { P } \{P\} {P} { Q } \{Q\} {Q}

为了绘制 DFA 方便,令 { A , C } \{A,C\} {A,C} 为状态 0 0 0 { B } \{B\} {B} 为状态 1 1 1 { D } \{D\} {D} 为状态 2 2 2 { E } \{E\} {E} 为状态 3 3 3 { F } \{F\} {F} 为状态 4 4 4 { G } \{G\} {G} 为状态 5 5 5 { H } \{H\} {H} 为状态 6 6 6 { I } \{I\} {I} 为状态 7 7 7 { J } \{J\} {J} 为状态 8 8 8 { K } \{K\} {K} 为状态 9 9 9 { L } \{L\} {L} 为状态 10 10 10 { M } \{M\} {M} 为状态 11 11 11 { N } \{N\} {N} 为状态 12 12 12 { O } \{O\} {O} 为状态 13 13 13 { P } \{P\} {P} 为状态 14 14 14 { Q } \{Q\} {Q} 为状态 15 15 15


T 2.13

构造一个 DFA,它接受 Σ = { 0 , 1 } \Sigma=\{0,1\} Σ={0,1} 0 0 0 1 1 1 的个数都是偶数的字符串

对于一个01串,无论其 0 和 1 的个数有多少,总属于下面四种情况之一:

0:0和1的个数都是偶数;

1:0的个数是偶数,1的个数是奇数;

2:0的个数是奇数,1的个数是偶数;

3:0和1的个数都是奇数.

无论上述哪种情况,在01串后添加一个0或1后,总会处于另一种情况中,因此构造的 DFA 可以通过四个状态表示出来:


T 2.14

构造一个 DFA,它接受 Σ = { 0 , 1 } \Sigma=\{0,1\} Σ={0,1} 上能被 5 5 5 整除的二进制数

一个数对5取模,存在五种结果,结果为0、1、2、3、4。结果为0对应的是接受状态,其余是非接受状态。这样便可通过五个状态构造 DFA。

0:对5取模得0;

1:对5取模得1;

2:对5取模得2;

3:对5取模得3;

4:对5取模得4.


T 2.15

构造一个最简的 DFA,它接受所有大于 101 101 101 的二进制整数

根据题意,先简单地将状态分为六种,为 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5和大于 5 5 5的整数。

0:对应二进制整数为0;

1:对应二进制整数为1;

2:对应二进制整数为2;

3:对应二进制整数为3;

4:对应二进制整数为4;

5:对应二进制整数为5;

6:对应二进制整数大于5.

初步构造 DFA:

对上面的 DFA 进行化简:

初步划分为接受状态子集 { 6 } \{6\} {6} 和非接受状态子集 { 0 ,   1 ,   2 ,   3 ,   4 ,   5 } \{0,\space 1,\space2, \space 3,\space4,\space5\} {0, 1, 2, 3, 4, 5}

接受状态子集无法进一步划分;

对非接受状态子集进一步划分:

m o v e ( { 0 ,   1 ,   2 ,   3 ,   4 ,   5 } ,   0 ) = { 0 ,   2 ,   4 ,   6 } move(\{0,\space 1,\space2, \space 3,\space4,\space5\}, \space0)=\{0, \space 2, \space 4, \space 6\} move({0, 1, 2, 3, 4, 5}, 0)={0, 2, 4, 6},其中状态 0 0 0 转换到状态 0 0 0,状态 1 1 1 转换到状态 2 2 2,状态 2 2 2 转换到状态 4 4 4,状态 3 ,   4 ,   5 3,\space4,\space5 3, 4, 5 均转换到状态 6 6 6

m o v e ( { 0 ,   1 ,   2 ,   3 ,   4 ,   5 } ,   1 ) = { 1 ,   3 ,   5 ,   6 } move(\{0,\space 1,\space2, \space 3,\space4,\space5\}, \space1)=\{1, \space 3, \space 5, \space 6\} move({0, 1, 2, 3, 4, 5}, 1)={1, 3, 5, 6},其中状态 0 0 0 转换到状态 1 1 1,状态 1 1 1 转换到状态 3 3 3,状态 2 2 2 转换到状态 5 5 5,状态 3 ,   4 ,   5 3,\space4,\space5 3, 4, 5 均转换到状态 6 6 6

由于 0 ,   1 ,   2 ,   3 ,   4 ,   5 0,\space1,\space2,\space 3,\space4,\space5 0, 1, 2, 3, 4, 5 属于同一个子集,所以 0 ,   1 ,   2 0,\space1,\space2 0, 1, 2 仍属于同一子集,而由于 3 ,   4 ,   5 3,\space4,\space5 3, 4, 5 转换到了另一个不同的子集中,所以 3 ,   4 ,   5 3,\space4,\space5 3, 4, 5 被归为新的一个子集,子集 { 0 ,   1 ,   2 } \{0,\space1,\space2\} {0, 1, 2} 和子集 { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5} 代替了原先的子集 { 0 ,   1 ,   2 ,   3 ,   4 ,   5 } \{0,\space 1,\space2, \space 3,\space4,\space5\} {0, 1, 2, 3, 4, 5}

现在全部子集为 { 6 } \{6\} {6} { 0 ,   1 ,   2 } \{0,\space1,\space2\} {0, 1, 2} { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5},分别对子集 { 0 ,   1 ,   2 } \{0,\space1,\space2\} {0, 1, 2} 和子集 { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5} 进一步划分:

m o v e ( { 0 ,   1 ,   2 } ,   0 ) = { 0 ,   2 ,   4 } move(\{0,\space 1,\space2\}, \space0)=\{0, \space 2, \space 4\} move({0, 1, 2}, 0)={0, 2, 4},其中状态 0 0 0 转换到状态 0 0 0,状态 1 1 1 转换到状态 2 2 2,状态 2 2 2 转换到状态 4 4 4

m o v e ( { 0 ,   1 ,   2 } ,   1 ) = { 1 ,   3 ,   5 } move(\{0,\space 1,\space2\}, \space1)=\{1, \space 3, \space 5\} move({0, 1, 2}, 1)={1, 3, 5},其中状态 0 0 0 转换到状态 1 1 1,状态 1 1 1 转换到状态 3 3 3,状态 2 2 2 转换到状态 5 5 5

在输入字符为 0 0 0的情况下,状态 0 0 0 和 状态 1 1 1 均转换到同一集合 { 0 ,   1 ,   2 } \{0,\space 1,\space2\} {0, 1, 2} 中,但是状态 2 2 2 转换到了另一个集合 { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5} 中,所以状态 2 2 2 将被划分到与状态 0 0 0 和状态 1 1 1 不同的子集中;在输入字符为 1 1 1的情况下,状态 0 0 0 转换到子集 { 0 ,   1 ,   2 } \{0,\space 1,\space2\} {0, 1, 2} 中,而状态 1 1 1 转移到子集 { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5} 中,根据子集划分的要求“两个状态 s s s t t t 被划分到同一子集中,当且仅当对任意输入符号 α \alpha α,状态 s s s t t t 转换到本次划分前的同一子集中”,所以状态 0 0 0 和 状态 1 1 1 也要被划分到不同子集。故,经过本次划分,得到全部子集 { 0 } \{0\} {0} { 1 } \{1\} {1} { 2 } \{2\} {2} { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5} { 6 } \{6\} {6}

m o v e ( { 3 ,   4 ,   5 } ,   0 ) = m o v e ( { 3 ,   4 ,   5 } ,   1 ) = { 6 } move(\{3,\space4,\space5\}, \space0) = move(\{3,\space4,\space5\}, \space1) = \{6\} move({3, 4, 5}, 0)=move({3, 4, 5}, 1)={6},所以无需进一步划分。

最终得到全部子集 { 0 } \{0\} {0} { 1 } \{1\} {1} { 2 } \{2\} {2} { 3 ,   4 ,   5 } \{3,\space4,\space5\} {3, 4, 5} { 6 } \{6\} {6}。令 A = { 0 } A=\{0\} A={0} B = { 1 } B=\{1\} B={1} C = { 2 } C=\{2\} C={2} D = { 3 ,   4 ,   5 } D=\{3,\space4,\space5\} D={3, 4, 5} E = { 6 } E=\{6\} E={6},最简 DFA 如下:

有关【编译原理】第二章部分课后题答案的更多相关文章

  1. ruby - Sinatra set cache_control to static files in public folder编译错误 - 2

    我不知道为什么,但是当我设置这个设置时它无法编译设置:static_cache_control,[:public,:max_age=>300]这是我得到的syntaxerror,unexpectedtASSOC,expecting']'(SyntaxError)set:static_cache_control,[:public,:max_age=>300]^我只想将“过期”header设置为css、javaascript和图像文件。谢谢。 最佳答案 我猜您使用的是Ruby1.8.7。Sinatra文档中显示的语法似乎是在Ruby1.

  2. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  3. ruby - 如何跳过 CSV 文件的第一行并将第二行作为标题 - 2

    有没有办法跳过CSV文件的第一行,让第二行作为标题?我有一个CSV文件,第一行是日期,第二行是标题,所以我需要能够在遍历它时跳过第一行。我尝试使用slice但它会将CSV转换为数组,我真的很想将其读取为CSV,以便我可以利用header。 最佳答案 根据您的数据,您可以使用另一种方法和skip_lines-option此示例跳过所有以#开头的行require'csv'CSV.parse(DATA.read,:col_sep=>';',:headers=>true,:skip_lines=>/^#/#Markcomments!)do|

  4. .net - 是否有 Ruby .NET 编译器? - 2

    是否有适用于Ruby语言的.NETFramework编译器?我听说过DLR(动态语言运行时),这是否将使Ruby能够用于.NET开发? 最佳答案 IronRuby是Microsoft支持的项目,建立在动态语言运行时之上。 关于.net-是否有Ruby.NET编译器?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/199638/

  5. python - 使用 Python、Ruby 和 Perl 重新编译 MacPort 版本的 MacVim - 2

    关闭。这个问题是off-topic.它目前不接受答案。想改进这个问题吗?Updatethequestion所以它是on-topic用于堆栈溢出。关闭10年前。ImprovethisquestionLinux专家正在转向Mac(10.8)。因为我懒...我使用MacPorts安装MacVim。它似乎安装没有错误。我只需要mvim中的python、ruby和perl支持。$/opt/local/bin/mvim--version|egrep'patches|python|ruby|perl'Includedpatches:1-244,246-646+multi_lang-mzscheme+

  6. ruby - 如何使用部分字符串搜索数组并返回索引? - 2

    我想使用部分字符串搜索数组,然后获取找到该字符串的索引。例如:a=["Thisisline1","Wehaveline2here","andfinallyline3","potato"]a.index("potato")#thisreturns3a.index("Wehave")#thisreturnsnil使用a.grep将返回完整的字符串,使用a.any?将返回正确的true/false语句,但都不会返回匹配的索引找到了,或者至少我不知道该怎么做。我正在编写一段代码,该代码读取文件、查找特定header,然后返回该header的索引,以便它可以将其用作future搜索的偏移量。如果

  7. ruby - 为什么 `middleman serve` 有效,但是 `middleman build` 编译这个 Sass 失败? - 2

    当我刚刚运行middleman时服务,all.css编译得很好,只包含对+box-shadow(none)的调用:/*line1,/home/yang/asdf/source/stylesheets/content.css.sass*/div{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;}但是当我构建网站时,我得到了这个Sass/Compass错误:$middlemanbuildSlim::EmbeddedEngineisdeprecated,itiscalledSlim::EmbeddedinSlim2.0

  8. ruby-on-rails - 如何将数据传递给部分? - 2

    K伙计们,所以我创建了这个赞成/反对的投票脚本(基本上就像stackoverflow上的那个),我试图向其中添加一些Ajax,这样页面就不会在您每次投票时都重新加载。我有两个Controller,一个叫grinder,一个叫votes。(磨床基本都是帖子)所以这是所有研磨机的索引(看起来像这样)这是该页面的代码。Listinggrinders"grinders/grinders")%>这就是我在views/grinders/_grinders.erb中的内容true)do|u|%>grinder.id%>"up"%>'create')%>true)do|d|%>grinder.id%>

  9. ruby-on-rails - 将 restclient 与多部分帖子一起使用 - 2

    我将restclient用于多部分表单,以将数据发送到restfulweb服务(它是Panda视频编码服务)。不过,诀窍在于我传递给restclient(Technoweenie分支)的文件来自用户提交的我自己的表单。那么,让我们来看看这个。用户将文件发布到我的Rails应用程序。在我的Controller中,它从params[:file]接收文件。然后我想使用RestClient将params[:file]传递给Panda。我在Panda服务器上遇到的错误如下。我注意到堆栈跟踪中的文件参数也在一个字符串中(我假设Panda将其转换为字符串以获得更好的堆栈跟踪)。~Startedreq

  10. ruby - 有没有办法在 Ruby 中执行编译时类型检查? - 2

    我知道Ruby是动态和强类型的,但据我所知,由于每个参数缺少显式类型表示法(或契约),当前语法不允许在编译时检查参数类型。如果我想执行编译时类型检查,我有哪些(实际成熟的)选项?更新我的意思是类型检查类似于典型的静态类型语言。比如C。例如,C函数表示每个参数的类型,编译器检查传入的参数是否正确。voidfunc1(structAAAaaa){structBBBbbb;func1(bbb);//Wrongtype.Compiletimeerror.}作为另一个例子,Objective-C通过放置显式类型信息来做到这一点。-(id)method1:(AAA*)aaa{BBB*bbb=[[A

随机推荐