发现没有后缀树和O(n)的字典序最小的串旋转

编程入门 行业动态 更新时间:2024-10-10 04:25:44
本文介绍了发现没有后缀树和O(n)的字典序最小的串旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何找到该指数在一个圆形阵列,这样即形成从该指数开始字符串是第一个在字典顺序。

how to find the index in an circular array such that the string that is formed starting from that index is first in lexicographic order.

有关例如:在圆阵ABCDEABCCDE 答案是6,因为从第六位元素的起始圆形串是第一位从圆形阵列的所有可能的字符串形成的字典。

For Ex : in the circular array ABCDEABCCDE The answer is 6 because the circular string starting from the element A in the 6th position comes first in the dictionary formed from all the possible strings of the circular array.

推荐答案

理论:如果有K出现在长度为N的序列的字母X的,至少有两次出现的X,使得它们之间的距离小于N / K

Theory A: If there are K occurrences of a letter X in a sequence of length N, there are at least two occurrences of X such that the distance between them is less than N/K.

查找最小信件并安排指向其所有出现在排序列表。叫它。

Find the min letter and arrange pointers to all of its occurrences in a sorted list. Call it A.

有关一个给定的R,找到的字母分钟A [1] + R,并过滤掉所有的量元件在A [1] + r为不等于min的指针。同时过滤掉所有的指针进行的研究[J],使得A [D] = A [I] + R一段我。

For a given r, find min of letters at A[i]+r, and filter out all the pointers for which element at A[i]+r is not equal to min. Also filter out all the pointers A[j] such that A[j]=A[i]+r for some i.

您就要跑最多N / K倍以上声明,并在每次运行将花费最多O(K)的时间。因此,这种算法的复杂度为O(N)的

You will have to run the above statement at most N/K times and each run would cost at most O(K) time. Therefore, the complexity of this algorithm is O(N).

更详细的算法: 假设Z是圆形的名单,我们正在处理。

More detailed algorithm: Assume Z is the circular list we are dealing with.

def filter(A,Z,r): t = min( Z[A[i]+r] ) forall i remove A[i] if Z[A[i]+r]!=t forall i rmflag = [false if A[i]==A[j]+r else false for i in range(len(A)] //NOTE: This step can be done in O(len(A)) time since A is sorted remove A[i] if rmflag[i]

更多推荐

发现没有后缀树和O(n)的字典序最小的串旋转

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

发布评论

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

>www.elefans.com

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