Page 1 of 1

distinct substring

Posted: Fri Aug 18, 2006 5:52 pm
by yogeshgo05
hi i think this is bytecode 06 problem..
i getting sol for this O(n^3),i heard that we hav sol in method called
suffix array ,i didn't understand how to get O(n^2) using this method
could somebody plz tell me how..

Posted: Fri Aug 18, 2006 10:29 pm
by SilentStrike
Is the problem just count the number of distinct substrings?

I don't know about suffix arrays, but I do know an O(n^2) solution using tries. You can put each subsring in a trie in O(n^2) time. As you are building the trie, you can count new substrings.

For example, ABABACA

insert A
insert AB [keep pointer to A]
insert ABA [keep pointer to AB]
insert ABAB [keep pointer to ABA]
...
insert ABABACA

insert B
insert BA
..