最长的共同连续子

编程入门 行业动态 更新时间:2024-10-15 22:28:24
本文介绍了最长的共同连续子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道如何找到两个序列/字符串的LCS,但LCS不征收该子必须是连续的限制。我已经试过如下:

I know how to find the lcs of two sequences/strings, but lcs doesn't impose a restriction that the subsequence needs to be consecutive. I've tried it as follows

function lccs(a, b) if a.length == 0 or b.length == 0 return "" possible = [] if a[0] == b[0] possible.push(lcs(a[1:), b[1:]) possible.push(lcs(a[1:], b)) possible.push(lcs(a, b[1:)) return longest_string(possible)

其中, longest_string 返回数组中最长的字符串,而 S [1:] 表示第一个切片,从第一个字符开始。

where longest_string returns the longest string in an array, and s[1:] means a slice of s, starting from the first character.

我内外在JavaScript的浏览器运行它,并在golang,在这里我把每个呼叫在自己的goroutine到低成本航空公司,但我不知道有关服务器的硬件规格在远程服务器上,所以我没有思想这些程序的并行化。

I've run this both inside a browser in javascript, and in golang, on a remote server where I put each call to lccs in its own goroutine, although I have no idea about the server's hardware specs, so I have no idea of the parallelization of these routines.

在这两种情况下,我需要的方式运行太慢。有没有一种方法,以加快这?

In both these cases, in ran way too slowly for my needs. Is there a way to speed this up?

推荐答案

我认为,基本的想法是使用动态规划。这样的事情:

I believe that the basic idea would be to use dynamic programming. something like that:

for i in 1:length(a) { for j in 1:length(b) { if (a[i]==b[j]) then { result[i,j] = result[i-1,j-1]+1 #remember to initialize the borders with zeros # track the maximum of the matrix } else { result[i,j]=0 } } }

此问题是基本上similra到序列比对的上下文中,生物信息学中常用的。其实,你应该能够使用现有的序列比对算法为你的目的(如爆炸等),通过设置差距的处罚,以非常高的价值,几乎不允许空白对准

this question is basically similra to the context of sequence alignment, common in bioinformatics. in fact, you should be able to use existing sequence alignment algorithms for your purpose (such as blast, etc.) by setting the "gap" penalties to very high values, practically disallowing gaps in the alignment

更多推荐

最长的共同连续子

本文发布于:2023-11-29 19:56:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最长

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!