1 / 10

Algoritmer og Datastrukturer 2

Algoritmer og Datastrukturer 2. Gerth Stølting Brodal Mønstergenkendelse [CLRS, kapitel 32.1-32.2, 32.4]. Mønster genkendelse. forekomst på position 4. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. skift på 3. 1. 2. 3. 4.

kaylee
Download Presentation

Algoritmer og Datastrukturer 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algoritmer og Datastrukturer 2 Gerth Stølting Brodal Mønstergenkendelse [CLRS, kapitel 32.1-32.2, 32.4]

  2. Mønster genkendelse forekomst på position 4 1 2 3 4 5 6 7 8 9 10 11 12 13 skift på 3 1 2 3 4 Input: Tekst T af længde n og mønster Paf længde m Output: Alle positioner i T hvor P forekommer

  3. Naive Algoritme O(n∙m)

  4. Rabin-Karp : Eksempel P = 31415 T h(P) = P mod 13 hash værdier 310000 2 3 2 33 2 (ab) mod p = ((a mod p)b) mod p (a+b) mod p = ((a mod p)+b) mod p (a+px) mod p = a mod p, f.eks. 24 mod 13 = 11 = -2 mod 13

  5. 1981 Rabin-Karp T[s + m + 1] T[s+1]h O(n∙m) p = P[1]dm-1 +P[2]dm-2 + ∙∙∙ +P[m-1]d1+P[m]d0 mod q

  6. 1977 Knuth-Morris-Pratt π(0) = 0 π (q) = max { i | i<q og P[1..i] er et suffix af P[1..q] } i T y P x q P z O(n) π(q)

  7. Knuth-Morris-Pratt: Eksempel π(0) = 0 π (q) = max { i | i<q og P[1..i] er et suffix af P[1..q] }

  8. Knuth-Morris-Pratt: Beregning af prefix funktionen q = P y P x O(m) k

  9. Knuth-Morris-Pratt: Beregning af prefix funktionen

  10. Worst-case tider [CLRS] 32.1 32.2 (32.3) 32.4

More Related