最长共同连续子

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

我的问题很简单:是否有一个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.

更多推荐

最长共同连续子

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

发布评论

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

>www.elefans.com

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