A Bit-Parallel Algorithm to Solve the κ-Nearest Neighbor String Matching Problem

The nearest neighbor string matching problem is defined as follows: We are given a text string T and a pattern string P. Our problem is to find a substring in T whose edit distance with P is the smallest among all substrings in T. This problem can be solved by the Seller’s approach which finds the substring ending at location i of T whose edit distance with P is the smallest. Of course, we may use Myers’ approach which is an improved version of Seller’s algorithm. But, this approach needs to store the entire dynamic programming matrix. To improve Myers’ approach, we proposed floating window and circular approaches. The κ-nearest neighbor string matching problem is defined as follows: Given a text string T and a pattern string P, find all substrings of T whose edit distances with P are between the smallest and the κ-th among all substrings of T. We may use Hyyro and Novarro’s approach to solve the κ-nearest neighbor string matching problem. But, their algorithm was designed with an error bound k in mind. To overcome this problem, we used again the floating window approach. Experimental results show that our algorithms are efficient. 1 Notations and Definitions In this paper, we are interested in processing strings. A string S is a sequence of characters, denoted as n s s s S L 2 1 = where each si is a character. We shall use ) , ( j i S to denote j i i s s s L 1 + . A suffix of a string n s s s L 2 1 is a substring ) , ( n i S where n i ≤ ≤ 1 . The edit distance between two strings A and B, denoted ) , ( B A ED is the smallest number of deletions, insertions and substitutions to transform A to B [5]. The nearest neighbor string matching (NNSM) problem is defined as follows: Given a text string n t t t T L 2 1 = and a pattern string m p p p P L 2 1 = , find all substrings of T whose edit distances with P are the smallest among all substrings of T. Given T = AACTCATCAA and P = ATCTCA, the nearest neighbor strings are AACTCA and ATCTA. 2 The Seller’s Algorithm NNSM problem can be solved by Seller’s Algorithm [5]. This algorithm solves the following problem: Given a text string n t t t T L 2 1 = and a pattern string m p p p P L 2 1 = , for each location i of T, for all n i ≤ ≤ 1 , find the suffix i S of ) , 1 ( i T such that ) , ( P S ED i is the smallest. Let j i S , be the suffix of ) , 1 ( i T such that )) , 1 ( , ( , j P S ED j i is the smallest for all m j ≤ ≤ 1 . To simplify the notation, let ) , ( j i c denote )) , 1 ( , ( , j P S ED j i . The Seller’s Algorithm is based upon dynamic programming [7] which can be found by the following recursive formula. ) 1 , 1 ( ) , ( − − = j i c j i c if i j t p = else )} 1 , 1 ( ), 1 , ( ), , 1 ( min{ 1 − − − − + j i c j i c j i c (1) The initial condition of recursive formula (1) is that j j c = ) , 0 ( and 0 ) 0 , ( = i c for n i ≤ ≤ 0 and m j ≤ ≤ 1 . As can be seen, the algorithm essentially produces a dynamic programming table. The following is an example of the table produced. Figure 1. A dynamic programming matrix of Seller’s algorithm with T = AACTCATCAA and P = ATCT. In the above table, we can see that for locations 4, 8 and 9 of T, there are substrings ending at these i 0