longest common subsequence with linear memory usage [closed]

雨燕双飞 提交于 2019-12-12 06:48:12

问题


I'm trying to find an algorithm which uses linear space of memory for:

Given two strings x and y over an arbitrary alphabet, determine their longest common sub sequence.


回答1:


Note that when you're calculating the next row of the table in the dynamic programming solution to solve the LCS problem, you only need the previous row and your current row. Then you can modify the dynamic programming solution to keep track of only the previous row and the current row instead of the m x n table. Every time you reach the end of the current row, you set the previous row to the current row, and start from the beginning of the row again. You do this m times where m is the number of rows in your table. This will use space linear in the number of columns.



来源:https://stackoverflow.com/questions/16556815/longest-common-subsequence-with-linear-memory-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!