0

I'm working on creating a deterministic finite state automata for the following problem:

You can create strings made of x's and y's. How do you create a diagram that only accepts the language when the number of (x's mod 4) is greater than the number of (y's mod 4)?

What I am currently able to understand is that I need to create a diagram similar to below:

>(0,0) -b-> (0,1) -b-> (0,2) -b-> (0,3) -b-> (0,4)
   a          a          a          a          a
 (1,0) -b-> (1,1) -b-> (1,2) -b-> (1,3) -b-> (1,4)
   a          a          a          a          a
 (2,0) -b-> (2,1) -b-> (2,2) -b-> (2,3) -b-> (2,4)
   a          a          a          a          a
 (3,0) -b-> (3,1) -b-> (3,2) -b-> (3,3) -b-> (3,4)
   a          a          a          a          a
 (4,0) -b-> (4,1) -b-> (4,2) -b-> (4,3) -b-> (4,4)

But what I don't understand is how to compare the number of times x and y occur relative to one another.

sc1892353
  • 85
  • 1
  • 10

2 Answers2

0

I try to answer your question by defining the DFA behaviour through a transition table instead of using a transition diagram - a table is easier to type here and it's functionally equivalent to the corresponding transition diagram.

In the table below

  • the first column lists all the states; every state is represented by an ordered pair whose elements represents, respectively, the number of x's and the number of y's read so far
  • the second and third columns contain, respectively, the state reached when reading an x or an y while the DFA is in the state shown in the first column of the table
  • the states highlighted in yellow are the accept states: if the DFA is in one of those states after examining the last symbol in the string then the string is accepted, that is it belongs to the language.

enter image description here

Looking at this table, you should easily be able to adapt your diagram so as to make things work properly. For example, the first line in the table corresponds to the following portion of your diagram

>(0,0) -y-> (0,1)
   x
 (1,0)
mw215
  • 323
  • 1
  • 8
0

You have pretty much arrived at the answer in the question itself.

First you see which states you need. You need to calculate n(x) mod 4. This requires 4 states. Then you need to calculate n(y) mod 4. This also requires 4 states. Now, since you need to calculate both together, you have to intersect them. This will result in 4 x 4 = 16 states. Let us name those states as (a, b); a = n(x) mod 4, b = n(y) mod 4.

Then, you decide what is the initial state and what are the final states. In this case, initial state is (0,0) and final states are { (a,b) : a > b }.

So, this is what you get finally: Resultant DFA DFA drawer link

Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35