首先定义了suffix string 或者说suffix arrary
如果有个数组是 int[] text = {10, 20, 30, 25}
那么 suffix[0] = {10, 20, 30, 25}
suffix[1] = {20, 30, 25}
suffix[2] = {30, 25}
suffix[3] = {25}
如果对这些数组进行lexical order 的排序,我们可以得到
suffix[0] < suffix[1] < suffix[3] < suffix[2]
问题是:
input: int[] text
output: int[] suffix_array_order
e.g.
input: int[] text = {10, 20, 30, 25}
output: int[] suffix_array_order = {0, 1, 3, 2}
Solution:
注意: Arrays.sort(T[], Comparator)只能用于排序对象数组,不能用于排序int, long之类的原始值数组!
public Integer[] suffixArrayOrder(int[] A) { int n = A.length; Integer[] order = new Integer[n]; for(int i=0; i<n; i++) { order[i] = i; } Arrays.sort(order, new Comparator<Integer>(){ @Override public int compare(Integer o1, Integer o2) { int res = A[o1] - A[o2]; while(res == 0 && o1 < n && o2 < n) { res = A[o1++] - A[o2++]; } return res; } }); System.out.println(Arrays.toString(order)); return order; }
第二题: input: int[] text, int[] subText
output: boolean isExist;
检查text数组中有没有一个subarray 是subText。要求时间小于O(N^2), N == text.length;
这里假设我们有了第一题的 suffix_array_order.
(做法是binary search)
这个没看懂,不知道怎么写。
原文见:
相关推荐
matlab开发-SuffixArray。目的是说明后缀数组的计算。这不包括搜索操作。
matlab开发-SuffixArray.zip.zip
Algorithm-Ukkonen-s-Suffix-Tree-Algorithm.zip,ukkonen的后缀树算法,一个用python实现的完整版本,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
#Compressed-Suffix-Array(CSA) ##它是什么? CSA是一种简洁的数据结构(SDS),SDS可以隐式地表示一个对象,并且在接近对象信息论下界的空间中有效地支持对原始对象的操作。 CSA是SA(suffix-array)的隐式表达,...
我们已经将项目移至github。 https://github.com/saaddan/Compressed-Enhanced-Suffix-Array
SuffixArray 扩展(以单词为单位) 源码
A suffix array represents the suffixes of a string in sorted order. Being a simpler and more compact alternative to suffix trees, it is an important tool for full text indexing and other string ...
Two Efficient Algorithms for Linear Suffix Array Construction 生物信息论文
Prefix-Suffix Palindrome (Easy version) D2. Prefix-Suffix Palindrome (Hard version) 题意: 对于给出的字符串,可截取其前缀和后缀,求能组成的最长回文串。 思路: 正常来说暴力的思路是先匹配前缀pre和后缀...
讲解后缀数组的论文,不是国家集训队论文。是国外论文
中缀表达式转换为后缀表达式,并且求取表达式值,而且能够输出表达式
公共后缀一个存储库,为PyFunceble项目分发更新版本的public-suffix.json 。执照MIT LicenseCopyright (c) 2019, 2020, 2021 PyFuncebleCopyright (c) 2017, 2018, 2019, 2020, 2021 Nissar ChababyPermission is ...
后缀数组(Suffix Array)标程。采用DA算法。RMQ预处理询问。
Describing and testing two new linear Suffix Array Construction Algorithms 生物信息论文
后缀阵列和 LCP 后缀数组和最长公共前缀注意:我们保证每条线的长度相等。 给定 k = 2, 3, ..., 10 的字符串 find,出现 k 次的最长字符串是什么? 注意:如果输入是aaaaa,出现两次的最长字符串是aaaa 例如,如果这...
Prefix-Suffix Palindrome (Easy version) D2. Prefix-Suffix Palindrome (Hard version) 题意: 对于给出的字符串,可截取其前缀和后缀,求能组成的最长回文串。 思路: 正常来说暴力的思路是先匹配前缀pre和后缀...
The C-suffix devices are characterized for operation from 0C to 70C. The I-suffix devices are characterized for operation from − 40C to 85C. The Q-suffix devices are characterized for ...
...关于string的小结 kmp extend_kmp ac+trie 后缀数组
turkish-suffix-library 使用 名词 from turkish_suffix_library.turkish import Turkish print(Turkish('araba').dative()) print(Turkish('sebep').ablative()) print(Turkish('sebep').accusative()) print...
eScholarship provides open access, scholarly publishing services to the University of California and delivers a dynamic research platform to scholars worldwide.Previously Published Works ...