The test is open-everything with the sole limitation that you
neither solicit nor give help while the exam is in progress.
Do all ten problems.
Problem | You got | Out of |
---|
1 | | 10
|
2 | | 10
|
3 | | 10
|
4 | | 10
|
5 | | 10
|
6 | | 10
|
7 | | 10
|
8 | | 10
|
9 | | 10
|
10 | | 10
|
TOTAL | | 100
|
- Give the asymptotic time complexity
of the following, using $\Theta$-notation.
for (int i = 1; i * i <= n; i++) {
for (int j = 1; j <= n; j += j) {
System.out.println("*");
}
}
- Suppose $f(n)=\sqrt{n^3}$ and $g(n)=5^{\log_3{n}}$.
Is $f$ in $O(g)$, $\Omega(g)$, or $\Theta(g)$?
Justify your answer (rigorously), appealing to the definitions of $O$, $\Theta$,
or $\Omega$ as needed.
- The following items are inserted, in this order,
into a binary max heap: 1 5 4 17 22 3 19. Then we remove an element. What
does the heap now look like? Draw both the tree form and the array form.
- Here’s a famous function:
def c(n):
return 0 if n==1 else c(n/2 if n%2==0 else 3*n+1)+1
Write this function tail-recursively.
- An algorithm with complexity function $T(n) = 2^n$
can process a 30-element list on our PC in 256 seconds.
- How many days would it take to process a 40-element list?
- How many years would it take to process a 50-element list?
- If we ran the algorithm on a machine that was one
billion times faster than our PC, how large of a list could
we process in one day? (Note 1 day = 86400 seconds)
- If we needed a computer that could process 80 elements
in a week, how much faster than our original PC does
this computer need to be? (1 week = 604800 seconds)
- An algorithm with complexity function $T(n) = 8 \log_2 n$
can process a 512-element list on our PC in 144 seconds.
- How long would it take to process a 2048-element list?
- How long would it take to process a 1048576-element list?
- If we ran the algorithm on a machine that was one
thousand times faster than our PC, how large of a list could
we process in one day? (Note 1 day = 86400 seconds)
- If we needed a computer that could process 4096 elements
in a minute, how much faster than our original PC does
this computer need to be?
- In the reading for the course, you’ve seen that
Fermat’s Little
Theorem and corollaries give rise to probabilistic primality tests; for example
we know that if, for all $a$ not divisible by $p$, $a^{p-1} \equiv 1 \pmod p$
then $p$ might be prime. But it turns out that there is actually a
perfectly deterministic primality test: Wilson’s
Theorem says that $(p-1)! \equiv -1 \pmod p$ if and only if $p$ is prime.
Write a function called
is_prime
or isPrime
that
returns a boolean value indicating whether its argument is prime or not. Then
answer whether there are any disadvantages to using this function. Okay there
is a huge one. What is it? Answer using technical language and back it up with
real numbers.
- Given $p=876872342387$,
$q=276872342389$, and $e=5$, what are the RSA public and
private keys?
- How many possible “keys” are there
in a block transposition cipher that transposes individual bytes within blocks
of 16 bytes?
- In the mod-17 world, what is the discrete logarithm,
base 3, of 13?