DFA that begins with ' a ' but does not contain substring ' aab ' | C # code for the above DFA ; 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 transition state B ; 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 transition state C ; 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 transition state D ; 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 Q transition ; In dead state it shows string not accepted ; Driver code ; Take string input ; Call stateA to check the input
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void stateA ( string n ) { if ( n [ 0 ] == ' a ' ) { stateB ( n . Substring ( 1 ) ) ; } else { stateQ ( n ) ; } } static void stateB ( string n ) { if ( n . Length == 0 ) { Console . Write ( " Accepted " ) ; } else { if ( n [ 0 ] == ' a ' ) stateC ( n . Substring ( 1 ) ) ; else stateD ( n . Substring ( 1 ) ) ; } } static void stateC ( string n ) { if ( n . Length == 0 ) Console . Write ( " Accepted " ) ; else { if ( n [ 0 ] == ' a ' ) stateC ( n . Substring ( 1 ) ) ; else stateQ ( n ) ; } } static void stateD ( string n ) { if ( n . Length == 0 ) Console . Write ( " Accepted " ) ; else { if ( n [ 0 ] == ' a ' ) { stateB ( n . Substring ( 1 ) ) ; } else { stateD ( n . Substring ( 1 ) ) ; } } } static void stateQ ( string n ) { Console . Write ( " Not ▁ Accepted " ) ; } public static void Main ( string [ ] args ) { string n = " aaaba " ; stateA ( n ) ; } }