next up previous
Next: Prefix Array Up: CSE 2320: Algorithms and Previous: Knuth-Morris-Pratt Algorithm

Prefix Array


n e y o y o d y n e y o
    y o y o s          

s = 2

How far can we shift P over and be assured of catching all matches?

Since we have matched up to yoyo and yo is a suffix of yoyo, then we can shift over by 2 and start testing at P[3].

Copyright © 1998 The University of Texas at Arlington