Build a DFA to accept Binary strings that starts or ends with "01" | C # program to check if a string either 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
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void checkstateA ( string n ) { if ( n [ 0 ] == '0' ) stateB ( n . Substring ( 1 ) ) ; else stateD ( n . Substring ( 1 ) ) ; } static void stateB ( string n ) { if ( n . Length == 0 ) { Console . Write ( " string ▁ not ▁ accepted " ) ; } else { if ( n [ 0 ] == '1' ) stateC ( n . Substring ( 1 ) ) ; else stateD ( n . Substring ( 1 ) ) ; } } static void stateC ( string n ) { Console . Write ( " string ▁ accepted " ) ; } static void stateD ( string n ) { if ( n . Length == 0 ) Console . Write ( " string ▁ not ▁ accepted " ) ; else { if ( n [ 0 ] == '1' ) stateD ( n . Substring ( 1 ) ) ; else stateE ( n . Substring ( 1 ) ) ; } } static void stateE ( string n ) { if ( n . Length == 0 ) Console . Write ( " string ▁ not ▁ accepted " ) ; else { if ( n [ 0 ] == '0' ) stateE ( n . Substring ( 1 ) ) ; else stateF ( n . Substring ( 1 ) ) ; } } static void stateF ( string n ) { if ( n . Length == 0 ) Console . Write ( " string ▁ accepted " ) ; else { if ( n [ 0 ] == '1' ) stateD ( n . Substring ( 1 ) ) ; else stateE ( n . Substring ( 1 ) ) ; } } public static void Main ( string [ ] args ) { string n = "0100101" ; checkstateA ( n ) ; } }