Analysis of Algorithms, 91 s2

Analysis of Algorithms, 91 s2

<p> Algorithms (91.503) Homework # 8 Fall 2002</p><p>Solution for Part I of HW#8 91.503, 2002</p><p>* #1. |Z 18| = φ(18) = 18(1-1/2)(1-1/3) = 6 * Z 18= {1, 5, 7, 11, 13, 17} ■</p><p>#2. MODULAR-EQUATION-SOLVER x≡3 mod 7 a b └a/b┘ d x y 1 7 0 1 1 0 7 1 7 1 0 1 1 0 - 1 1 0 (d,x,y) = (1,1,0) since (d|b) = 1|3, x0 = 1(3/1) mod 7 = 3 mod 7 = 3 x≡5 mod 6 a b └a/b┘ d x y 1 6 0 1 1 0 6 1 6 1 0 1 1 0 - 1 1 0 (d,x,y) = (1,1,0) since (d|b) = 1|5, x0 = 1(5/1) mod 6 = 5 mod 6 = 5 x≡4 mod 11 a b └a/b┘ d x y 1 11 0 1 1 0 11 1 11 1 0 1 1 0 - 1 1 0 (d,x,y) = (1,1,0) since (d|b) = 1|3, x0 = 1(4/1) mod 11 = 4 mod 11 = 4</p><p>Chinese Remainder Theorem 7,6,and 11 are relatively prime, so there is solution [x0]m, where m = 7*6*11 = 462 x0 = m1*b1*a1+ m2*b2*a3+ m3*b3*a3 m1 = 6*11 = 66, a1 = 3 m2 = 7*11 = 77, a2 = 5 m3 = 7*6 = 42, a3 = 4</p><p>66*b1≡1 mod 7, b1 = 5 77*b1≡1 mod 6, b2 = 5 42*b1≡1 mod 11, b3 = 5 x0 = 66*5*3 + 77*5*5 + 42*5*4 = 990 + 1925 + 840 = 3755 x ≡3755 mod 462 ≡59 mod 462 All solutions are of the form 59+462k for arbitrary integers k. ■</p><p>#3 Page 1 of 4 Algorithms (91.503) Homework # 8 Fall 2002</p><p>P and S cannot be a pair of public, secret keys for RSA. Since 221 = 13*17, hence φ(221) = (p-1)(q-1) = (13-1)(17-1) = 12*16 = 192. e = 11, which is relatively prime with 192. Now we have to find the multiplicative inverse of 11, modulo 192. 11*d = 1(mod 192). d= 17 in S. e*d mod 192= 11*17 mod 192= 187 mod 192 ≠ 1 mod 192 That means, d is not the multiplicative inverse of e. The pair should be P=(11,221) S=(35,221) (The congruents to 1 mod 192 are {1,193,385,577,…}. We notice that 11|385, so we find d=35) ■</p><p>4. (40 points) Chapter 32: Textbook, p. 910, Exercise 32.1-4. (Courtesy of Harish Rathi) GAP-MATCHER (T, P) 1 List A  MAKE-SUBLIST (P) 2 for i  1 to length[A] 3 do start  NAÏVE-STRING-MATCHER (T, A[i], start) 4 if start equals -1 5 then return “No Pattern Found” 6 return “Pattern Found”</p><p>A modified version of NAÏVE-STRING-MATCHER NAÏVE-STRING-MATCHER (T, P, start) 1 n  length[T] 2 m  length[P] 3 for s  start to n – m 4 do if P[1…m] = T[s + 1… s + m] 5 then return s + m + 1 6 return -1</p><p>To analyze the running time of the algorithm above, lines (1) and (3) need to be analyzed in GAP- MATCHER. Line (1) makes a sublist of pattern P where each element of list is the part between the gap characters, start and gap or gap and end of the text. e.g. for pattern abbac, A will have A[1] = ab, A[2] = ba, A[3] = c This is in O(n). This can be counted as preprocessing time. Now, line (3) is a call to NAÏVE-STRING-MATCHER whose running time is O ((n – m + 1)m) where m is the length of pattern and n is text length. Page 2 of 4 Algorithms (91.503) Homework # 8 Fall 2002</p><p>Line (3) is executed ‘i’ times, that is the number of gap characters in pattern P. Thus, O(i (n – m + 1)m) In worst case P can have length[P] = m’ number of gap characters. When m’ is maximum, m will be minimum (= 1). Giving the running time as O(m’n) which is O(n2). When m’ is minimum (= 1: no gap characters) then running time is O(1(n – m + 1)m) and when m = n/2 then running time is O(n2). Thus worst case running time is thus (n2).</p><p>Comments from Prof. Daniels: We need to add initialization of start to 0 in between lines 1 and 2 of GAP-MATCHER. In line 5 of modified NAÏVE-STRING-MATCHER, s+m+1 should be s+m. In the run-time analysis, we note that start increases monotonically, so the total number of iterations of NAÏVE-STRING-MATCHER‘s for loop is in O(n-m+1). Furthermore, the size of each element of A is in O(m). The total time is therefore in O((n-m+1)m), just like the unmodified NAÏVE-STRING- MATCHER.</p><p>5. (15 points) Chapter 32: Working modulo q = 3, how many spurious hits does the Rabin-Karp matcher encounter in the text T = 4126719021586 when looking for the pattern P = 125? Answer: - (Courtesy of Samip Banker)</p><p>Given, T = 4126719021586 P = 125 q = 3 d = 10 So, n = 13 m = 3 Window size is 3</p><p>Proper Match or spurious hits will be when x = 125 mod 3 = 2 Different windows that we will get are: -</p><p>Window Number Window String Window Value Spurious or Proper Hit</p><p>X1 412 1 No Hit</p><p>X2 126 0 No Hit Page 3 of 4 Algorithms (91.503) Homework # 8 Fall 2002</p><p>X3 267 0 No Hit</p><p>X4 671 2 Spurious Hit</p><p>X5 719 2 Spurious Hit</p><p>X6 190 1 No Hit</p><p>X7 902 2 Spurious Hit</p><p>X8 021 0 No Hit</p><p>X9 215 2 Spurious Hit</p><p>X10 158 2 Spurious Hit</p><p>X11 586 1 No Hit</p><p>We can see that X4, X5, X7, X9, and X10 have value as 2, which mean that either there is a proper match or spurious hit. But as we know that the string value doesn’t match with the pattern we are trying to match, so we have total of 5 spurious hits.</p><p>6. (20 points) Chapter 32: Compute the prefix function π for the pattern abcaabbccab when the alphabet is Σ = {a, b, c}. Answer: -(Courtesy of Samip Banker)</p><p>Given, P = abcaabbccab q = |P| = 11</p><p>For Every k < q</p><p>P [k] (k = 0 to 10) P [q] (q = 1 to 11) Π [q] (q = 1 to 11) ε a 0 a ab 0 ab abc 0 abc abca 1 abca abcaa 1 abcaa abcaab 2 abcaab abcaabb 0 abcaabb abcaabbc 0 abcaabbc abcaabbcc 0 abcaabbcc abcaabbcca 1 abcaabbcca abcaabbccab 2</p><p> q 1 2 3 4 5 6 7 8 9 10 11 P[q] a b c a a b b c c a b Π[q] 0 0 0 1 1 2 0 0 0 1 2</p><p>Page 4 of 4</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us