3

Having string S of length n, finding the count of distinct substrings can be done in linear time using LCP array. Instead of asking for unique substrings count in whole string S, query q containing indexing (i,j) where 0 <= i <= j < n is asking for count of distinct substring inside given query range for string S[i..j].

My approach is just applying linear time construction of LCP array to each query. It gives complexity O(|q|n). Number of queries could raise to order of n so answering all queries makes it O(n^2).

Can it be done better, than linear time for every query?

In general, if one process substring of string for which we already have suffix array, suffix tree, lcp array, are those structures not relevant anymore, and must be build from scratch again?

Akhilesh
  • 51
  • 7

0 Answers0