博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Suffix array
阅读量:7133 次
发布时间:2019-06-28

本文共 1249 字,大约阅读时间需要 4 分钟。

A suffix array is a sorted array of all suffixes of a given string. The definition is similar to Suffix Tree which is compressed trie of all suffixes of the given text. Any suffix tree based algorithm can be replaced with an algorithm that uses a suffix array enhanced with additional information and solves the same problem in the same time complexity.

A suffix array can be constructed from Suffix tree by doing a DFS traversal of the suffix tree. In fact Suffix array and suffix tree both can be constructed from each other in linear time.

Advantages of suffix arrays over suffix trees include improved space requirements, simpler linear time construction algorithms (e.g., compared to Ukkonen’s algorithm) and improved cache locality.

最简单的构建方法就是把所有的后缀取出来再排序,时间复杂度是O(n^2lgn),因为每次比较都要O(n)。有了suffix array之后的查找开销需要O(mlgn),m为pattern长度,用二分查找。

当然,对于构建和查找都有线性的算法。

 有O(nlgnlgn)的构建算法,就是安前1个字符,前2个字符,前4个字符,前8个字符...一直到所有字符都排序过了。根据前$2^i$的排序结果,也就是该串中所有长度为$2^i$的子串的先后顺序都已经确定下来,所以可以在比较$2^{i+1}$长度的子串时,可以在O(1)内完成。所以每轮排序可以在O(nlgn)完成,总共有lgn轮排序,所以整个时间复杂度在O(nlgnlgn)。实现起来还是很巧妙的,没细看。

转自:http://www.geeksforgeeks.org/suffix-array-set-1-introduction/

http://www.geeksforgeeks.org/suffix-array-set-2-a-nlognlogn-algorithm/

转载于:https://www.cnblogs.com/linyx/p/4083189.html

你可能感兴趣的文章
QPM 准备优化前的思考
查看>>
From MVC to MVVM in Swift
查看>>
分布式之延时任务方案解析
查看>>
浏览器缓存机制
查看>>
LintCode 丑数
查看>>
【线上直播】Spark Streaming架构及实践
查看>>
为什么数组是对象(javascript基本数据类型)
查看>>
javax.persistence.TransactionRequiredException: Executing an update/delete query
查看>>
Set和Map数据结构。
查看>>
var,let和const深入解析(一)
查看>>
Puppeteer前端自动化测试实践
查看>>
云上中国年,阿里云CDN猪年春节高峰流量再创新高
查看>>
【Github Pages】如何被百度收录
查看>>
webstorm 不能热更新
查看>>
SAP ABAP里数据库表的Storage Parameters从哪里来的
查看>>
深入了解以太坊
查看>>
微服务应用新趋势:Service Mesh、AIOps和中台化
查看>>
前端技术周刊 2019-02-11 Serverless
查看>>
如何实现label长度固定,文字分散分布的效果
查看>>
视频去水印哪个好用,怎么一键去掉水印
查看>>