【问题标题】:DFA over language {0,1}基于语言的 DFA {0,1}
【发布时间】:2018-10-23 18:44:57
【问题描述】:

我正在努力满足以下要求(作业)

构造正则表达式和确定性自动机 接受 {0,1} 以上的以下语言。

  • (a) 不包含 00 的字符串。

  • (b) 至少包含三个符号的字符串。

  • (c) 每个 0 后跟 1 的字符串。

  • (d) 以 11 开头和结尾的字符串。

  • (e) 奇数个 0:s 和奇数个 1:s 的字符串。

到目前为止,我已经完成了以下操作,但感觉不对,有人对我可以做得更好有什么建议吗?我对此很陌生,甚至不知道我所做的是否符合要求。

【问题讨论】:

  • 问题的措辞方式听起来像是您应该分别为每种语言提出自动机。特别是,ca 的严格子集。

标签: automata finite-automata dfa


【解决方案1】:

我发现制作正则表达式比 DFA 更难,所以我建议先制作 DFA,然后再获取正则表达式。

(a) 我们可以做一个检测子串 00 并转换到死状态的 DFA。

 q    s   q'
--   --   --
q0    0   q1        q0 is the initial state
q0    1   q0        q0 and q1 are accepting
q1    0   q2        q2 is a dead state
q1    1   q0
q2    0   q2
q2    1   q2

为了获得正则表达式,我们迭代地为每个状态找到一个正则表达式,用于指向该状态的字符串。然后,我们将所有正则表达式的并集用于接受状态。

iteration 1
q0: e + (q0)1 + (q1)1
q1: (q0)0
q2: (q1)0 + (q2)0 + (q2)1

iteration 2
q0: e + (q0)1 + (q0)01
q1: (q0)0
q2: (q0)00 + (q2)0 + (q2)1

iteration 3
q0: e+(1+01)*
q1: (e+(1+01)*)0
q2: (e+(1+01)*)00(0+1)*

因为q0和q1都是接受状态,所以正则表达式是

  e+(1+01)*+(e+(1+01)*)0
= (1+01)*+(1+01)*0          // e + r* = r*
= (1+01)*e+(1+01)*0         // r = re
= (1+01)(e+0)               // distributive law of concatenation

(b) 这里的 DFA 是:

 q     s    s'
--    --    --
q0     0    q1
q0     1    q1           q0 is the initial state
q1     0    q2           q3 is the accepting state
q1     1    q2
q2     0    q3
q2     1    q3
q3     0    q3
q3     1    q3

同样的练习:

 iteration 1
 q0: e
 q1: (q0)0 + (q0)1
 q2: (q1)0 + (q1)1
 q3: (q2)0 + (q2)1

 iterations 2-3 (combined)
 q0: e
 q1: e0 + e1
 q2: (0+1)0 + (0+1)1
 q3: (q2)0 + (q2)1 + (q3)0 + (q3)1

 iteration 4
 q0: e
 q1: e0 + e1
 q2: (0+1)0 + (0+1)1
 q3: ((0+1)0 + (0+1)1)(0+1)(0+1)*

由于 q4 是唯一的接受状态,所以答案只是

  ((0+1)0 + (0+1)1)(0+1)(0+1)*
= (00+10+01+11)(0+1)(0+1)*

(c) 这与 (a) 非常相似,只是我们丢弃了以 0 结尾的字符串。也就是说,q1 不接受。因此,DFA 与 (a) 相同,q1 不接受,因此正则表达式为 e+(1+01)* = (1+01)*

(d) DFA:

 q     s    q'
--    --    --
q0     0    q1
q0     1    q2        q0 is the initial state
q1     0    q1        q3 is the accepting state
q1     1    q1        q1 is the dead state
q2     0    q1        q0,q1,q2 ensure the string starts with 11
q2     1    q3        q3,q4,q5 ensure the string stops with 11
q3     0    q4
q3     1    q3
q4     0    q4
q4     1    q5
q5     0    q4
q5     1    q3

我们当然可以进行与上述相同的练习,但这里实际上很容易创建正则表达式:11+111+11(0+1)*11

(e) DFA:

 q     s    q'
--    --    --
q0     0    q1
q0     1    q2    q0 is the initial state
q1     0    q0    q3 is the accepting state
q1     1    q3    q0: #0 and #1 are even
q2     0    q3    q1: #0 is odd, #1 is even
q2     1    q0    q2: #0 is even, #1 is odd
q3     0    q2    q3: #0 is odd, #1 is odd
q3     1    q1

这里的正则表达式很难,留作练习。您可以像前面的示例一样进行迭代;只要记住规则是:

qx: r + (qx)s    --->    qx: (r)(s*)

然后一次只删除一个符号,直到你有一个没有状态占位符的 (q3) 正则表达式。祝你好运。

【讨论】:

    猜你喜欢
    • 2017-06-25
    • 2012-02-16
    • 2017-03-13
    • 2012-07-18
    • 2014-05-18
    • 2013-09-07
    • 1970-01-01
    • 2018-09-03
    • 2017-04-14
    相关资源
    最近更新 更多