DFA that begins with ' a ' but does not contain substring ' aab ' | Function for state A transition ; If at index 0 ' a ' if found then call stateB function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateQ function with passing n to it ; Function for state B transition ; Length of string become 0 then print Accepted ; If at index 0 ' a ' if found then call stateC function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateD function with passing n [ 1 : ] to it ; Function for state C transition ; Length of string become 0 then print Accepted ; If at index 0 ' a ' if found then call stateC function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateQ function with passing n to it ; Function for state D transition ; Length of string become 0 then print Accepted ; If at index 0 ' a ' if found then call stateB function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateD function with passing n [ 1 : ] to it ; Function for state Q transition ; In dead state it shows string not accepted ; Take string input ; Call stateA to check the input
def stateA ( n ) : NEW_LINE INDENT if ( n [ 0 ] == ' a ' ) : NEW_LINE INDENT stateB ( n [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT stateQ ( n ) NEW_LINE DEDENT DEDENT def stateB ( n ) : NEW_LINE INDENT if ( len ( n ) == 0 ) : NEW_LINE INDENT print ( " Accepted " ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( n [ 0 ] == ' a ' ) : NEW_LINE INDENT stateC ( n [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT stateD ( n [ 1 : ] ) NEW_LINE DEDENT DEDENT DEDENT def stateC ( n ) : NEW_LINE INDENT if ( len ( n ) == 0 ) : NEW_LINE INDENT print ( " Accepted " ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( n [ 0 ] == ' a ' ) : NEW_LINE INDENT stateC ( n [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT stateQ ( n ) NEW_LINE DEDENT DEDENT DEDENT def stateD ( n ) : NEW_LINE INDENT if ( len ( n ) == 0 ) : NEW_LINE INDENT print ( " Accepted " ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( n [ 0 ] == ' a ' ) : NEW_LINE INDENT stateB ( n [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT stateD ( n [ 1 : ] ) NEW_LINE DEDENT DEDENT DEDENT def stateQ ( n ) : NEW_LINE INDENT print ( " Not ▁ Accepted " ) NEW_LINE DEDENT n = " aaaba " NEW_LINE stateA ( n ) NEW_LINE