3

I have a program that simply takes all the states as a set of states as a input. And then the next input that is taken is the initial state among the set of states and then set of final states.

The next is a set of transition that I take among the states.

For example: q0,1,q1

This means on input one there is a transition from q0 to q1.

For each state the transitions are entered.

But here what I am facing is the refrences can be jumpled up in a random fashion that is the transitions can be n number of transition for non duplicate characters, and hence cause of this I want to maintain a hashmap object for each state dynamically.

How can I achieve this?

2 Answers2

1

Since this is a DFA, it may be easier and more efficient to maintain a single hashmap from (state, input) pairs to resulting states. The DFA properties guarantee that the transition relation can be viewed as a function in this manner.

So, maintain a HashMap<StateInput, State> trans and do trans.put(StateInput(q0, 1), q1) for the example you gave, where

class StateInput {
    public State state;
    public int input;
}
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
0

Something like this, maybe?

class State {
  private Map<State, Character> transitions;

  // ...

  public void addTransition(State nextState, Character input) {
     transistions.put(nextState, input);
  }

  // ...
}
Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • Now the object refrence of Class state in StateInput class is getting the value q0 in the above example. i am not so clear what is happening in the constructor of the StateInput class. and also about the constructor of State class. addTransition is given the key,value in terms of State and the char as key and value respectively. but wouldnt it be better if the value is made the key? – Shridatt Zambodker Sep 20 '11 at 11:05