2.1.1. $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $
State 0 = currently counted an even number of 1s [initial state]
State 1 = currently counted an odd number of 1s [final state]
When we read a 0, we stay on the same state, as we are only counting ones.
When we find a one:
If we were on state 0, it means we counted until the previous step an even number of ones. Now we have an odd number of ones, so we need to move to state 1.
If we were on state 1, it means we counted until the previous step an odd number of ones. Now we have an even number of ones, so we need to move to state 0.
2.1.2. The language of binary words which contain exactly two ones
State 0: no ones have been found yet [initial state]
State 1: 1 one have been found so far
State 2: 2 ones have been found so far [final state]
State 3: more than 2 ones have been found so far [sink state]
2.1.3. The language of binary words which encode odd numbers (the last digit is least significative)
2.1.4. (hard) The language of words which encode numbers divisible by 3
State 0: 3k [initial state and final state]
State 1: 3k + 1
State 2: 3k + 2
When we read a 0, the number we had so far is multiplied by 2:
3k –(*2)–> 3k
3k + 1 –(*2)–> 3k + 2
3k + 2 –(*2)–> 3k + 1
When we read a 1, the number we had so far is multiplied by 2 and we also add 1:
3k –(*2)–> 3k –(+1)–> 3k + 1
3k + 1 –(*2)–> 3k + 2 –(+1)–> 3k
3k + 2 –(*2)–> 3k + 1 –(+1)–> 3k + 2
2.1.5. The language of words that encode a calendar date (DD/MM/YYYY)
(do not overthink about the actual number of days in a month)
Note: Checking for months with 30 or 31 days can be done with a slightly bigger DFA.
Note: Even checking for bisect years (29 Feb) can still be done with a DFA, but it's too big to do as a seminar example.
2.1.6. (HARD) $ L=\{w \in \{0,1,2,3\}^* \text{ | w follows the rule that every zero is immediately followed by a sequence of at least 2 consecutive threes and every one is immediately followed by a sequence of at most 2 consecutive twos} \} $
2.1.7. The set of all binary strings having the substring 00101
Every state corresponds to a certain current configuration (eg. state B translates to a sequence of 0; C to a seq of 00; D → 001 and so on)
Analyze how each incoming character changes the current available sequence. For example, if we are in state E and we read character 1 we reach a final state, but if we read 0 we go back to state C since the available seq will be 00