Skip to content

Commit 9e78273

Browse files
feat(strings): add professional suffix array and LCP implementation
1 parent 732aaf2 commit 9e78273

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

strings/suffix_array.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
"""
23
suffix_array.py
34
@@ -14,19 +15,9 @@
1415
"""
1516

1617

18+
=======
19+
>>>>>>> c176d091 (feat(strings): add professional suffix array and LCP implementation)
1720
def 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

5849
def 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

0 commit comments

Comments
 (0)