Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2022:lab02-dfa [2022/10/06 09:19] alexandra.udrescu01 |
lfa:2022:lab02-dfa [2023/10/17 00:01] (current) mihai.calitescu added exercises for DFA lab |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== 2. Deterministic Finite Automata ====== | ====== 2. Deterministic Finite Automata ====== | ||
- | ===== 2.1. Demo ===== | + | ===== 2.1. DFA practice ===== |
- | <code> | + | |
- | TODO | + | |
- | </code> | + | |
- | ===== 2.2. DFA practice ===== | + | |
<note> | <note> | ||
* Blue = final state | * Blue = final state | ||
* Orange = non-final state | * Orange = non-final state | ||
- | * Sink state = a state that is not final; once reached, there is no transition to leave it, thus the DFA will reject; there is a transition that loops in this state for each possible character | + | * 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 |
</note> | </note> | ||
+ | |||
+ | |||
=== Write DFAs for the following languages: === | === Write DFAs for the following languages: === | ||
- | **2.2.1.** $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $ | + | **2.1.1.** $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $ |
<hidden> | <hidden> | ||
Line 25: | Line 25: | ||
</hidden> | </hidden> | ||
- | **2.2.2.** The language of binary words which contain **exactly** two ones | + | |
+ | **2.1.2.** The language of binary words which contain **exactly** two ones | ||
<hidden> | <hidden> | ||
Line 35: | Line 37: | ||
</hidden> | </hidden> | ||
- | **2.2.3.** The language of binary words which encode odd numbers (the last digit is least significative) | + | |
+ | **2.1.3.** The language of binary words which encode odd numbers (the last digit is least significative) | ||
<hidden> | <hidden> | ||
Line 42: | Line 46: | ||
</hidden> | </hidden> | ||
- | **2.2.4.** (hard) The language of words which encode numbers divisible by 3 | + | |
+ | **2.1.4.** (hard) The language of words which encode numbers divisible by 3 | ||
<hidden> | <hidden> | ||
Line 59: | Line 65: | ||
</hidden> | </hidden> | ||
- | **2.2.5.** The language of words that encode a calendar date (DD/MM/YYYY) | + | |
+ | **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) | (do not overthink about the actual number of days in a month) | ||
+ | |||
+ | |||
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab2_ex5.png?600|}} | {{:lfa:2022:lfa2022_lab2_ex5.png?600|}} | ||
+ | * 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. | * 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. | ||
</hidden> | </hidden> | ||
- | **2.2.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.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} \} $ | ||
<hidden> | <hidden> | ||
+ | |||
+ | {{:lfa:2022:lfa2022_lab2_ex6_v2.png?400|}} | ||
{{:lfa:2022:lfa2022_lab2_ex6.png?400|}} | {{:lfa:2022:lfa2022_lab2_ex6.png?400|}} | ||
- | * injuraturile redirectati-le catre AU | + | * injuraturile redirectati-le catre AU :)) (si MP) |
* All missing transitions lead to a sink state (where there is a transition that loops in that state for any character) | * All missing transitions lead to a sink state (where there is a transition that loops in that state for any character) | ||
</hidden> | </hidden> | ||
+ | |||
+ | **2.1.7.** The set of all binary strings 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> | ||
+ | |||
=== Describe the language of the following DFAs and simulate them on the given inputs: === | === Describe the language of the following DFAs and simulate them on the given inputs: === | ||
- | **2.2.7.** w<sub>1</sub> = 10011110, w<sub>2</sub> = 00110010 | + | **2.1.8.** w<sub>1</sub> = 10011110, w<sub>2</sub> = 00110010 |
{{:lfa:2022:lfa2022_lab2_ex8.png?400|}} | {{:lfa:2022:lfa2022_lab2_ex8.png?400|}} | ||
+ | |||
<hidden> | <hidden> | ||
* The language of binary words where there are no sequences in which the same character repeats 3 or more times. | * The language of binary words where there are no sequences in which the same character repeats 3 or more times. | ||
Line 84: | Line 108: | ||
* (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). | * (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> | </hidden> | ||
+ |