90 likes | 215 Vues
This document explores Crochemore’s algorithm for detecting repetitions within sequences, focusing on its efficient implementation in terms of speed and memory usage. It compares a brute-force approach with the optimized implementation, highlighting the algorithm's ability to identify patterns effectively. The algorithms are presented through various code snippets and analysis of complexity, showcasing its adaptability for applications in computer science. The benefits of this algorithm include reduced computational time and efficient use of resources, making it a valuable tool for researchers and developers.
E N D
Crochemore’s algorithm for repetitions and its fast and space-efficient implementation F. Franek Algorithms Research GroupComputing and Software McMaster University November 2001 slide 1/9
for(i = 0; i < N-2; i++) {for(k = 1; k <= (N-i)/2; k++) { s = 1;for(j = 0; j < k; j++) if (x[i+j] != x[i+k+j]) {s=0; break; } if (s) printf(“square of length %d at position %d\n”,k,i);}} Trivial, brute force O(n3) algorithm for repetitions. slide 2/9
a b a a b a b a a b a a b a b0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 level 1 {0,2,3,5,7,8,10,11,13}a {1,4,6,9,12,14}b 2 {2,7,10}aa {0,3,5,8,11,13}ab {1,4,6,9,12}ba {14}b$ 3 {2,7,10}aab {0,3,5,8,11}aba {13}ab$ {1,6,9}baa {4,12}bab 4 {2,7,10}aaba {0,5,8}abaa {3,11}abab {1,6,9}baab {4}baba {12}bab$ 5 {7}aabaa {2,10}aabab {0,5,8}abaab {3}ababa {11}abab$ {1,6,9}baaba 6 {2}aababa {10}aabab$ {0,5,8}abaaba {6}baabaa {1,9}baabab 7 {5,8}abaabaa {0}abaabab {1}baababa {9}baabab$ 8 {5}abaabaab {8}abaabaa$ slide 3/9
O O 0 1 2 3 4 5 6 N indexes 4 5 CNext[ ] c1={2,4,5} 2 4 CPrev[ ] 5 CEnd[ ] 2 CStart[ ] 3 CSize[ ] 1 1 1 CMember[] Total this slide 6*Nsubtotal 6*N slide 4/9
0 1 2 3 4 5 6 N indexes …. 0 1 3 CEmptyStack SelQueue ScQueue RefStack Refine[] Total this slide 5*Nsubtotal 11*N slide 5/9
O O 0 1 2 3 4 5 6 N indexes 5 FNext[ ] f2={3,5} 3 FPrev[ ] 3 FStart[ ] 2 2 FMember[] Total this slide 4*Noverall total 15*N slide 6/9
0 1 2 3 4 5 6 N indexes 4 5 3 CNext[ ] c1={2,4,5} 5 2 CPrev[ ] Memoryvirtualization CEnd[ ] 2 CStart[ ] CSize[ ] 1 1 1 CMember[] Total this slide 4*Nsubtotal 4*N slide 7/9
0 1 2 3 4 5 6 N indexes ScQueue CEmptyStack …. 0 1 3 Memorymultiplexing RefStack SelQueue Refine[] Refine[] is virtualized over FNext[], FPrev[], and FStart[] Total this slide 2*Nsubtotal 6*N slide 8/9
0 1 2 3 4 5 6 N indexes 5 FNext[ ] f2={3,5} 3 FPrev[ ] Memoryvirtualization 3 FStart[ ] 2 2 FMember[] Refine[] is virtualized over Total this slide 4*Noverall total 10*N slide 9/9