Skip to content

Commit 4a11133

Browse files
authored
Quick edit + partially addressing Issue #924.
Change minlength(v) to minlen(v) for consistency. Issue #924 improvement. Will complete after feedback!
1 parent 1fc0972 commit 4a11133

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/string/suffix-automaton.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Before proceeding to the algorithm itself, we recap the accumulated knowledge, a
193193
- For each state $v$ one or multiple substrings match.
194194
We denote by $longest(v)$ the longest such string, and through $len(v)$ its length.
195195
We denote by $shortest(v)$ the shortest such substring, and its length with $minlen(v)$.
196-
Then all the strings corresponding to this state are different suffixes of the string $longest(v)$ and have all possible lengths in the interval $[minlength(v); len(v)]$.
196+
Then all the strings corresponding to this state are different suffixes of the string $longest(v)$ and have all possible lengths in the interval $[minlen(v); len(v)]$.
197197
- For each state $v \ne t_0$ a suffix link is defined as a link, that leads to a state that corresponds to the suffix of the string $longest(v)$ of length $minlen(v) - 1$.
198198
The suffix links form a tree with the root in $t_0$, and at the same time this tree forms an inclusion relationship between the sets $endpos$.
199199
- We can express $minlen(v)$ for $v \ne t_0$ using the suffix link $link(v)$ as:
@@ -494,6 +494,21 @@ The number of different substrings is the value $d[t_0] - 1$ (since we don't cou
494494
495495
Total time complexity: $O(length(S))$
496496
497+
498+
Alternatively, we can take advantage of the fact that each state $v$ matches to substrings of length $[minlen(v),len(v)]$.
499+
Therefore, given $minlen(v) = 1 + len(link(v))$, we have total distinct substrings at state $v$ being $len(v) - minlen(v) + 1 = len(v) - 1 + len(link(v)) + 1 = len(v) - len(link(v))$.
500+
501+
This is demonstrated succinctly below:
502+
503+
```cpp
504+
long long tot{};
505+
for(int i=1;i<sz;i++) {
506+
tot+=len[i] - len[link[i]];
507+
}
508+
```
509+
510+
While this is also $O(length(S))$, it requires no extra space besides (what's used for the suffix automaton construction) and no recursive calls, consequently running faster in practice.
511+
497512
### Total length of all different substrings
498513

499514
Given a string $S$.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy