// CALL: MATCH("ATT", "GATTACA") // STOPS: index // One bound is wrong. Every position where pattern P occurs exactly in text T. FUNCTION MATCH(P : STRING, T : STRING) RETURNS LIST OF INTEGER // Set up DECLARE N : INTEGER DECLARE M : INTEGER DECLARE Matched : BOOL DECLARE Answer : LIST OF INTEGER N <- LENGTH(T) M <- LENGTH(P) // Visit each legal start FOR I <- 0 TO N // Test: does the pattern match here? Matched <- TRUE FOR J <- 0 TO M IF T[I + J] != P[J] THEN Matched <- FALSE BREAK ENDIF NEXT J // Update IF Matched THEN APPEND(Answer, I) ENDIF NEXT I RETURN Answer ENDFUNCTION