A Linear Space Algorithm for Computing Maximal Common Subsequences

A Linear Space Algorithm for Computing Maximal Common Subsequences

June 1975 | D.S. Hirschberg
This paper presents a linear space algorithm for computing maximal common subsequences of two strings. The problem of finding the longest common subsequence (LCS) of two strings has been solved in quadratic time and space. The proposed algorithm solves the problem in quadratic time and linear space. The algorithm is based on dynamic programming. It uses a matrix L(i,j) to store the maximum length of a common subsequence of the first i characters of string A and the first j characters of string B. The algorithm uses two passes to compute the matrix, reducing the space complexity from O(mn) to O(m + n). The algorithm is divided into three parts: Algorithm A computes the matrix L(i,j), Algorithm B computes the matrix using only one row of memory, and Algorithm C recursively divides the problem into smaller subproblems until a trivial problem is reached. Algorithm C uses the results from Algorithm B to find the maximal common subsequence. The paper also presents a theorem that allows the maximal common subsequence to be found by combining the results of two subproblems. This theorem is used in Algorithm C to divide the problem into two smaller subproblems. The algorithm has a time complexity of O(mn) and a space complexity of O(m + n). The paper also discusses the possibility of modifying the algorithm to find the edit distance between two strings.This paper presents a linear space algorithm for computing maximal common subsequences of two strings. The problem of finding the longest common subsequence (LCS) of two strings has been solved in quadratic time and space. The proposed algorithm solves the problem in quadratic time and linear space. The algorithm is based on dynamic programming. It uses a matrix L(i,j) to store the maximum length of a common subsequence of the first i characters of string A and the first j characters of string B. The algorithm uses two passes to compute the matrix, reducing the space complexity from O(mn) to O(m + n). The algorithm is divided into three parts: Algorithm A computes the matrix L(i,j), Algorithm B computes the matrix using only one row of memory, and Algorithm C recursively divides the problem into smaller subproblems until a trivial problem is reached. Algorithm C uses the results from Algorithm B to find the maximal common subsequence. The paper also presents a theorem that allows the maximal common subsequence to be found by combining the results of two subproblems. This theorem is used in Algorithm C to divide the problem into two smaller subproblems. The algorithm has a time complexity of O(mn) and a space complexity of O(m + n). The paper also discusses the possibility of modifying the algorithm to find the edit distance between two strings.
Reach us at info@study.space
Understanding A linear space algorithm for computing maximal common subsequences