Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== 1. Deterministic Finite Automata ====== <note> Notation conventions: * Double-circle = final state * Hanging arrow entering state = initial state * Sink state = a state that is not final; once reached, there is no transition that leaves it, thus the DFA will reject; there is a transition that loops in this state for each possible character * We can assume any missing transition leads to a sink state </note> ---- === 2.1. Write DFAs for the following languages: === **2.1.1.** The language of binary words which encode odd numbers (the last digit is least significative). /*<hidden> {{:lfa:2022:lfa2022_lab2_ex3.png?300|}} * We pass through the word, marking the parity of the last character that we have read. </hidden>*/ **2.1.2.** $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $. /*<hidden> {{:lfa:2022:lfa2022_lab2_ex1.png?400|}} * 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. </hidden>*/ **2.1.3.** The language of binary words which contain **exactly** two ones. /*<hidden> {{:lfa:2022:lfa2022_lab2_ex2.png?550|}} * 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] </hidden>*/ **2.1.4.** (*) The language of words which encode binary numbers divisible by 3. **2.1.5.** (* *) The language of words which encode binary numbers divisible by 3, represented in reverse order (the least significant digit is first). **2.1.6.** (*) The language of quaternary words (base 4), that follow 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 language of all binary words having the substring 00101. /*<hidden> {{:lfa:2022:ex_8_dfa.png?400|}} * 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** </hidden>*/ **2.1.8.** The language of binary words that start and end with different digits. /*<hidden> * The language of binary words where there are no sequences in which the same character repeats 3 or more times. * regex: $math[(11 \cup 1 \cup \epsilon) ( (00 \cup 0) 1 (1 \cup \epsilon) )^* (00 \cup 0 \cup \epsilon)] * (0, **10011110**) |--<sub>A</sub> (11, 0011110) |--<sub>A</sub> (01, 011110) |--<sub>A</sub> (02, 11110) |--<sub>A</sub> (11, 1110) |--<sub>A</sub> (12, 110) [There is no transition, so we go to a sink state which is not figured on the drawing.] |--<sub>A</sub> (sink, 10) |--<sub>A</sub> (sink, 0) |--<sub>A</sub> (sink, $math[\epsilon]) The sink state is not a final state, so this word is **rejected**. * (0, **00110010**) |--<sub>A</sub> (01, 0110010) |--<sub>A</sub> (02, 110010) |--<sub>A</sub> (11, 10010) |--<sub>A</sub> (12, 0010) |--<sub>A</sub> (01, 010) |--<sub>A</sub> (02, 10) |--<sub>A</sub> (11, 0) |--<sub>A</sub> (01, $math[\epsilon]) The word is **accepted** by the DFA because we reached a final state (blue). </hidden>*/ ---- === 2.2. Describe in natural speak the language accepted by these DFAs. Make sure your description is fit to the DFA and not too broad (covers all words accepted and no other word). === <note tip> We highly recommend simulating how the automaton behaves on a few test words. </note> **2.2.1** {{:lfa:2024:lab1-2_2_2.png?300|}} /* Cel puțin un grup de: 0 urmat de un număr impar de 1-uri urmat de un număr par de 0-uri */ **2.2.2** {{:lfa:2024:lab1-2_2_1.png?500|}} /* Cuvinte nevide în care după un grup de 0-uri consecutive urmează fie nimic, fie un număr impar de 1-uri consecutive, și după un grup consecutiv de 1-uri urmează fie nimic, fie un număr par de 0-uri consecutive */ **2.2.3** {{:lfa:2024:lab1-2_2_3.png?300|}} /* Oricâte grupuri de a sau ab sau abc */ **2.2.4** {{:lfa:2024:lab1-2_2_4.png?300|}} /* Cuvinte nevide peste {0,1}* care nu încep și se termină cu aceași cifră */ **2.2.5** {{:lfa:2024:lab1-2_2_5.png?400|}} /* Cuvinte de lungime pară care conțin cel puțin un b */ **2.2.6** {{:lfa:2024:lab1-2_2_6.png?400|}} /* Cuvinte care încep cu a sau b și sunt formate din secvențe alternative (posibil vide) separate prin c în care după orice a urmează un b sau după orice b urmează un a; dacă cuvântul începe cu a, prima secvență este de primul tip, iar dacă începe cu b. prima secvență este de al doilea tip */ ---- **2.3.1** What happens if we switch all final states to non-final states and vice-versa in a DFA? **2.3.2** Prove that if L(M) is infinite, there has to be some cycle in the states graph, such that there is a path from the initial state to the cycle, and from the cycle to a final state. **2.3.3** If no such cycle described above exist, L(M) is finite. **2.3.4** Show that if you can construct a DFA to accept L, than you can also construct a DFA to accept $ L \cup \{a\}, \forall a \in \Sigma $.