File tree Expand file tree Collapse file tree 1 file changed +3
-25
lines changed
Expand file tree Collapse file tree 1 file changed +3
-25
lines changed Original file line number Diff line number Diff line change 1+ < << << << HEAD
12"""
23suffix_array.py
34
1415"""
1516
1617
18+ == == == =
19+ >> >> >> > c176d091 (feat (strings ): add professional suffix array and LCP implementation )
1720def build_suffix_array (s : str ) -> list [int ]:
18- """
19- Builds the suffix array of the given string using the doubling algorithm.
20-
21- Parameters:
22- s (str): Input string
23-
24- Returns:
25- list[int]: List of starting indices of suffixes in sorted order
26-
27- Complexity:
28- O(n log n) time and O(n) space.
29- """
3021 # Append a sentinel that is lexicographically smaller than all other characters
3122 s += "\0 "
3223 n = len (s )
@@ -56,19 +47,6 @@ def build_suffix_array(s: str) -> list[int]:
5647
5748
5849def build_lcp_array (s : str , sa : list [int ]) -> list [int ]:
59- """
60- Builds the LCP (Longest Common Prefix) array using Kasai's algorithm.
61-
62- Parameters:
63- s (str): Original string
64- sa (list[int]): Suffix array of s
65-
66- Returns:
67- list[int]: LCP array where lcp[i] = LCP(sa[i], sa[i-1])
68-
69- Complexity:
70- O(n) time and O(n) space.
71- """
7250 n = len (sa )
7351 # Inverse of suffix array: pos[i] gives rank of suffix at i
7452 pos = [0 ] * n
You can’t perform that action at this time.
0 commit comments