Build a DFA to accept Binary strings that starts or ends with "01" | Function for transition state A ; State transition to B if the character is 0 ; State transition to D if the character is 1 ; Function for transition state B ; Check if the string has ended ; State transition to C if the character is 1 ; State transition to D if the character is 0 ; Function for transition state C ; Function for transition state D ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Function for transition state E ; State transition to E if the character is 0 ; State transition to F if the character is 1 ; Function for transition state F ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Driver Code
function checkstateA ( n ) { if ( n [ 0 ] == ' ' ) stateB ( n . substr ( 1 ) ) ; else stateD ( n . substr ( 1 ) ) ; } function stateB ( n ) { if ( n . length == 0 ) { document . write ( " " ) ; } else { if ( n [ 0 ] == ' ' ) stateC ( n . substr ( 1 ) ) ; else stateD ( n . substr ( 1 ) ) ; } } function stateC ( n ) { document . write ( " " ) ; } function stateD ( n ) { if ( n . length == 0 ) Console . Write ( " " ) ; else { if ( n [ 0 ] == ' ' ) stateD ( n . substr ( 1 ) ) ; else stateE ( n . substr ( 1 ) ) ; } } function stateE ( n ) { if ( n . length == 0 ) document . write ( " " ) ; else { if ( n [ 0 ] == ' ' ) stateE ( n . substr ( 1 ) ) ; else stateF ( n . substr ( 1 ) ) ; } } function stateF ( n ) { if ( n . length == 0 ) document . write ( " " ) ; else { if ( n [ 0 ] == ' ' ) stateD ( n . substr ( 1 ) ) ; else stateE ( n . substr ( 1 ) ) ; } } let n = " " ; checkstateA ( n ) ;