Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2023:lab02 [2023/10/16 21:01] mihai.udubasa added some solutions |
lfa:2023:lab02 [2024/10/06 21:30] (current) stefan.sterea old revision restored (2023/10/31 11:44) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 2. Deterministic Finite Automata ====== | + | ====== 2. Deterministic Finite Automata and Regular Expressions ====== |
===== 2.1. DFA practice ===== | ===== 2.1. DFA practice ===== | ||
Line 83: | Line 83: | ||
{{:lfa:2022:lfa2022_lab2_ex6_v2.png?400|}} | {{:lfa:2022:lfa2022_lab2_ex6_v2.png?400|}} | ||
- | {{:lfa:2022:lfa2022_lab2_ex6.png?400|}} | ||
* injuraturile redirectati-le catre AU :)) (si MP) | * 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> | ||
+ | |||
+ | |||
+ | **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> | </hidden> | ||
Line 91: | Line 100: | ||
=== 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.1.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|}} | ||
Line 101: | Line 110: | ||
* (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> | ||
- | |||
===== 2.2. Regex practice ===== | ===== 2.2. Regex practice ===== | ||
For each of the exercises from DFA practice write a regex describing the same language. | For each of the exercises from DFA practice write a regex describing the same language. | ||
+ | |||
<hidden 2.2.1.> | <hidden 2.2.1.> | ||
Line 123: | Line 132: | ||
<hidden 2.2.4.> | <hidden 2.2.4.> | ||
- | TODO | + | creating the regex directly is not easy, but the pattern can be derived by studying the dfa, and trying to 'replace' states with more complex transitions. For a step-by-step description of the method, wait until the lecture/lab about the dfa to regex transformation algorithm |
- | $math[] | + | |
+ | |||
+ | $math[((1(01^*0)^*1)\cup0)^*] | ||
</hidden> | </hidden> | ||
Line 131: | Line 143: | ||
$(0[1-9])\cup((1\cup2)[0-9])\cup(3(0\cup1))/((0[1-9])\cup(1(0\cup1\cup2))/[0-9][0-9][0-9][0-9])$ | $(0[1-9])\cup((1\cup2)[0-9])\cup(3(0\cup1))/((0[1-9])\cup(1(0\cup1\cup2))/[0-9][0-9][0-9][0-9])$ | ||
</hidden> | </hidden> | ||
+ | |||
+ | <hidden 2.2.6.> | ||
+ | This language is a good example of a language which is significantly easier to describe using a dfa rather than a regex. The regex is very hard to build intuitively and is very long. For a way to algorithmically build this regex from the dfa built during the first part, wait until the lab/lecture about the dfa->regex transformation. | ||
+ | </hidden> | ||
+ | |||
+ | <hidden 2.2.7> | ||
+ | $math[(0 \cup 1)^*00101(0 \cup 1)^*] | ||
+ | </hidden> | ||
+ |