Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ICSI 210 PRACTICE Final Exam SOLUTIONS (90 points)

December 7, 2022 Name:

1. (10 points) Let m be an integer > 1, and let k be an integer. Recall that the residue of k
mod m is the unique integer in the set {0, 1, 2, ..., m − 1} that is congruent to k modulo m.
Compute the following residues:

1. [11]10 .
2. [−8]6 .
3. [2]3 .
4. [0]12 .

Solution: We simply apply the following formula:


(
x − bx/yc · y x≥0
[x]y = (1)
x + d−x/ye · y x<0

This results in the following answers: [11]10 = 1, [−8]6 = 4, [2]3 = 2, [0]12 = 0.

2. (10 points) An application of modular arithmetic to hash tables.


Consider constructing a hash table on an array of size 27 = 33 . Recall that we defined the hash
of key k ∈ Z to be h(k) = [k]27 , i.e., the residue of k mod 27. Suppose that k = 9`, for some
integer `.
Show that h(k) is either 0, 9, or 18.
Hint: Split into cases based on whether the remainder of ` mod 3 is 0, 1, or 2.
Solution:
We know, from the quotient-remainder theorem, that ` can be written as 3q + r, for some q ∈ Z
and r ∈ {0, 1, 2}. This implies that k = 9(3q + r) = 27q + 9r. Reducing modulo 27, we get that

k ≡ 9r( mod 27). (2)

Note what we did here: we noticed that 27q ≡ 0( mod 27), so that we’re just left
with k ≡ 9r.
If r = 0, then k ≡ 0( mod 27). If r = 1, then k ≡ 9( mod 27). Finally, if r = 2, then k ≡ 18(
mod 27). Thus, the only possible values for h(k) are 0, 9, and 18, as desired.
Addendum: Why did we choose to split into cases based on the remainder of ` divided by
3? We chose 3 in particular because k = 9`, and 9 · 3 = 27, which is the size of the array,
and hence the modulus that we’re working with. This implies that h(k) = 9r, where r is the
remainder of ` divided by 3. If I had chosen some other modulus, such as 81, then we would
consider the remainder of ` divided by 81/9 = 9.

3. (10 points) Suppose that p is a prime number > 2. Suppose that m is a number such that
gcd(m, p) > 1. What must be true about m?
Solution:
Since gcd(m, p) > 1, this implies that m and p both have a common factor other than 1. Since
the only factors of p are 1 and itself, this implies that m has p as a factor. In other words, m
is a multiple of p.
ICSI 210 PRACTICE Final Exam SOLUTIONS Page 2 of 3

4. (10 points) Suppose that a sandwich shop allows customers to build a sandwich by choosing
one out of each of the following sets:

• B = {f ocaccia, baguette},
• C = {stilton, camembert, ricotta},
• M = {turkey, ham, chickpea, tof u}

However, there is a constraint: if baguette is chosen, then stilton and turkey cannot be chosen.
How many valid sandwiches are possible?
Solution:
We use a combination of the product and sum rules: we use the sum rule to count two disjoint
subsets of sandwiches: those that have baguettes and those that don’t. In the former case,
there are 2 · 3 = 6 possibilities. In the latter case, there are 3 · 4 = 12 possibilities. The total
number is thus 6 + 12 = 18.

5. (10 points) A bowl contains 10 red balls and 10 blue balls. A person selects balls at random
without looking at them. How many balls must be selected to be sure of having at least three
blue balls? Justify your answer.
Solution:
The total number of drawn balls is r +b, where r is the number of red balls, and b is the number
of blue ones. Let x be the minimum number of balls such that we are guaranteed to have at
least three blue balls. This is given by

x = max{r + b | 0 ≤ r ≤ 10, 0 ≤ b ≤ 2} + 1. (3)

The maximum in the above expression is achieved when we plug in r = 10, b = 2, so that
x = 13.

6. (10 points) Write down the 5th term of the sum 40


P
j=1 (2j + 5). You do not have to actually do
the arithmetic here. I am trying to test whether or not you understand the summation symbol.
Solution:
The fifth term is 2 · 5 + 5. That is, we replaced j in the generic term (2j + 5) with 5.

7. (10 points) Find a “big O” notation expression for f (n) = 10n + 1/n + 5n log n − 37 + 2log n as
n → ∞ that is as simple as possible.
Solution: The entire expression is O(n log n).
P100 100 j 100−j . Your answer should be a number or an
8. (10 points) Compute j=0 j 37 · (−35)
arithmetic expression, but should not contain variables.
Solution:
We can use the binomial theorem to simplify the expression:
100  
X 100
37j · (−35)100−j = (37 − 35)100 = 2100 . (4)
j
j=0
ICSI 210 PRACTICE Final Exam SOLUTIONS Page 3 of 3

9. (10 points) Suppose that two sets A and B are such that |A| = 8, |B| = 10, and |A ∩ B| = 4.
Compute |A ∪ B|.
Solution:
We use the inclusion-exclusion principle. We have

|A ∪ B| = |A| + |B| − |A ∩ B| = 8 + 10 − 4 = 14. (5)

You might also like