The naive algorithm for generating all unique substrings involves traversing all the string from 1..n
, thus takes $\mathcal{O}(n^2)$, but it also involves maintaining a list for all generated substring to check everytime for repetitions.
So the total time can't be $\mathcal{O}(n^2)$, since there is an added checking of uniqueness, which means that I have to maintain a list of all previous generated substrings.
So how is it correct that when it is said that the algorithm takes only $\mathcal{O}(n^2)$ time.
There is obviously an added cost at each substring generation.
The actual time complexity should be as pointed out by Raphael should be something like the following -:
$\mathcal{O}(n^2) + (\mathcal{O}(m^2) * \mathcal{O}(n)))$
where $m$ is the total number of substrings generated $n(n+1)/2$, and the time to compare 2 different strings is the smaller length between two strings, assuming the strings are being compared character by character.
Now if the above is correct then what I am confused about is should it be plus or a multiply with the comparision cost.