Frage

I am writing the code to convert NFA to DFA, if we have a power state {1,2,4}, I have to convert it into the some unique number, say x. Also I have to do the reverse mapping such that is I get x, I have to return the power state as {1,2,4}

I came up with having HashMap of string representation of set 1,2,4 and having value as unique number. But as code grows, I might have (1,2,4) and (2,1,4) both are same set but not the same string. Then I thought of sorting the state string and using it as map key. But seems like my logic is complex.

War es hilfreich?

Lösung

You can take the state number th power of 2 and go on adding this to yield unique number. For reverse mapping you can device the logic as this number will be the sum of the numbers which are perfect power of 2. I leave it for you, as it's your homework.

e.g. (1,2,3) = 2+4+8 = 14

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top