Midterm 1 Solutions
Midterm 1 Solutions
Midterm 1 Solutions
Midterm 1
October 9, 2007
Midterm 1 Solutions
Solution to Part 1
The public exponent e must be relatively prime to (p 1)(q 1) = 24. The smallest such e > 1 is e = 5. The
private key d is the inverse modulo 24 of e, so the corresponding d is 51 mod 24 = 5 since 5 5 = 25 1
mod 24. The encrypted message is me mod N , where m = 3, e = 3, and N = pq = 35. This gives 35
mod 35 33.
For an (e, d) pair to be valid, e must be relatively prime to (p 1)(q 1) = 24. We also assume 1 < e < 24.
This gives 7 possible values for e: 5, 7, 11, 13, 17, 19, and 23. For each e, there is a unique inverse modulo
24, and hence a unique d. Therefore, there are 7 valid (e, d) pairs.
They do not all result in different encryptions of m = 3 because 312 1 mod 35. Therefore, 35 mod 35
and 317 mod 35 are the same encrypted message. Similarly, 37 mod 35 and 319 mod 35 are the same, as
well as 311 mod 35 and 323 mod 35.
Solution to Part 2
When n = 4, = e(2i/4) = i, so the FFT matrix M4 () is
1 1
1
1
1 i 1 i
1 1 1 1 .
1 i 1 i
1
0
1
1
1
1
1
i
1
i
1
1
1
1
1
1
0
i
1 0
i
1
2
1i
=
0 .
1+i
1 1
1
1
1
1 i 1 i .
1 1 1 1
4
1 i 1 i
1
0
1
1
1
4 1
1
1
i
1
i
1
1
1
1
1
i
0
=
0
1
1
4 (1
1
2
+ i)
.
0
1
4 (1 i)
Solution to Problem 3
When Dijkstras algorithm runs, it normally uses a variable dist(u) to store the current best shortest path
distance to a node u V , and prev(u) to store the last node needed to reach node u V in the current best
shortest path found. In order to solve this new problem, we need to create a new variable long(u) for all
nodes u V , which keeps track of the length of the longest edge which needs to be used in order to reach
node u in the current best shortest path. To this end, we can define our algorithm as follows:
***Initialize Variables***
For all u V
dist(u) =
long(u) =
prev(u) = nil
dist(s) = 0
long(s) = 0
H = makequeue(V )
***Begin Main Loop***
While H is not empty
u = deletemin(H)
for all edges (u, v) E
if (dist(v) > dist(u) + l(u,v)) OR
((dist(v) == dist(u) + l(u,v)) AND (long(v) > max(long(u), l(u,v))))
dist(v) = dist(u) + l(u,v)
long(v) = max(long(u),l(u,v))
prev(v) = u
Note that at the end of the algorithm prev(u) stores the last edge used in the shortest path to node u,
where the shortest path chosen is a path amongst all shortest paths, where the longest edge in the path is as
small as possible. Furthermore, we can reconstruct the requisite shortest path from s to t using the prev(u)
pointers.
Solution to Problem 4
If T (n) is the number of lines printed for input n, then T (n) = 3T (n/2) + n4 with a base case of T (1) = 0.
For an asymptotic solution, we can apply the master theorem with nlogb a = nlog2 3 and f (n) = n4 . Since
f (n) polynomially dominates nlogb a (see handout on website), T (n) = (f (n)) = (n4 ) by the master
theorem.
For an exact solution, we expand the recurrence as follows:
T (n) = n4 + 3(n/2)4 + 9(n/4)4 + . . . + 3k (2)4 ,
where k = log2 n 1 since T (1) = 0.
Pk
Pk
3 log2 n
3
This gives T (n) = i=0 3i (n/2i )4 = n4 i=0 (3/16)i = n4 (( 16
1)/( 16
1)) (by the geometric series
4
log2 (3/16)
formula and using k = log2 n 1 ). This can be further simplified to T (n) = 16
) =
13 n (1 n
16
4
log2 3
(n
n
).
13
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: