gpt4 book ai didi

algorithm - Ukkonen 的后缀树算法 : procedure 'test and split' unclear

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:21:03 26 4
gpt4 key购买 nike

ukkonen's on line construction algorithm

我在尝试理解“测试和拆分”过程时遇到了问题,具体如下:程序 test–and–split(s, (k, p), t):

>1. if k ≤ p then
>2. let g'(s,(k',p'))=s' be the tk-transition from s
>3. if t=t(k'+p-k+1) then return (true,s)

我的问题是,第二行到底是什么意思,如果 g'(s,(k',p')) 从 s 开始然后是 t(k') 而不是,它怎么可能仍然是一个 tk-transition的 t(k)??

最佳答案

可能你已经弄明白了,你不再需要答案了,但由于我在试图理解它时遇到了同样的问题,也许它将来对其他人有用,我认为的答案是下面的。

Ukkonen's on line construction algorithm ,在第 7 页,您可以阅读到:

...
The string w spelled out by the transition path in STrie(T) between two explicit states s and r is represented in STree(T) as generalized transition g′(s,w) = r. To save space the string w is actually represented as a pair (k,p) of pointers (the left pointer k and the right pointer p) to T such that tk . . . tp = w. In this way the generalized transition gets form g′(s, (k, p)) = r.
Such pointers exist because there must be a suffix Ti such that the transition path for Ti in STrie(T) goes through s and r. We could select the smallest such i, and let k and p point to the substring of this Ti that is spelled out by the transition path from s to r. A transition g′(s, (k, p)) = r is called an a–transition if tk = a. Each s can have at most one a–transition for each a ∈ Σ.
...

这意味着我们正在寻找满足 tk 的最小索引 kp 。 . . tp = w T
=> 如果 Tw 出现不止一次,对于 kp 我们总是引用第一个。

现在,程序 test–and–split(s,(k,p),t) 测试是否具有规范引用对的状态 (s,(k,p) ) 是端点,也就是说,在 STrie(T i−1) 中的状态将有一个 ti – 过渡。符号 ti 作为输入参数 t 给出。

算法的第一行如下:

   procedure test–and–split(s,(k,p),t):
1. if k ≤ p then
2. let g′(s,(k′,p′)) = s′ be the t(k)–transition from s;
3. if t = t(k′+p−k+1) then return(true,s)
4. else ...

在第 1 行,我们检查状态是否是隐式的(即 k <= p 时)。

如果是这样,那么在第 2 行我们要找到从 s 开始的转换,该转换以我们在 Tk 位置找到的字符开始>(即 tk)。请注意,tk 必须等于 tk' 但索引 kk' 可以不同,因为我们总是指向字符串 wT 中的第一次出现(还请记住,从一个状态可以有最多有一个以字符 tk => 开头的转换,所以这是正确的,也是唯一的)。

然后在第 3 行,我们检查规范引用对 (s,(k,p)) 引用的状态是否为端点,即它是否具有 ti - 过渡。状态 (s,(k,p)) 是我们可以从状态 s 到达的状态(隐式或非隐式),紧随 t k' -transition(即 tk-transition 因为 k' = k)对于 (p - k) 个字符。这解释了 tk′+p−k+1,其中 +1 代表下一个字符,即我们要检查的字符如果它等于 t(其中 t = ti)。在那种情况下,我们到达终点并返回 true。

否则,从第 4 行开始,我们拆分转换 g′(s,(k′,p′)) = s′ 以明确状态 (s,(k ,p)) 并返回新的显式状态。

关于algorithm - Ukkonen 的后缀树算法 : procedure 'test and split' unclear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29897491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com