Optimal on-line search and sublinear time update in string matching