Skip to content

Commit 5efbf11

Browse files
authored
Merge pull request #1192 from mhayter/patch-6
Update suffix-automaton.md - No definition of answer(P)
2 parents 86b1324 + 9053635 commit 5efbf11

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/string/suffix-automaton.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ In other words we need to find all the states that can reach the state $t$ via s
651651
Therefore to solve the problem we need to save for each state a list of suffix references leading to it.
652652
The answer to the query then will then contain all $firstpos$ for each state that we can find on a DFS / BFS starting from the state $t$ using only the suffix references.
653653

654-
This workaround will work in time $O(answer(P))$, because we will not visit a state twice (because only one suffix link leaves each state, so there cannot be two different paths leading to the same state).
654+
Overall, this requires $O(length (T))$ for preprocessing and $O(length(P) + answer(P))$ for each request, where $answer(P)$ — this is the size of the answer.
655+
656+
First, we walk down the automaton for each character in the pattern to find our starting node requiring $O(length(P))$. Then, we use our workaround which will work in time $O(answer(P))$, because we will not visit a state twice (because only one suffix link leaves each state, so there cannot be two different paths leading to the same state).
655657

656658
We only must take into account that two different states can have the same $firstpos$ value.
657659
This happens if one state was obtained by cloning another.

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