distinct substring

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

distinct substring

Post 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..
SilentStrike
New poster
Posts: 22
Joined: Fri Jan 04, 2002 2:00 am

Post 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
..
Post Reply

Return to “Algorithms”