TCS Journal 1989 Journal Article
- Zvi Galil
- Raffaele Giancarlo
Consider the problem of computing E[j]= min 0⩽k⩽j−1 {D[k]+w(k, j)}, j=1, …, n, where w is a given weight function, D[0] is given and for every k=1, …, n, D[k] is easily computable from E[k]. This problem appears as a subproblem in dynamic programming solutions to various problems. Obviously, it can be solved in time O(n 2), and for a general weight function no better algorithm is possible. We consider two dual cases that arise in applications: In the concave case, the weight function satisfies the quadrangle inequality: w(k, j)+w(l, j′)⩽w(l, j)+w(k, j′) for all k⩽l⩽j⩽j′. In the convex case, the weight function satisfies the inverse quadrangle inequality. In both cases we show how to use the assumed property of w to derive an O(n log n) algorithm. Even better, linear-time algorithms are obtained if w satisfies the following additional closest zero property: for every two integers l and k, l<k, and real number a, the smallest zero of f(x)=w(l, x)−w(k, x)−a which is larger than k can be found in constant time. The two algorithms speed up several dynamic programming routines that solve as a subproblem the problem above. The speed-up is from O(n 3) to O(n 2log n) or O(n 2). Applications include algorithms for comparing DNA sequences and algorithms used in speech recognition and geology. One typical problem is the following: given the cost of substituting any pair of symbols and a convex cost function g for gaps (where g(r) is the cost of a gap of size r), compute the modified edit distance between the two given sequences.