简体   繁体   English

正则表达式到 DFA

[英]Regular Expression to DFA

Can someone tell me if the attached DFA is correct ?有人可以告诉我附加的 DFA 是否正确吗?

I am suppose to give DFA for the language that has alphabet Σ ={a, b}我想为具有字母 Σ ={a, b} 的语言提供 DFA

I need DFA for this ----> A={ε, b, ab}我需要 DFA ----> A={ε, b, ab} 在此处输入图像描述

No, for multiple reasons:不,有多种原因:

  1. Your automaton bab你的机器人bab
  2. Your automaton does not accept ab您的自动机不接受ab
  3. Your automaton is not a DFA, at least by some strict definitions您的自动机不是 DFA,至少按照一些严格的定义

Regarding the first point: starting at q1 , we see b , go to q2 , see a , go to q3 , see b , and go to q4 , which is accepting.关于第一点:从q1开始,我们看到b ,到q2 ,看到a ,到q3 ,看到b ,再到q4 ,这是接受。 We saw bab and accepted it.我们看到了bab并接受了它。

Regarding the second point: starting at q1 , we see a but have no defined transition.关于第二点:从q1开始,我们看到a但没有定义的转换。 The automaton "crashes" and fails to accept.自动机“崩溃”并且无法接受。 So no string starting with a is accepted, including ab .因此不接受以a开头的字符串,包括ab

Regarding the third point: DFAs are often required to show all states and transitions, including dead states and transitions that will never lead back to any accepting state.关于第三点:DFA 通常需要显示所有状态和转换,包括死状态和永远不会返回任何接受状态的转换。 You don't show all transitions and don't show all states in your automaton.您不会显示所有转换,也不会显示自动机中的所有状态。

You can use the Myhill-Nerode theorem to determine how many states a minimal DFA for your language has.您可以使用 Myhill-Nerode 定理来确定您的语言的最小 DFA 有多少个状态。 We note that the empty state can have appended either the empty string, b or ab to get a string in the language;我们注意到空状态可以附加空字符串bab以获得语言中的字符串; a can have b appended; a可以附加b and b can have the empty string appended.并且b可以附加空字符串。 Nothing can be appended to aa , bb , or ba to get a string in the language (so these are indistinguishable);不能将任何内容附加到aabbba以获取语言中的字符串(因此这些是无法区分的); but ab can have the empty string appended (and so is indistinguishable from b ).ab可以附加空字符串(因此与b无法区分)。

Equivalence classes so determined correspond to states in a minimal DFA.如此确定的等价类对应于最小 DFA 中的状态。 Our equivalence classes are:我们的等价类是:

  1. Strings like the empty string类似空字符串的字符串
  2. Strings like bb这样的字符串
  3. Strings like aa字符串
  4. Strings like aaaa这样的字符串

We note that b is in the language, so the second class will correspond to an accepting state.我们注意到b在语言中,因此第二类将对应于接受状态。 We notice nothing can be appended to aa to get a string in the language, so this class corresponds to a dead state in the DFA.我们注意到不能将任何内容附加到aa以获取语言中的字符串,因此此类对应于 DFA 中的死状态。 We write the transitions between these states by seeing which new equivalence class the appending of a new symbol puts us in:我们通过查看附加新符号将我们置于哪个新等价类来编写这些状态之间的转换:

  1. Appending a puts us in (3) since appending a to the empty string gives a which is in (3).附加a将我们置于 (3) 中,因为将a附加到空字符串给出a (3) 中的 a。 Appending b puts us in (2) since appending b to the empty string gives b which is in (2)附加b将我们置于 (2) 中,因为将b附加到空字符串会得到位于 (2) 中的b

  2. Appending a puts us in (4) since appending a to to b gives ba which is like aa in that it isn't a prefix of any string in the language.附加a将我们置于 (4) 中,因为将a附加到b给出了ba ,这与aa类似,因为它不是语言中任何字符串的前缀。 Appending b , we arrive in (4) by a similar argument.附加b ,我们通过类似的论点到达(4)。

  3. Appending a we get aa and are in (4).附加a我们得到aa并且在 (4) 中。 Appending b we get ab which is like b so we are in (2).附加b我们得到ab就像b所以我们在(2)中。

  4. All transitions from a dead state return to a dead state;所有从死状态的转换都返回到死状态; both a and b lead back to (4). ab都返回到 (4)。

You end up with something like:你最终会得到类似的东西:

q1 --a--> q3
 |        /|
 b  --b--< a
 | /       |
 vv        v
q2 -a,b-> q4 \
           ^ a,b
           \_/

Or in tabular form:或以表格形式:

q    s    q'
==   =    ==
q1   a    q3
q1   b    q2
q2   a    q4
q2   b    q4
q3   a    q4
q3   b    q2
q4   a    q4
q4   b    q4

i think this DFA is correct for that language.我认为这个 DFA 对那种语言是正确的。

在此处输入图像描述

Your attached DFA is wrong.. your DFA is acceptable only for €,b,bab but it cannot accept ab.您附加的 DFA 错误.. 您的 DFA 仅适用于 €,b,bab 但不能接受 ab。 To make your dfa to accept ab also add a new state to q0 which accepts a and whenever newstate gets input as b send it to a final state.为了让您的 dfa 接受 ab,还向 q0 添加一个新状态,它接受 a 并且每当 newstate 作为 b 获得输入时,将其发送到最终状态。 As it is a dfa the inputs which are not required for u send it to a new state (DEAD STATE) The dfa for your question is here: click here to view the dfa由于它是一个 dfa,因此您不需要将其发送到新状态(死亡状态)您的问题的 dfa 在这里:单击此处查看 dfa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM