DFA String Examples
We will now discuss about string patterns such as, starting with some symbol, ending with some symbol, etc.
Design a DFA in which start and end symbol must be differentGiven: Input alphabet, Σ={a, b}
Language L = {ab, ab, abab, aabb, aaabbb,...}
Clearly the language is infinite because there is infinite number of strings.
The idea behind this approach is very simple, follow the steps below and you will understand.
- We know that if the first input is 'a' then the last input cannot be 'a', so we start two flows form start state, one for staring with 'a' and another for starting with 'b'
- This is also clear that there will be two final states
- In the first flow starting with 'a' we have already discussed the process in the previous examples. We will accept the input 'a' on state B for multiple times and then on b we will go to final state.
- On final state we will direct the input 'a' to state B so that the last symbol should not be 'a'
- The same mechanism will be for another flow staring from start state A on input 'a'.
Testing 1
- Lets take one input string abab(this will describe for strings which starts with a and ends with different symbol b)
- Scan string from left to right
- First input is a, so from state A we will go to state B
- Second input is b, so from state B we will go to state C
- Third input is a, so from state C we will go to state B
- Fourth input is b, so from state B we will go to state C (final state)
Testing 2
- Lets take another input string bbabaa(this will describe for strings which starts with b and ends with different symbol a)
- Scan string from left to right
- First input is b, so from state A we will go to state D
- Second input is b, so from state D we will go to state D itself
- Third input is a, so from state D we will go to state E
- Fourth input is b, so from state E we will go to state D
- Fifth input is a, so from state D we will go to state E (final state)
- Sixth input is a, so from state E we will go to state E itself(final state)
You may also try some examples of strings to run over this DFA, and you will understand more