Program to build a DFA that checks if a string ends with "01" or "10" | End position is checked using the string length value . q0 is the starting state . q1 and q2 are intermediate states . q3 and q4 are final states . ; state transitions 0 takes to q1 , 1 takes to q3 ; state transitions 0 takes to q4 , 1 takes to q2 ; state transitions 0 takes to q4 , 1 takes to q2 ; state transitions 0 takes to q1 , 1 takes to q3 ; state transitions 0 takes to q1 , 1 takes to q2 ; Driver Code ; all state transitions are printed . if string is accpetable , YES is printed . else NO is printed
function q1 ( s , i ) { document . write ( " " ) ; if ( i === s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] === " " ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } function q2 ( s , i ) { document . write ( " " ) ; if ( i === s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] === " " ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } function q3 ( s , i ) { document . write ( " " ) ; if ( i === s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] === " " ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } function q4 ( s , i ) { document . write ( " " ) ; if ( i === s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] === " " ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } function q0 ( s , i ) { document . write ( " " ) ; if ( i === s . length ) { document . write ( " " ) ; return ; } if ( s [ i ] === " " ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } var s = " " ; document . write ( " " ) ; q0 ( s , 0 ) ;