简体   繁体   中英

Construct a NFA for the following language defined over Σ = {0, 1}. D = {0^n 10^m10^q |n, m, q ∈ N, q ≡ nm (mod 5)}

Need help solving the below question:

Construct a NFA for the following language defined over Σ = {0, 1}.

D = {0^n 10^m10^q |n, m, q ∈ N, q ≡ nm (mod 5)}

I am confused on how to create the NFA factoring in the q part of the language.

We can use five states to remember the value of n mod 5:

        _______________0______________
       /                              \
       |                              |
       V                              |
----->q0--0-->q1--0-->q2--0-->q3--0-->q4

Now we need to read the 1:

        _______________0______________
       /                              \
       |                              |
       V                              |
----->q0--0-->q1--0-->q2--0-->q3--0-->q4
       |       |       |       |       |
       1       1       1       1       1
       |       |       |       |       |
       V       V       V       V       V
      q0'     q1'     q2'     q3'     q4'

Now we can look at each case individually. For q0', we know we saw a number of 0s in the first section that is congruent to 0 mod 5. Thus, nm = 0 (mod 5) is already known. We can accept any number of 0s, then a 1, and then accept if we have no further input: we can make q0' do this:

     _0_
    /   \
    |   |
    \   /
----->q0'--1-->qA

For q1', we will have q = nm (mod 5) = m (mod 5) since n = 1 (mod 5) in this case. We can accomplish this by remembering the current value so far of m (mod 5) and then looking for that many 0s in q. That is, q1' can be replaced with:

        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q1'--0-->q1''--0-->q1'''--0-->q1''''--0-->q1'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA<--0--qA'<--0--qA''<--0--qA'''<--0--qA''''

qA is the same accepting state we introduced previously. For q2', we can keep track of the current value of nm (mod 5) which is 2m (mod 5):

        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q2'--0-->q2''--0-->q2'''--0-->q2''''--0-->q2'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA      qA''     qA''''     qA'         qA'''

The states qA', qA'', qA''' and qA'''' are the same as introduced before, but notice the order is different now: this reflects the fact that 2 x 0 = 0 (as before), 2 x 1 = 2 (not 1), 2 x 2 = 4 (not 2), etc.

We can do the same thing for q3' and q4':

        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q3'--0-->q3''--0-->q3'''--0-->q3''''--0-->q3'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA      qA'''    qA'        qA''''      qA''


        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q4'--0-->q4''--0-->q4'''--0-->q4''''--0-->q4'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA      qA''''   qA'''      qA''        qA'

Putting all of these various DFAs together into one huge DFA is guaranteed to give you a DFA that will work. Whether there is a substantially similar NFA, I cannot say for certain. This DFA has states:

  1. q0, q0': 2 states
  2. q1, q1', …., q1''''': 6 states
  3. q2, q2', …., q2''''': 6 states
  4. q3, q3', …., q3''''': 6 states
  5. q4, q4', …., q4''''': 6 states
  6. qA, qA', …., qA'''': 5 states

This is a total of 32 states. If you wanted to attempt minimization you might be able to knock a few of those off.

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