Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CompSci 230 Midterm Exam Sample The exam will be closed-book, closed-notes, except for a single 8.5 × 11 inch sheet of paper, on which you may write anything you wish. You will not be allowed to have anything on your desk other than the exam, a pen/pencil, an eraser, and the sheet of paper just mentioned. Use margins and backs of the exam pages for scratch space. If you have a bag, you will be asked to zip it closed. You will be asked to turn off all your electronic devices. Simple solutions will be preferred to complex ones. Only answer the questions being asked. Show intermediate results only when asked for, or when you are unsure of your answer (for possible partial credit). Materials covered are all the materials listed in parts 1, 2, 3 on the class syllabus web page (up to and including February 19), plus homework assignments 1 through 6. This includes class notes, FDM, and supplementary materials, but no LATEX. 1. Place T for “true” and F for “false” next to each of the statements below. P is the set of positive integers. 3|6 T 6|3 F 2 3=6 F If n ∈ P then n|0 T If a, b > 0 then log(a) + log(b) = log(ab) T ∅∈∅ F 15 and 18 are coprime F 2. Write numerical values for the following expressions in the table below. Each answer is a single number. 7 mod 3 1 3 mod 7 3 GCD(2 × 33 × 42 , 22 × 3 × 4) 24 3. What is the prime factorization of 120? 4. What is the decimal representation of 1101{2}? COMPSCI 230 — Duke — February 22, 2015 5. What is the binary representation of 26{10}? 6. Is this function tail recursive? (define (f n k) (cond ((> k n) 0) ((or (= k 0) (= k n)) 1) (else (+ (f (- n 1) (- k 1)) (f (- n 1) k))))) 7. What does the function in the previous question compute? 8. What does this Racket expression evaluate to? (map (lambda (x) (apply + (cons x '(2 3)))) '(1)) 9. Apply the substitution model to the following expression: (cond ((< 0 3) (- 5 (* 2 2))) (else 2)) COMPSCI 230 — Duke — February 22, 2015 10. Write the simplest possible expression for the set N \ P. Assume that zero is a natural number. 11. Let A = {1, 2} and B = {2, 3, 4}. Write the following set by enumerating its elements explicitly. C = (B \ A) × (A ∩ B) 12. Consider all 3-sequences from domain D = {1, 2, 3} into codomain C = {a, b, c}. (a) How many such sequences are there? (b) How many of such sequences are surjections? (c) How many of such sequences are injections? 13. This is a row of Pascal’s triangle: 1 6 15 20 15 6 Write the subsequent row. COMPSCI 230 — Duke — February 22, 2015 1 14. Let D = {x : x ∈ Z and |x| = x2 } and C = {y : y ∈ [2..5] and y | 6} (a) Write D by listing its elements explicitly. (b) Write C by listing its elements explicitly. (c) Let f be the function with domain D and codomain C defined as follows: f = {(−1, 3), (0, 2), (1, 2)} Is f an injection? (d) Is f a surjection? (e) How many functions are there from D to C? (f) How many functions are there from C to D? COMPSCI 230 — Duke — February 22, 2015 15. The following is an inefficient implementation for the RSA encryption of a cleartext message m with public key (n, e): (define (encrypt m e n) (modulo (expt m e) n)) Write the definition of an equally inefficient function decrypt that decrypts the resulting cypher text c with private key (n, d). 16. If A is a denumerable set (that is, it has the same cardinality as the set of natural numbers), is A × A always denumerable? 17. Should you use dovetailing (Cantor’s first diagonal argument) or diagonalization (Cantor’s second diagonal argument) to prove your previous answer? 18. Use the binomial theorem to prove that n ∑ ( ) n (−1) =0 k k k=0 COMPSCI 230 — Duke — February 22, 2015 19. There are three men and six women. Each man marries one of the women. In how many ways can this be done? 20. Prove the following equality with a combinatorial argument: ( ) ( ) n n = for 0 ≤ i ≤ n i n−i (no credit for an algebraic proof). COMPSCI 230 — Duke — February 22, 2015