Download Sample Solution

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

History of the function concept wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Transcript
CompSci 230 Midterm Exam Sample— Sample Solution
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.
3. What is the prime factorization of 120?
7 mod 3
1
3 mod 7
3
GCD(2 × 33 × 42 , 22 × 3 × 4)
24
Answer: 23 × 3 × 5
4. What is the decimal representation of 1101{2}?
5. What is the binary representation of 26{10}?
Answer: 13
Answer: 11010
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)))))
Answer: No.
7. What does the function in the previous question compute?
Answer:
(n)
k
8. What does this Racket expression evaluate to?
(map (lambda (x) (apply + (cons x '(2 3)))) '(1))
Answer: '(6)
9. Apply the substitution model to the following expression:
(cond ((< 0 3) (- 5 (* 2 2))) (else 2))
Answer:
(cond (#t (- 5 (* 2 2))) (else 2))
(- 5 (* 2 2))
(- 5 4)
1
COMPSCI 230 — Duke — February 22, 2015
10. Write the simplest possible expression for the set N \ P. Assume that zero is a natural number.
Answer: {0}
11. Let A = {1, 2} and B = {2, 3, 4}. Write the following set by enumerating its elements explicitly.
C = (B \ A) × (A ∩ B)
Answer: {(3, 2) , (4, 2)}
12. Consider all 3-sequences from domain D = {1, 2, 3} into codomain C = {a, b, c}.
Answer: 33 = 27.
(a) How many such sequences are there?
Answer: 3! = 6
(b) How many of such sequences are surjections?
Answer: 3! = 6
(c) How many of such sequences are injections?
13. This is a row of Pascal’s triangle:
1
6
15
20
15
6
1
Write the subsequent row.
Answer:
1
7
21
35
35
21
7
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.
Answer: D = {−1, 0, 1}
(b) Write C by listing its elements explicitly.
Answer: C = {2, 3}
(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?
Answer: No.
(d) Is f a surjection?
Answer: Yes.
(e) How many functions are there from D to C?
Answer: 23 = 8
(f) How many functions are there from C to D?
Answer: 32 = 9
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).
Answer:
(define (decrypt c d n)
(modulo (expt c d) n))
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?
Answer: Yes.
17. Should you use dovetailing (Cantor’s first diagonal argument) or diagonalization (Cantor’s second diagonal argument) to prove
your previous answer?
Answer: Dovetailing.
COMPSCI 230 — Duke — February 22, 2015
18. Use the binomial theorem to prove that
n
∑
( )
n
(−1)
=0
k
k
k=0
Answer: Letting a = −1 and b = 1 in
(a + b)n =
n ( )
∑
n k n−k
a b
k
k=0
yields the result immediately.
19. There are three men and six women. Each man marries one of the women. In how many ways can this be done?
Answer: Every 3-permutation of a 6-set corresponds to a different set of marriages, so the count is
(6)3 =
6!
= 6 · 5 · 4 = 120 .
(6 − 3)!
20. Prove the following equality with a combinatorial argument:
( ) (
)
n
n
=
i
n−i
for
0≤i≤n
(no credit for an algebraic proof).
( )
Answer: There are ni ways( to pick
) i elements out of an n-set. Each choice is equivalent to identifying the n − i elements that
n
are not chosen, and there are n−i
ways to do so. So the lefthand side and the righthand side of the equality above must be equal
to each other.
COMPSCI 230 — Duke — February 22, 2015