COMPUTE-SUFFIX-ARRAY'(T, n) allocate arrays substr-rank[1:n], rank[1:n], and SA[1:n] for i = 1 to n substr-rank[i].left-rank = ord(T[i]) if i < n substr-rank[i].right-rank = ord(T[i + 1]) else substr-rank[i].right-rank = 0 substr-rank[i].index = i sort the array substr-rank into monotonically increasing order based on the left-rank attributes, using the right-rank attributes to break ties; if still a tie, the order does not matter l = 2 while l < n MAKE-RANKS(substr-rank, rank, n) for i = 1 to n substr-rank[i].left-rank = rank[i] if i + l ≤ n substr-rank[i].right-rank = rank[i + l] else substr-rank[i].right-rank = 0 substr-rank[i].index = i sort the array substr-rank into monotonically increasing order based on the left-rank attributes, using the right-rank attributes to break ties; if still a tie, the order does not matter l = 2 * l for i = 1 to n SA[i] = substr-rank[i].index return SA
LONGEST-COMMON-SUBSTRINGS(T1, T2, n1, n2) T = T1 @ T2 n = n1 + n2 + 1 SA = COMPUTE-SUFFIX-ARRAY(T, n) LCP = COMPUTE-LCP(T, SA, n) len = 0 S = ∅ for i = 2 to n l = SA[i - 1] r = SA[i] if min{l, r} <= n1 and max(l, r) > n1 + 1 if LCP[i] > len len = LCP[i] S = {min{l, r}} else if lCP[i] == len S = S ∪ {min{l, r}} let string-list be a new array for l in S INSERT(string-list, T1[l : l + len - 1]) return string-list