If I want to find the longest common substring for 2 strings then which approach will be more efficient in terms of time/space complexity: using suffix arrays of DP?
DP will incur O(m*n) space with O(m*n) time complexity, what will be the time complexity of the suffix array approach?
1) Calculate the suffixes O(m) + O(n) 2) Sort them O(m+n log2(m+n)) 3) Finding longest common prefix for m+n-1 strings? [I'm not sure how to calculate #of comparisons]
Suffix arrays allow us to do many more things with the sub-strings (like search for sub-string etc.), but since in this case rest of the functions are not needed, will DP be considered an easier/cleaner approach?Which one should be used in the case where we are comparing 2 strings?
Also, what if we have more than 2 strings?