简体   繁体   中英

How to determine whether finite-state automata is deterministic?

I have a automata coursework that is really bothering me by its difficulty. I have spent almost 5 hours today doing without actually knowing whether it's right or not. The task is to write a Java code that will determine whether the given automaton is deterministic. What I have is a class that represents automata and it has the following five variables: int alphabet_size; int n_states; int delta[][]; int initial_state; int accepting_states[];

Delta represents following eg in real automata q1, 1, q2 in program would look like {1, 1, 2}. I know that in a non-deterministic automaton there could be more than one possible state to go to, but I don't know how to compute that.

Thanks in advance.

To solve it I would go this way:

  1. Create a Map (String, String or integer), I will use the key to check what actual state>symbol is and the value to track which state the transaction goes to (null or -1 if the actual state do not have a transaction with that symbol);
  2. Populate the map keys and values, ex: map.put("1>1", null) means from state 1 with symbol 1 goes to null. For now, put null or -1 for every possibility;
  3. Iterate over your transaction possibilities, build the key string, retrieve fom the map the corresponding value. If it is null include the number of the state that goes to, else means there is another transaction coming from the same state with the same symbol that goes to a different state, so it is not deterministic;

If you can iterate over the whole array it is deterministic!

With the member variables that you have now, you can only represent a deterministic FSA. Why? Because a NDFSA is one where there is a state q 1 and input a such that both

  • (q 1 , a) -> q 2
  • (q 1 , a) -> q 3

are in delta. You implement this (q from , input) -> q to mapping as int[][] , which means that for each instate-input pair, you can only store one outstate.

One very quick fix would be to allow a list of outstates for all instate-input pair, like so:

ArrayList[][] delta;

However, this is ugly. We can arrive at a nicer solution* if you realize that delta is actually the mapping q from -> input -> q to , and it can be bracketed in two ways:

  • (q from -> input) -> q to : this is what you had, with a little different notation
  • q from -> (input -> q to )

Another thing to realize is that int[] is conceptually the same as Map<Integer, Integer> . With that, the second mapping can implemented in Java as:

Map<Integer, Map<Integer, List<Integer>>> delta;

Whichever implementation you choose, the test that decides if the FSA is deterministic or not is very simple, and comes from the definition: A is a DFSA iff the lengths of all lists in delta are <= 1; otherwise, it is a NDFSA .

*Note that real FSA libraries usually use a different approach. For instance, foma uses an array of transition object with fields instate, outstate and the input character. However, for starters, the ones above are probably easier to handle.

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