简体   繁体   English

从简单的陈述中得出 DFA(或 NFA)的步骤?

[英]Steps to draw a DFA (or NFA) from a simple statement?

I am given a simple statement: Construct a DFA over alphabet {0, 1} that accepts all the strings that end in 101 ?我得到一个简单的语句:在alphabet {0, 1}上构造一个 DFA,它接受all the strings that end in 101

My question is that what will be the steps to design it?我的问题是,设计它的步骤是什么? Or design an NFA, because then I know the clear steps yo convert an NFA to a DFA, so I will then convert the NFA to the DFA.或者设计一个 NFA,因为那时我知道将 NFA 转换为 DFA 的明确步骤,所以我会将 NFA 转换为 DFA。

Note:- It is just a minor course for me, so I have never studied anything like regular expressions, or any algorithms probably used to construct DFA's.注意:-这对我来说只是一门小课程,所以我从来没有研究过像正则表达式这样的东西,或者任何可能用于构造 DFA 的算法。

If you want more of an explanation on how I derived this, I'd be happy to explain, but for now I just drew the DFA and explained each state. 如果你想要更多地解释我如何得出这个,我会很乐意解释,但是现在我只画了DFA并解释了每个州。

Sorry about the screenshot...I didn't know how to convert it straight to an image. 抱歉截图...我不知道如何将其直接转换为图像。

DFA

  • On input 0 at state 0, it loops back to itself. 在状态0的输入0上,它循环回自身。 On 1, it prepares itself to end because it could possibly be '101'. 在1,它准备结束因为它可能是'101'。

  • q1 loops to itself on input 1 because it's still preparing to end on '101'. q1在输入1上循环自身,因为它仍然准备以'101'结束。 Input '0' on q1 means it is preparing for input '10', so it goes to q2. 在q1上输入'0'表示它正在准备输入'10',因此它进入q2。

  • Input '0' on q2 breaks the whole cycle and goes back to q0. q2上的输入'0'打破整个循环并返回q0。 Input '1' results in moving to q3, the accepting state. 输入'1'导致移动到接受状态q3。

  • Any input on q3 results in going back to whatever point in the cycle the input corresponds with. q3上的任何输入都会返回到输入对应的循环中的任何点。

  • That is, on '1' it goes back to q1, or the state where the first '1' was encountered in '101', preparing to end. 也就是说,在'1'时它返回到q1,或者在'101'中遇到第一个'1'的状态,准备结束。

  • On '0', it goes to q2 because in order to get to q3, there must have been an input of '1' from q2, so no matter what, the last two input symbols are '10' now. 在'0',它进入q2,因为为了到达q3,必须从q2输入'1',所以无论如何,最后两个输入符号现在是'10'。

TikZ DFA examples. TikZ DFA的例子。

Here,the string should end with 101.So we need to draw nfa for it and later convert it into DFA Here the total states are A,B,C,D.这里,字符串应该以101结尾。所以我们需要为其绘制nfa,然后将其转换为DFA。这里的总状态是A,B,C,D。 I will upload an image here.我会在这里上传一张图片。 In that I have drawn NFA and then I have drawn transition table for it.在那我画了 NFA,然后我画了它的转换表。 And then I have drawn transition table for conversion of NFA to DFA.然后我绘制了 NFA 到 DFA 转换的转换表。 I also drawn DFA for your sake.为了你,我还画了 DFA。

In NFA, when a specific input is given to the current state, the machine goes to multiple states.在 NFA 中,当向当前 state 提供特定输入时,机器会进入多个状态。 It can have zero, one or more than one move on a given input symbol.对于给定的输入符号,它可以有零个、一个或多个移动。 On the other hand, in DFA, when a specific input is given to the current state, the machine goes to only one state.另一方面,在 DFA 中,当给当前 state 一个特定输入时,机器只转到一个 state。 DFA has only one move on a given input State. DFA 在给定的输入 State 上只有一次移动。

THE STEPS FOR CONVERTING NFA TO DFA: Step 1: Initially Q' = ϕ将 NFA 转换为 DFA 的步骤: 步骤 1:最初 Q' = φ

Step 2: Add q0 of NFA to Q'.步骤 2:将 NFA 的 q0 添加到 Q'。 Then find the transitions from this start state.然后从这个开始 state 找到转换。

Step 3: In Q', find the possible set of states for each input symbol.第 3 步:在 Q' 中,找到每个输入符号的可能状态集。 If this set of states is not in Q', then add it to Q'.如果这组状态不在 Q' 中,则将其添加到 Q' 中。

Step 4: In DFA, the final state will be all the states which contain F(final states of NFA)第4步:在DFA中,最终的state将是所有包含F的状态(NFA的最终状态)

View the image here Click here在这里查看图片点击这里

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

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