CPSC 2: Models of Computation ssignment #4, due Wednesday, July 22nd, 29 at 4: Submission Instructions Type or write your assignment on clean sheets of paper with question numbers prominently labeled. nswers that are difficult to read or locate may lose marks. We recommend working problems on a draft copy then writing a separate final copy to submit. Your submission must be stapled below the CPSC 2 assignment cover page located at http://www. ugrad.cs.ubc.ca/ cs2/current/ssignments/assign-cover-page.pdf or a clearly legible reproduction of the same information. (If you are writing by hand, you may omit the text of the academic conduct policy, but you must include and sign the statement I understand the academic conduct policy and certify that my assignment follows it. and acknowledge assistance.) dditionally, include your name at the top of each page. We are not responsible for lost pages from unstapled submissions. Submit your assignment to the appropriately marked box outside of ICCS by the due date and time listed above. Late submissions are not accepted. Note: the number of marks allocated to a question appears in square brackets before the question number. Questions [6]. Consider each of the following equalities. If it is true for all sets, B and C, then prove it using the set identities. If it isn t, then give a couterexample that shows that it is not always true. (a) ( B) = B. (b) (B C) = ( B) ( C) [6] 2. Prove that for all subsets, B and C of the universal set U, if B C, then C B. [6] 3. Let and B be arbitrary sets contained in a universal set, U. Construct a formal proof to show that If B = ( B) (B ) then B = Hint: Try proving the contrapositive of the theorem using a proof by contradiction. [8] 4. There is a very important concept in Computer Science called hashing. hash function performs hashing by taking a potentially large and complex piece of data and representing it with a relatively short number. mong other things, we use hashing for security and robustness (i.e., sending a document and its hash to a recipient so that the recipient can check that the received document still matches the hash and is therefore probably not corrupted) and for highly efficient data structures called hash tables that store complex data in arrays, using the hashed value as the index in the array. Below is a link to the PI for the java.lang.object.hashcode() method. This java method is a hash function. While you re reading the PI, think about the definition of a function and think about which parts of the PI description of this method are directly based on the fact that the hashcode() method is a hash function. http://java.sun.com/javase/6/docs/api/java/lang/object.html#hashcode() (Note that it s not necessary to read the PI to answer the following questions) In this problem, you will explore hash functions.
[2] a. We ll consider a hash function that maps documents whose file size is exactly 8, bits to a 32-bit number. Of course, we can think of an 8, bit document as a 8,-bit binary number if we want. Write a formal description of our hash function h s domain and co-domain. Your answer should look like f : Z + Z but with the right function letter, domain, and codomain. (HINT: we can think of a 3-bit number as being drawn from the set {,, 2,..., 6, 7}. How can that help with your domain/co-domain?) [2] b. Is our hash function necessarily onto? Can it be onto? [2] c. Is our hash function one-to-one? Can it be one-to-one? [2] d. Hash tables must include a collision strategy: a way to deal with situations where more than one element has the same hash value (and would therefore be stored at the same place in the array the hash table uses). Either explain why this is necessary based on your answers to (b) and (c) or explain how hash tables could avoid such a strategy altogether (but still operate with the sample domain and co-domain we described in this question). [8] 5. For each of the following indicate whether it is -, whether it is onto, and whether it is a - correspondence. Your answers must be well justified (a simple yes or no is not sufficient), but you need not formally prove them. [2] a. Negation over the integers. [2] b. ddition over the positive integers. (Note: we consider a function that takes two arguments to take a two-tuple. In this case, then, the domain is Z + Z + and the codomain is Z +. Multiplication works similarly!) [2] c. Multiplication over the positive integers. [2] d. Negation over 32-bit signed ints (using a two s complement representation). [8] 6. The following finite-state machines, starting in the designated starting state, will end up in an accepting state after seeing some strings consisting of characters taken from the given input alphabet Σ. escribe in English, and as simply as possible, the strings for which the machine ends up in an accepting state, i.e., the language the F accepts. Briefly explain your answer (but you need not prove your answer correct). [2] a. The alphabet Σ = {, }. [3] b. The alphabet Σ = {, }.,
[3] c. The alphabet Σ = {, }. Hint: think of the input as an unsigned integer; try running the first 5 unsigned binary integers through the F.) [6] 7. Let Σ = {, C, G, T }. esign a F that accepts exactly the strings that start with either or T, and end with a character different from the one they started from. For instance, your F should accept the strings CCGGTC and TCGCCT but not the strings CGGTC or GGC- CCGC. (s always, write your answer neatly; this is especially important with Fs!) [6] 8. esign a F that will accept exactly the strings over the alphabet {, B,..., Z} that contain the substring B, but not the substring C. For instance, your F should accept the strings BB- BLING, BSOLUTE and BOBB, but not CCIENT, BRCBR or COMPUTER. (Note: you can label an arc Σ to indicate that every input letter received while at the arc s initial state follows the arc or label it else to indicate that every input letter not otherwise labelled from the arc s initial state follows the arc.) [3] 9. Theoretically, the transition function of a F may or may not be onto. In practical terms, what would it mean if the transition function for a F was not onto? Could such a F be useful? If so, under what circumstances? If not, why not?
[6]. raw the F represented by the following sequential circuit. Label states so that their correspondence with the circuit is clear. Use prediction = and last = as your start state. (ssume the FFs ( flip flops) start with prediction = and last = and not in an undefined state.) Label arcs with the value of taken, i.e., or. States in which prediction is true should be accepting states.
[]. For practice only: Consider the following definition for a sequence of sets based on a F: R is the set containing the start state of the F. R is the union of R with all the states in the F that are connected to by arcs from the states in R. R 2 is the union of R with all the states in the F that are connected to by arcs from the states in R. nd so forth. (So, R n is the union of R n with all the states in the F that are connected to by arcs from the states in R n, where n.) [] a. What is the value of R R R 2 R 3...? [] b. For the following F, what is R 3? [] c. If a F had states that were not in R n for any non-negative integer n, what could you say about those states? [] 2. For practice only: Write regular expressions describing the following sets of strings: [3] a. Strings of s, Bs and Cs that do not contain two consecutive letters that are both or C. [4] b. Java comments that start with the characters /* and end at the next occurrence of the characters */. Since the character * has special meaning inside a regular expression, you can write [*] to represent it. Be careful: /* This is not all */ a comment*/ is not a valid comment, because there is an extra */ inside.