Let Σ = {0, 1} and let D = {w w contains an equal number of occurrences of the…
- User
Let Σ = {0, 1} and let D = {w | w contains an equal number of occurrences of the substrings 01 and 10}. Thus 101 ∈ D because it contains a single 01 and a single 10 but 1010 ̸∈ D because it contains a single 01 but two 10s. Show that D is a regular Language.
Answer: Every time the input switches from 0 to 1, we have 01. Every time it switches from 1 to 0, we have 10. So, the number of 01 and 10 substrings can differ by most by 1. If a string starts with 0 and ends with 0 or starts with 1 and ends with 1, the counts of 01 and 10 substrings are equal. If a string starts with 0 and ends with 1 or starts with 1 and ends with 0, the counts differ by 1. D includes only strings where the counts are equal. So, we can construct a DFA that keeps track of the current symbol (0 or 1) and the parity of the counts of 01 and 10 substrings.
Our states can be even, odd, start0, and start1. We start in even either way. Then, when reading a symbol that does not change from the previous symbol, stay in the current state. On reading a symbol that changes from the previous symbol, if moving from even then go to odd. If going from odd then go to even.The DFA accepts when we end in even.
Since we can make a DFA to recognize D, D is a regular language.
- (Let Σ = {0, 1} and let Bsubscript3 = {w | w is a proper binary representation of a number divisible by 3}, where “proper” means the representation has no leading 0s unless the entire string is just one zero. Is Bsubscript3 a regular language?
Answer: Yes, it is regular.
To start: the strings can’t have leading zeroes. A binary number is divisible by 3 based on the modulo 3 remainder of its value. We can construct a DFA that represents the reminders (0, 1, and 2) when divided by 3. The accepting state only accepts when the remainder is 0, or the input is divisible by 3. Since we can construct a DFA (shown below) for the language, we can conclude that it is regular.
- In this problem, assume that the components of a DFA are given to you in appropriate data structures, that is, sets for Q, Σ, and F and a map (dictionary) for δ.
(a) Describe a method, i.e. an algorithm, which, given a DFA M = (Q, Σ, δ, q0, F), determines whether L(M) = ∅. (b) Describe a method, i.e. an algorithm, which, given two DFAs M1 and M2, determines whether their languages are disjoint, that is, whether L(M1) ∩ L(M2) = ∅.
Answers:
I am not the greatest at pseudocode, so I am going to just describe this algorithm in English to the best of my ability. First, we make an empty set - let’s call it “visited” - to keep track of states that have been visited. Then we create a stack and push the initial state q0. While the stack is not empty, we pop a state q from the stack. Then, if q is in F (accepting state) return False (because L(M) is not ∅y). If q is not in visited, add q to visited, then for each symbol a∈Σ, we compute the next state q’ = δ(q,a). If q’ is not in visited, we push q’ onto the stack. If the loop ends and no accepting state has been reached, we return true (indicating that L(M) = ∅.) Here we are determining whether the languages recognized by two DFAs are disjoint. First, we can make a new DFA that tracks the states of both DFAs at the same time. The new DFA starts in a state where both DFA 1 and DFA 2 are in their starting states. For every character we read, we move both DFAs according to their own rules. The new machine is accepting if both DFAs are in accepting states. If we can reach any accepting state in this combined machine, it means at least one string is accepted by both DFA 1 and 2, meaning they aren’t disjoint. We would then need to check all states that we can reach in this new DFA, and keep track of visited states. If we find a state that accepts for our new DFA, L(M1)∩L(M2)=∅ (the languages are not disjoint). If none exist, L(M1)∩L(M2)=∅ (the languages are disjoint).
- Assistant