简体   繁体   中英

DFA that will accepts the string having odd number of 1's and odd number of 0's

我想要 DFA 生成,它将接受具有奇数个 1 和奇数个 0 的字符串。

First, let's build a DFA that accepts an odd number of 0. We need at least one state or else we can't accept anything. That state can't be accepting since the empty string leads there and the empty string doesn't have an odd number of 0. So, we need at least two states - an initial state that is not accepting, and an accepting state. Do we need more?

To answer that question let's start filling in the transitions and see where we get. There must be a transition originating in the accepting state. Where does it go? If it goes to itself, then we don't accept the string 0, which has an odd number (one) of 0. So we need to go to some accepting state on 0 in the initial state. We just so happen to have an accepting state already; let's go there.

Next, we must have a transition from the accepting state. If we return to the accepting state, we would accept the string 00, so we can't do that. We must transition to some non-accepting state. We have a non-accepting state already - our initial state - so that choice might work. Alternatively, if not, we must introduce a new state. Let us first consider whether returning to the initial state works, since in that case we are done.

We have already reasoned that the strings 0 and 00 are handled correctly. From then on, 000 will be handled correctly since we return to the accepting state from the initial state on the subsequent 0; indeed, we return to the initial state on 0^2k and to the accepting state on 0^(2k+1), for k >= 0. Therefore, this DFA is correct for the language of strings of odd numbers of 0. The diagram looks like:

        /---0----\
        |        |
        V        |
----->(q0)--0-->(q1)

By changing the labels we can get an automaton for the language of strings of odd numbers of 1:

        /---1----\
        |        |
        V        |
----->(q2)--1-->(q3)

To get an automaton accepting strings containing odd numbers of both 0 and 1, imagine running both automata simultaneously: whenever we see a 0, we pass it to the first one, and whenever we see a 1, we pass it to the second one. Then, we accept if both automata ended up in accepting states. We can represent the combined state of the two automata by considering all four pairs of states from the first and second automata as states of a new, combined automaton, the transitions graph of which looks like this:

          /----0----\
          |         |
          V         |
----->(q0,q2)--0-->(q1,q2)
       ^  |         ^  |
       |  1         |  1
       1  |         1  |
       |  V         |  V
      (q0,q3)--0-->(q1,q3)
          ^         |
          |         |
          \----0----/

These are the intuitions behind the Myhill-Nerode theorem on regularity of languages and the Cartesian product machine construction for the intersection of regular languages.

MEANS you want a DFA for odd-odd language

here is the DFA that you required 在此处输入图像描述

look here when you apply 0 it didn't accept ..then you apply 1 it will reach to final state . As DFA accepting odd number of '0's and odd number of '1's .it will accept strings unless their length is odd .you can run strings on DFA to check it. Hope it would help you

Let q0,q1,q2,q3,q4,q5 are the states of DFA . Also given that to construct a DFA that accepts odd no of 0's and odd no of 1's so that q0 on 0 gives q0 and q0 on q 1 q1 on 0 gives q2 and q1 on 1 q 1 q2 on 0 gives q0 and q2 on 1 q3. q3 on 0 gives q2 and q3 on 1 q4. And q4 on 0 and 1 remains in the same state by checking substring 1011 q0 on 1 goes to q1 q1 on 0 goes to q2 q2 on 1 goes to q3 q3 on 1 goes to q4 the final state . It is the required DFA . https://i.stack.imgur.com/jy109.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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