Mathematics Question

Mathematics

Question Description

The exam is on PST 1-27, starts at 12 am to 12 pm, so the time period is 24 hours. And you can choose any one hour in that period. So the time limit for exam is 1 hour.

The exam will contain the topic DFA, NFA, regular expressions, regular language, equivalence of regular expression and DFA.

I post the practice exam and hw sa well, hope can help for the exam.

Unformatted Attachment Preview

1. (10 points) Using proof by contradiction show that for any positive real numbers x, y √ that x + y ≥ 2 xy. Solution Assume by way of contradiction that √ x + y < 2 xy. √ Since x and y are both positive, x + y and 2 xy are also both positive. Thus we can square both sides of this inequality to get the inequality x2 + 2xy + y 2 < 4xy. Subtracting 4xy from both sides gives x2 − 2xy + y 2 < 0. Factoring the left-hand side of this gives (x − y)2 < 0, but x − y is a real number (since x and y are both real numbers), and the square of any real number is non-negative. Thus we have reached a contradiction, and we have that √ x + y ≥ 2 xy. 2. (10 points) Show using induction that the sequence defined recursively by a1 = 1 and an = 3an−1 + 1 satisfies the formula an = 3n − 1 . 2 Solution We will prove this formula by induction on n. For a base case n we will take n = 1. Plugging n = 1 into the formula 3 2−1 gives 3−1 2 = = 1, 2 2 and since a1 is defined to be equal to 1, the base case holds. For the inductive step, assume that the formula holds for n = k where k is some positive integer. That is, we assume that ak = 3k − 1 . 2 Then by the recursive relation we have that ak+1 = 3ak + 1. 1 By the inductive assumption we have that this is equal to 3· 3k − 1 3k+1 − 3 + 2 3k+1 − 1 +1= = . 2 2 2 Thus we have that 3k+1 − 1 . 2 Therefore the formula holds for n = k + 1. Then we have shown the base case and the inductive step, so by the principle of mathematical induction the formula holds for all positive integers n. ak+1 = 3. (10 points) Prove that sets A and B are equal if (AC ∩ B) ∪ (A ∩ B C ) = ∅. Solution We begin by noting that if (AC ∩ B) ∪ (A ∩ B C ) = ∅, then (AC ∩ B) and (A ∩ B C ) are both subsets of the emptyset, but since the only subset of the emptyset is the emptyset this means that (A ∩ B C ) and (AC ∩ B) are both equal to the emptyset. Now to show the equality of A and B, we will show inclusion both ways. First let a ∈ A, then since A∩B C is the emptyset, a 6∈ A∩B C , which, since a ∈ A, implies that a 6∈ B C . This by the definition of the set complement implies that a ∈ B. Thus since a was arbitrary, every element of A is in B, and A ⊂ B. In the reverse direction let b ∈ B. Then since AC ∩ B is the emptyset and b ∈ B, we have that b 6∈ AC , which implies that b ∈ A. Therefore since every element of B is in A, B ⊂ A, and thus since we have shown inclusion both ways, the sets A and B are equal. 4. (10 points) Give a regular expression for each of the following languages. Include brief justification of your answers. (a) The set of binary strings that start and end with different characters. 2 Solution [1(0 ∪ 1)∗ 0] ∪ [0(0 ∪ 1)∗ 1] Reasoning: Such binary strings either start with 1 and end with 0, or they start with 0 and end with 1. In between we can have anything. 1(0 ∪ 1)∗ 0 gives all words that start with 1 and end with 0, and 0(0 ∪ 1)∗ 1 gives all words that start with 0 and end with 1, and the union of these two regular expressions covers both cases. (b) The set of words in the alphabet {a, b, c} in which every c is followed by at least one b or by at least two a’s. Solution (a ∪ b ∪ caa ∪ cb)∗ Reasoning: Any such word will be a concatenation of copies of a, b, caa, and cb, thus (a ∪ b ∪ caa ∪ cb)∗ is a regular expression for this language. (c) The set of binary strings of odd length. Solution (0 ∪ 1)[(0 ∪ 1)(0 ∪ 1)]∗ Reasoning: (0 ∪ 1)(0 ∪ 1) is the set of all length 2 binary strings so taking the Kleene star operation of that will give all even length strings. Then adding (0 ∪ 1) in front adds one character to give all odd length strings. (d) The set of strings in the alphabet {a, b, c} which contain at most 2 c’s. Solution (a ∪ b)∗ (ε ∪ c)(a ∪ b)∗ (ε ∪ c)(a ∪ b)∗ Reasoning: We have (ε ∪ c) twice since each is a potential c in our strings. Before and after each of these potential c’s, we can have any word in a and b which is what the terms (a ∪ b)∗ give. (e) The set of binary strings that start and end with 1. Solution [1(0 ∪ 1)∗ 1] ∪ 1 Reasoning: If the first and last 1’s are different, then in between them can be anything which is given by the regular expression [1(0 ∪ 1)∗ 1]. If the first and last 1’s are the same, then the only possibility is that the word is just 1. Taking the union of these two cases gives every possibility. 3 1. (10 points) Draw the DFA that is described by the formal definition: ({q0 , q1 , q2 , q3 , q4 }, {0, 1, 2}, δ, q0 , {q0 }) with δ defined by δ(qi , 0) = qi , δ(qi , 1) = q(i+1 mod 5) , and δ(qi , 2) = q(i−1 mod 5) (a) Draw the state diagram of your DFA in JFLAP, export the image as a png or jpg file, and include it as part of your submission. Solution (b) Describe the language recognized by this DFA. Solution The language of this machine is the set of strings over the alphabet {0, 1, 2} such that the difference in the number of 1’s and the number of 2’s is a multiple of 5. To prove this we claim that on input w ∈ {0, 1, 2}∗ , this DFA ends in the state qi if the number of 1’s in w, minus the number of 2’s in w is equal to i (mod 5). This can be shown by induction on the length of w. The base case is that the length of w is 0, which is true since q0 is the start state, and the empty word contains zero 1’s and zero 2’s. For the inductive assumption assume that the statement is true for words of 1 length n − 1. Then let w = w1 w2 . . . wn be an arbitrary word in {0, 1, 2}∗ of length n. By the inductive assumption after n − 1 steps the state of the computation will be qi where i is the number of 1’s among w1 , . . . , wn−1 , minus the number of 2’s reduced modulo 5. The final state of the computation on w will then be δ(qi , wn ). We then have three cases. If wn = 0, then δ(qi , wn ) = qi , and the difference between the number of 1’s and 2’s reduced mod 5 is still i, so the statement is true for w. If wn = 1, then δ(qi , wn ) = qi+1 mod 5 , and since adding wn will increase difference between the number of 1’s and 2’s by 1 modulo 5, again the statement holds for w. Finally if wn = 2, then δ(qi , wn ) = qi−1 mod 5 , and since adding wn will decrease the difference between the number of 1’s and 2’s by 1 modulo 5, the statement holds for wn . Thus the statement is true in any case, and so by the principle of mathematical induction the statement is true for word in {0, 1, 2}∗ of any length. Therefore since q0 is the only accept state, the language of the machine is precisely the set of words for which the difference between the number of 1’s and 2’s is 0 mod 5, or in other words is a multiple of 5. (c) ∗ Is it possible to construct a DFA that recognizes this language with fewer states? If not, explain why not. If so, then draw it using JFLAP. What if we took a NFA instead of a DFA? 2. (10 points) Consider the DFA, M , whose state diagram is given by: 2 (a) Describe the language L(M ). Solution The language of this set is precisely the set of words in {a, b} that have two consecutive characters that are the same. (b) If w ∈ L(M ), will the string obtained by swapping a’s and b’s in w also be in L(M )? Explain your answer. Solution Yes, if w has two consecutive a’s then swapping a’s and b’s will result in two consecutive b’s, similarly if w has two consecutive b’s, then swapping a’s and b’s will result in two consecutive a’s. In either case the resulting word will still have two identical consecutive characters. (c) If w ∈ L(M ), will the string wR (the reverse of w) also be in L(M )? Explain your answer Solution Yes, if w = w1 w2 . . . wn and wi = wi+1 for some index i, then in the word wn wn−1 . . . w2 w1 wi+1 and wi will be consecutive characters such that wi+1 = wi . (d) Describe in your own words the “role” of each of the states. Solution The role of q0 is to be the start state in which we have read no characters from our input. The role of q1 is for if we have not yet encountered two consecutive identical characters in our input, and the last character we have read is an a. The role of q2 is for if we have not yet encountered two consecutive identical characters in out input, and the last character we have read is a b. The role of q3 is for if we have encountered two consecutive identical characters. (e) Write a regular expression that describes L(M ). (please explain your reasoning.) Solution (a ∪ b)∗ (aa ∪ bb)(a ∪ b)∗ . The (aa ∪ bb) is the required two consecutive identical characters, then the (a ∪ b)∗ before and after are allowing us to anything before and after those two characters. (f) ∗ (g) ∗ For c and d, if your answer is no, give a DFA that describes the language obtained by applying that operation (swapping a’s and b’s or reversing) to all elements of L(M ) Can you create a NFA for L(M ) that uses fewer states? 3. (10 points) Consider the DFA, M , whose state diagram is given by: 3 (a) Describe the language L(M ). Solution The language of M is the set of all words over the alphabet {a, b} that start and end with different characters. (b) If w ∈ L(M ), will the string obtained by swapping a’s and b’s in w also be in L(M )? Explain your answer. Solution Yes, if w starts with a and ends with b, then swapping a’s and b’s will result in a word that starts with b and ends with a which is still in the language. Similarly if w starts with b and ends with a, then swapping a’s and b’s will result in a word that starts with a and ends with b, which again will still be in the language. (c) If w ∈ L(M ), will the string wR (the reverse of w) also be in L(M )? Explain your answer Yes, if w = w1 w2 . . . wn , and we consider wR = wn . . . w2 w1 , then since w1 6= wn , we also have that wn 6= w1 , so that wR is also in the language of M . (d) Describe in your own words the “role” of each of the states. Solution The role of q0 is to be the start state in which we have read no characters yet. The role of q1 is for if our word started with a, and the most recently read character is also a. 4 The role of q2 is for if our word started with b, and the most recently read character is also b. The role of q3 is for if our word started with a, and the most recently read character is a b. The role of q4 is for if our word started with b, and the most recently read character is an a. (e) Write a regular expression that describes L(M ). (please explain your reasoning.) Solution (a(a ∪ b)∗ b) ∪ (b(a ∪ b)∗ a). Words in this language fall into two cases: starting with a and ending with b, or starting with b and ending with a. The term (a(a ∪ b)∗ b) covers the first case, and the term (b(a ∪ b)∗ a) covers the second, so taking the union covers all cases. (f) ∗ (g) ∗ For c and d, if your answer is no, give a DFA that descibes the language obtained by applying that operation (swapping a’s and b’s or reversing) to all elements of L(M ) Can you create a NFA for L(M ) that uses fewer states? 4. (10 points) Consider the DFA, M , whose state diagram is given by: (a) Describe the language L(M ). 5 Solution The language L(M ) is equal to {bn am : n, m ≥ 0}, in words it is the set of words that consist of some number of b’s followed by some number of a’s. (b) If w ∈ L(M ), will the string obtained by swapping a’s and b’s in w also be in L(M )? Explain your answer. Solution No, for a counter example we can consider w = ba which is in the language of M , swapping a’s and b’s gives the word ab which is not in L(M ). (c) If w ∈ L(M ), will the string wR (the reverse of w) also be in L(M )? Explain your answer Solution No, for a counter example we can consider w = ba which is in the language of M , reversing w gives the word ab which is not in L(M ). (d) Describe in your own words the “role” of each of the states. Solution The role of q0 is that we have only read b’s so far. The role of q1 is that we have read some (positive) number of a’s after some number of b’s. The role of q2 is that we have at some point encountered a b that occured after an a. (e) Write a regular expression that describes L(M ). (please explain your reasoning.) Solution b∗ a∗ . The b∗ gives us any number of b’s which is then followed by a∗ which gives us any number of a’s. (f) ∗ (g) ∗ For c and d, if your answer is no, give a DFA that describes the language obtained by applying that operation (swapping a’s and b’s or reversing) to all elements of L(M ) Can you create a NFA for L(M ) that uses fewer states? 5. (10 points) Consider the NFA, M , whose state diagram is given by: 6 (a) Describe the language L(M ). Solution The language of M is {ai bj ak : i, j, k ≥ 0}. In words it is the set of words that consist of any number of a’s followed by any number of b’s followed by any number of a’s. (b) If w ∈ L(M ), will the string obtained by swapping a’s and b’s in w also be in L(M )? Explain your answer. Solution No, for a counter example consider the string aba. Swapping a’s and b’s gives the string bab, which is not in L(M ). (c) If w ∈ L(M ), will the string wR (the reverse of w) also be in L(M )? Explain your answer Solution Yes, if w is in L(M ), then w is of the form ai bj ak for some non-negative integers i, j, k. Reversing w will give the word ak bj ai which will also be in L(M ). (d) Describe in your own words the “role” of each of the states. Solution The role of q0 is that we have only read a’s so far. The role of q1 is that we have read some number of a’s followed by some number of b’s. The role of q2 is that we have read some number of a’s followed by some number of b’s followed by some number of a’s. 7 (e) Write a regular expression that describes L(M ). (please explain your reasoning.) Solution a∗ b∗ a∗ . The a∗ ’s gives us the any number of a’s that start and end our words, and the b∗ gives us the any number of b’s in between. (f) ∗ For c and d, if your answer is no, give a NFA that descibes the language obtained by applying that operation (swapping a’s and b’s or reversing) to all elements of L(M ) (g) ∗ Give a DFA that describes the same language as L(M ). 6. (15 points) For each problem, the alphabet will be Σ = {0, 1, 2} and we will be considering each string to be an integer base 3. For the DFA design problems, draw the state diagram in JFLAP, export the image as a png or jpg file, and include it as part of your submission. (a) Design a DFA that recognizes the language: {w ∈ {0, 1, 2}∗ : w in base 3 is congruent to 0 mod 2.} (Note: this set does include the empty string.) Solution We first note that 3n reduces to 1 modulo 2, so that each 1 appearing in a word will contribute 1 to the value of the word reduced modulo 2. Additionally since 0 and 2 both reduce to 0 mod 2, they will not contribute anything. Thus the value of the entire word reduced modulo 2 will be equal to the number of 1’s mod 2. With this in mind we can create a DFA with two states that correspond to the number of 1’s read so far mod 2. 8 (b) Design a regular expression that describes the language: {w ∈ {0, 1, 2}∗ : w in base 3 is congruent to 0 mod 2.} (Note: this set does include the empty string.) Solution As in part a this is equivalent to there being an even number of 1’s in the word. Given such a word we can break it up based on the positions on the 1’s. Before the first 1 will be a string over the alphabet {0, 2}, which is given by (0 ∪ 2)∗ . After that we consider breaking the word into parts that contain two 1’s starting with a 1 and ending either at the end of the word, or right before a third 1 would be added. Each of these parts will be in the regular expression 1(0 ∪ 2)∗ 1(0 ∪ 2)∗ . Then if we want to have any number of these parts (which will correspond to having any even number of 1’s in our words) we will take the Kleene star operation of this expression. Combining this with the first part gives the regular expression: (0 ∪ 2)∗ (1(0 ∪ 2)∗ 1(0 ∪ 2)∗ )∗ . (c) Design a DFA that recognizes the language: {w ∈ {0, 1, 2}∗ : w in base 3 is congruent to 1 mod 4.} (Note: this set does not include the empty string.) Solution We first note that 3 = −1 mod 4, thus the reduction of w0 mod 4 is equal −w mod 4 since adding a 0 to a base 3 expansion is the same as multiplying by 3 Further since wi = w0 + i for i = 0, 1, 2 (doing operations in base 3) the reduction of wi for i = 0, 1, 2 will be equal to −w + i mod 4. We will create a DFA with 4 states, q0 , q1 , q2 , q3 with the intention that we should be at state qi if the word we have currently read reduces to i mod 4. By the previous remark we can achieve this by defining the transition function by δ(qi , a) = q−i+a mod 4 Drawing this out and making q1 the sole accept state, and q0 the start state gives: 9 (d) ∗ Design a regular expression that describes the language: {w ∈ {0, 1, 2}∗ : w in base 3 is congruent to 1 mod 4.} (Note: this set does not include the empty string.) 10 ...
Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Similar Questions
Related Tags