In this I am getting two different RE for state q4 and q5. So my question is If we get more than one different RE for one FSM with more than one final state, is it correct??
If we get more than one different regular expression for the same finite state machine with more than one final state, is it correct?
Rather than push the buttons mechanically, you have to understand what you're doing. Your task is to find a regular expression equivalent to a given FSM. This means that the language accepted by your regular expression has to be the same as the language accepted by the given FSM.
For every state $\sigma$ in the FSM, you can computer a regular expression $r_\sigma$ for the language $L_\sigma$ of all words upon reading of which the FSM ends up at the state $\sigma$ (this definition is valid in the deterministic case; for non-deterministic automata, it has to be slightly modified). The language $L$ accepted by the FSM consists of all words upon reading of which the FSM ends up at an accepting state. Given this data, you should be able to come up with a regular expression for $L$ using the regular expressions $r_\sigma$ for all accepting states — you just have to combine them in the correct way.
4 steps to convert FSM to RegEx:
- Make sure no inward arrows in Initial state ($q0$), if there is then add a new state ($q00$) which goes to initial state ($q0$) on encountering $\epsilon$. Now treat this new state ($q00$) as your new initial state.
- If there is an outward arrow from a final state (like $q5$ to $q6$) then add a new state ($fq5$). And make the final state ($q5$) point to this new state ($fq5$) on encountering $\epsilon$. Treat this new state ($fq5$) as the new final state.
- If there are multiple final states (like $q5$ and $q4$) then add a new state ($q54$). And make all the final states to point to this new state ($q54$) on encountering $\epsilon$. Treat this new state ($q54$) as the only final state.
- Now start eliminating states one by one and substitute a correct RegEx in their place*. Goal is to reach with only 1 initial state and 1 final state, connected by the RegEx.
Now if you ask, can there be more than 1 RegEx for a FSM, then the answer is Yes. It depends on what order you eliminated the states.
Consider a NFA:
- $q00$ to $q0$ on $\epsilon$
- $q0$ to $q1$ on $b$
- $q1$ to $q0$ on $a$
- $q1$ to $q1$ on $c$ and
- $q1$ to $q2$ (final state) on $d$
Now if you remove $q0$ first you'll get different RegEx $[b(ab)^*(c+(ab)^*)^*d]$ and if you eliminate $q1$ first you'll get a different RegEx $[(bc^*a)^*bc^*d]$.