Regular expression for the machine M2 and M3



Here we get final state by one or several time of ‘a b’  OR (+) by one or several time of ‘b a’  OR (+) combination of  ab and ba.

By taking longest path regular expression RE = (ab + ba)*


M3 machine,



Here regular expression is simple because we get initial state to final state only by input a. And another state is trap state

Regular Expression REa