class: center, middle # CS-3110: Formal Languages and Automata ## Midterm Review --- class: center, middle # Spring 2022 Midterm --- # Spring 2022 Midterm Question 1 Write a regular expression that defines the language of all words over the alphabet `\(\Sigma = \{a, b, c\}\)` that contain exactly two as (and any number, including zero, of bs and cs anywhere in the word). --- # Spring 2022 Midterm Question 2 Given the Deterministic Finite Automaton M below, determine: $$ a \\in L(M), abc \\in L(M), cbca \\in L(M), bb \\in L(M)\\\\ \\delta^\ast(s_1,bc), \\delta^\ast(s_1, abc),\\delta^\ast(s_2,bba)\\\\ \\delta^\ast(s_2, ab), \\delta^\ast(s_3, ab), \\delta^\ast(s_3, cbaa) $$
--- # Spring 2022 Midterm Question 3 Design a Finite Automaton (you can choose if you want to make it deter- ministic or not) that recognizes the language over the alphabet `\(\Sigma = \{0, 1\}\)` of words that consist of an odd number of 0s followed by an even number (including zero!) of 1s. Some valid words in this language are 011, 000, or 0000011. Not valid would be 0011 (even number of 0s), 01100 (all 0s have to be at the start of the word), or 001 (even number of zeros, odd number of ones, both are not allowed). Hint: There is an NFA (my solution) with 4 states that accepts this language. There is also a DFA with 5 states. --- # Spring 2022 Midterm Question 4 Convert the regular expression `((01)*)|1` to an equivalent NFA. You don't have to use Thompson's construction, but if you are unsure I recommend that you do (If you follow Thompson's construction without shortcuts you will end up with 9 states; the smallest NFA I could find needs 4). --- class: center, middle # Spring 2021 Midterm --- # Spring 2021 Midterm Question 1 Define the language of all words (using set notation!) over the alphabet `\(\Sigma = \{a,b,c\}\)` that consist of two concatenated palindromes (each of which may be empty). For example, `abaccbbcc` would be a valid word, consisting of `aba` and `ccbbcc`, both of which are palindromes. --- # Spring 2021 Midterm Question 2 Consider the language of all words over the alphabet `\(\Sigma = \{a,b,c\}\)` that contain an even number of `a`s and an odd number of `b`s. I wrote the regular expression `\(c^\ast{}b((aa)^\ast{}|(bc^\ast{}b)|c)^\ast{}\)` for this language, but it is wrong: While the number of `a`s is always even, and the number of `b`s is always odd, there are words that should be in the language, but are not. List 5 example words that *should* be in the language (i.e. they have an even number of `a`s and an odd number of `b`s) but are not recognized by this regular expression and briefly explain why they are not recognized. --- # Spring 2021 Midterm Question 3 Design a Finite Automaton (you can choose if you want to make it deterministic or not) that recognizes the language over the alphabet `\(\Sigma = \{0,1\}\)` that contains exactly one `0` or exactly one `1` (or both). --- # Spring 2021 Midterm Question 4 Convert the regular expression `\(((00)|1)^\ast{}\)` to an equivalent NFA. You don't *have* to use Thompson's construction, but if you are unsure I recommend that you do. --- class: center, middle # More Review Questions --- # Languages ### Using set notation, define the language over the alphabet `\(\Sigma = \{0,1\}\)` that consists of a palindrome with an optional pre- and suffix, where the pre- and suffix are equal (all of which may be empty). For example, `10011011100` would be a word in this language, with `11011` being the palindrome, and `100` the prefix and suffix. -- $$ L = \\{xpx| x \in \Sigma^\ast \wedge p \in \Sigma^\ast \wedge p = p^R\\} $$ --- # Languages ### Using set notation, define the language over the alphabet `\(\Sigma = \{a,b,c\}\)` that contains exactly one `a` or exactly one `b`. -- $$ L = (\\{b,c\\}^\ast{}a\\{b,c\\}^\ast{}) \cup (\\{a,c\\}^\ast{}b\\{a,c\\}^\ast{}) $$ --- # Regular Expressions ### Write a regular expression that recognizes the language over the alphabet `\(\{0,1,2\}\)` of all words that start with a lower digit than they end (e.g. starts with a 0, ends with a 2). -- $$ (0(0|1|2)^\ast(1|2)) | (1(0|1|2)^\ast{}2) $$ --- # Regular Expressions ### Which of the following words are recognized by the regular expression `\((b((ab)|(ca))^\ast{}b)^\ast\)` $$ bb\\\\ babb\\\\ bababbbcab\\\\ bacba\\\\ bacab\\\\ bbacbb\\\\ bbcabb $$ --- # Regular Expressions ### Consider the language over the alphabet `\(\Sigma = \{a,b,c\}\)` of all words where no `a` is directly followed by a `b`, and no `b` is directly followed by a `c`. ### I wrote the regular expression `\((aa^\ast{}c^\ast{})|(bb^\ast{}a^\ast{})|(cc^\ast{})\)` but it doesn't work: There are some words that should be recognized by the regular expression but aren't. List five of them and explain why. -- $$ aca\\\\ bac\\\\ \varepsilon\\\\ cba\\\\ cccb $$ --- # Deterministic Finite Automata ### Construct a Deterministic Finite Automaton that recognizes the language over the alphabet `\(\Sigma = \{a,b,c\}\)` that contains no `a`s or no `b`s. --- # Deterministic Finite Automata .left-column[ Determine: $$ \\text{cad} \in L(M)\\\\ \\text{adc} \in L(M)\\\\ \\text{ddd} \in L(M)\\\\ \\text{dcadd} \in L(M)\\\\ \delta^\ast{}(0, \\text{c})\\\\ \delta^\ast{}(1, \\text{dc})\\\\ \delta^\ast{}(1, \\text{da})\\\\ \delta^\ast{}(1, \\text{dca})\\\\ \delta^\ast{}(2, \\text{acd})\\\\ $$ ] .right-column[
] --- # Deterministic Finite Automata ### Construct a Non-Deterministic Finite Automaton that recognizes the language over the alphabet `\(\Sigma = \{a,b,c\}\)` that contains no `a`s or at most two `b`s. --- # Non-Deterministic Finite Automata .left-column[ Determine: $$ \\text{acca} \in L(M)\\\\ \\text{aca} \in L(M)\\\\ \\text{aa} \in L(M)\\\\ \\text{aba} \in L(M)\\\\ \partial^\ast{}(s_0, \\text{acb})\\\\ \partial^\ast{}(s_2, \\text{bc})\\\\ \partial^\ast{}(s_2, \\text{abc})\\\\ \partial^\ast{}(s_1, \\text{acb}) $$ ] .right-column[
] --- # Thompson's Construction ### Convert the regular expression `\((a^\ast{}|b)\)` into an NFA using Thompson's Construction. --- # NFA to DFA ### Convert the NFA below into a DFA using the power set construction.