Docsity

Extended Euclidean Algorithm, Shortest Paths-Algorithm Design and Data Representation-Exam Paper Solution, Exams of Data Representation and Algorithm Design

Toggle sidebar
bg1
Model Solutions
COMP202 Class Exam 2
Complexity of Algorithms 29 April 2009
1. (a) Here’s the table format that we talked about in class, where we fill
in the top four rows from left-ro-right, and then having done that,
we find the last two rows for jand kfrom right-to-left:
a306 264 42 12 6
b264 42 12 6 0
q1 6 3 2 -
r42 12 6 0 -
j19 −3 1 0 1
k−22 19 −310
This tells us that the gcd is d= 6.
(b) From above, we see that 6 = (19) ·(306) + (−22) ·(264) (as can also
be easily checked).
Hence j= 19 and k=−22 are the relevant jand k.
2. We can use Dijkstra’s algorithm to find shortest paths for this graph. We
start with the distance from Ato itself to be 0, and distances to neighbors
of Aset to the edge lengths. At each step after that, a vertex having
smallest temporary distance label becomes “fixed”, and we update (non-
fixed) vertex distances that are neighbors of the newly fixed vertex.
The entries in the table are the distance labels (temporary or permanent)
and the predecessor vertex so that we can reconstruct the shortest paths
by tracing backwards through the table at the end of the algorithm.
Fixed A B C D E F G H J K
A0,∅ ∞ ∞ 4, A 2, A ∞ ∞ 2, A 4, A ∞
E0,∅ ∞ 5, E 3, E 2, A 7, E ∞2, A 4, A ∞
H0,∅ ∞ 5, E 3, E 2, A 7, E ∞2, A 2, H 6, K
J0,∅ ∞ 5, E 3, E 2, A 7, E ∞2, A 2, H 5, J
D0,∅6, D 5, E 3, E 2, A 4, D ∞2,A 2, H 5, J
F0,∅6, D 5, E 3, E 2, A 4, D ∞2,A 2, H 5, J
K0,∅6, D 5, E 3, E 2, A 4, D ∞2,A 2, H 5, J
C0,∅6, D 5, E 3, E 2, A 4, D 5, C 2, A 2, H 5, J
G0,∅6, D 5, E 3, E 2, A 4, D 5, C 2, A 2, H 5, J
B0,∅6, D 5, E 3, E 2, A 4, D 5, C 2, A 2, H 5, J
3. (a) To encrypt the message M= 100, we compute n=p·q= 221 and
then we compute
C= 1005mod 221.
1
docsity.com
pf3

Partial preview of the text

Download Extended Euclidean Algorithm, Shortest Paths-Algorithm Design and Data Representation-Exam Paper Solution and more Exams Data Representation and Algorithm Design in PDF only on Docsity!

Model Solutions

COMP202 Class Exam 2 Complexity of Algorithms 29 April 2009

  1. (a) Here’s the table format that we talked about in class, where we fill in the top four rows from left-ro-right, and then having done that, we find the last two rows for j and k from right-to-left: a 306 264 42 12 6 b 264 42 12 6 0 q 1 6 3 2 - r 42 12 6 0 - j 19 − 3 1 0 1 k − 22 19 − 3 1 0 This tells us that the gcd is d = 6. (b) From above, we see that 6 = (19) · (306) + (−22) · (264) (as can also be easily checked). Hence j = 19 and k = −22 are the relevant j and k.
  2. We can use Dijkstra’s algorithm to find shortest paths for this graph. We start with the distance from A to itself to be 0, and distances to neighbors of A set to the edge lengths. At each step after that, a vertex having smallest temporary distance label becomes “fixed”, and we update (non- fixed) vertex distances that are neighbors of the newly fixed vertex. The entries in the table are the distance labels (temporary or permanent) and the predecessor vertex so that we can reconstruct the shortest paths by tracing backwards through the table at the end of the algorithm. Fixed A B C D E F G H J K A 0 , ∅ ∞ ∞ 4 , A 2 , A ∞ ∞ 2 , A 4 , A ∞ E 0 , ∅ ∞ 5 , E 3 , E 2 , A 7 , E ∞ 2 , A 4 , A ∞ H 0 , ∅ ∞ 5 , E 3 , E 2 , A 7 , E ∞ 2 , A 2 , H 6 , K J 0 , ∅ ∞ 5 , E 3 , E 2 , A 7 , E ∞ 2 , A 2 , H 5 , J D 0 , ∅ 6 , D 5 , E 3 , E 2 , A 4 , D ∞ 2 , A 2 , H 5 , J F 0 , ∅ 6 , D 5 , E 3 , E 2 , A 4 , D ∞ 2 , A 2 , H 5 , J K 0 , ∅ 6 , D 5 , E 3 , E 2 , A 4 , D ∞ 2 , A 2 , H 5 , J C 0 , ∅ 6 , D 5 , E 3 , E 2 , A 4 , D 5 , C 2 , A 2 , H 5 , J G 0 , ∅ 6 , D 5 , E 3 , E 2 , A 4 , D 5 , C 2 , A 2 , H 5 , J B 0 , ∅ 6 , D 5 , E 3 , E 2 , A 4 , D 5 , C 2 , A 2 , H 5 , J
  3. (a) To encrypt the message M = 100, we compute n = p · q = 221 and then we compute C = 100^5 mod 221.

(b) To find the decryption key, we use the Extended Euclidean Algorithm applied to (p − 1)(q − 1) = 16 · 12 = 192 and e. As before, here’s the table for doing this: a 192 5 2 1 b 5 2 1 0 q 38 2 2 - r 2 1 0 - j − 2 1 0 1 k 77 − 2 1 0 From the table above we see that 1 = (−2) · 192 + 77 · 5. Then, using this equation, we can see that 1 ≡ 77 · 5 (mod 192). This tells us that we can take the decryption key as d = 77.

  1. The pictures for parts (a) and (b) are given below. Note that I described two augmentations that we can do (and they don’t use the same edges), so I did them both in one operation. The final flow we end up with (after the two augmentations) is shown at the bottom. The middle graph is the residual network after we have after the two augmentations is shown in the middle. The final flow has value 13 (the total flow from s to t is 13 units).