string-to-string correction problem
In computer science, the string-to-string correction problem refers to determining the minimum cost sequence of edit operations necessary to change one string into another (i.e., computing the shortest edit distance). Each type of edit operation has its own cost value.{{cite journal |first1=Robert A. |last1=Wagner |first2=Michael J. |last2=Fischer |author2-link=Michael J. Fischer |title=The String-to-String Correction Problem |journal=Journal of the ACM |volume=21 |issue=1 |year=1974 |pages=168–173 |doi= 10.1145/321796.321811|s2cid=13381535 |doi-access=free }} A single edit operation may be changing a single symbol of the string into another (cost WC), deleting a symbol (cost WD), or inserting a new symbol (cost WI).{{cite journal |last1=Lowrance |first1=Roy |last2=Wagner |first2=Robert A. |title=An Extension of the String-to-String Correction Problem |journal=Journal of the ACM |date=April 1975 |volume=22 |issue=2 |pages=177–183 |doi=10.1145/321879.321880 |s2cid=18892193 |doi-access=free }}
If all edit operations have the same unit costs (WC = WD = WI = 1) the problem is the same as computing the Levenshtein distance of two strings.
Several algorithms exist to provide an efficient way to determine string distance and specify the minimum number of transformation operations required.Edit distance#Computation{{cite journal |first=Walter F. |last=Tichy |title=The string-to-string correction problem with block moves |journal=ACM Transactions on Computer Systems |volume=2 |issue=4 |year=1984 |pages=309–321 |doi= 10.1145/357401.357404|s2cid=14034845 |url=http://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1377&context=cstech |doi-access=free }} Such algorithms are particularly useful for delta creation operations where something is stored as a set of differences relative to a base version. This allows several versions of a single object to be stored much more efficiently than storing them separately. This holds true even for single versions of several objects if they do not differ greatly, or anything in between.
Notably, such difference algorithms are used in molecular biology to provide some measure of kinship between different kinds of organisms based on the similarities of their macromolecules (such as proteins or DNA).
Extension
The extended variant of the problem includes a new type of edit operation: swapping any two adjacent symbols, with a cost of WS.
This version can be solved in polynomial time under certain restrictions on edit operation costs.{{cite book |last1=Wagner |first1=Robert A. |title=Proceedings of seventh annual ACM symposium on Theory of computing - STOC '75 |chapter=On the complexity of the Extended String-to-String Correction Problem |date=May 1975 |pages=218–223 |doi=10.1145/800116.803771 |isbn=9781450374194 |s2cid=18705107 |chapter-url=https://dl.acm.org/doi/10.1145/800116.803771}}
Robert A. Wagner (1975) showed that the general problem is NP-complete. In particular, he proved that when WI < WC = WD = ∞ and 0 < WS < ∞ (or equivalently, changing and deletion are not permitted), the problem is NP-complete.