What does a suffix array represent for a given string?
Think about how suffixes are organized to help with substring searches.
A suffix array stores the starting positions of all suffixes of a string sorted lexicographically. This helps in efficient substring search and pattern matching.
What is the best known time complexity for constructing a suffix array for a string of length n?
Modern algorithms can build suffix arrays very efficiently.
There exist algorithms like SA-IS that can construct suffix arrays in linear time O(n), which is optimal for this problem.
Given a suffix array for a string, how can you efficiently check if a substring exists in the string?
Think about how the suffix array is sorted and how binary search works.
Since suffixes are sorted lexicographically in the suffix array, binary search can quickly find if the substring matches the prefix of any suffix.
Which of the following is a key advantage of suffix arrays over suffix trees?
Consider memory usage and implementation complexity.
Suffix arrays are more space-efficient and simpler to implement compared to suffix trees, though suffix trees can offer faster queries in some cases.
Given a string of length n and its suffix array along with the longest common prefix (LCP) array, how can you compute the number of distinct substrings of the string?
Think about how suffixes overlap and how LCP helps avoid counting duplicates.
The total number of substrings is the sum of lengths of all suffixes. Subtracting the sum of LCP values removes duplicates counted due to common prefixes.