最长共同连续子 - 算法 [英] Longest common contiguous subsequence - algorithm

查看:174
本文介绍了最长共同连续子 - 算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:是否有一个O(n)的算法寻找两个序列A和B之间的最长连续子?我搜索,但所有的结果都对濒海战斗舰的问题,这不是我所追求的。

注意:的,如果你愿意给任何样品code,你非常欢迎这样做,但请,如果可以的话,用C或C ++

编辑:的下面是一个例子:

  A:{A,B,A,B,B,B,A}
B:{A,D,B,B,B,C,N}
最长公共连续子:{B,B,B}
 

解决方案

是的,你可以在线性时间内做到这一点。一种方法是通过构建后缀树同时为图案和文字和计算它们的交点。我不能想办法做到这一点,而不涉及后缀树或后缀数组,虽然。

My question is simple: Is there an O(n) algorithm for finding the longest contiguous subsequence between two sequences A and B? I searched it, but all the results were about the LCS problem, which is not what I'm seeking.

Note: if you are willing to give any sample code, you are more than welcome to do so, but please, if you can, in C or C++.

Edit: Here is an example:

A: { a, b, a, b, b, b, a }
B: { a, d, b, b, b, c, n }
longest common contiguous subsequence: { b, b, b }

解决方案

Yes, you can do this in linear time. One way is by building suffix trees for both the pattern and the text and computing their intersection. I can't think of a way to do this without involving suffix trees or suffix arrays, though.

这篇关于最长共同连续子 - 算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆