halkujabra
halkujabra

Reputation: 2942

unique substrings using suffix tree

For a given string S of length n-

The suffix tree for S can be created in O(n) time. Now, my question is-

How can we use the suffix tree for S to get all the unique substrings of S in O(n^2)?

Upvotes: 1

Views: 2046

Answers (2)

halkujabra
halkujabra

Reputation: 2942

It can be done optimally through tries. Add the strings to trie and traverse from root to node. Each root to node path will denote suffixes of a string. Take all the prefixes of these suffixes. These are the unique substrings.

Upvotes: 1

Frank59
Frank59

Reputation: 3261

Try to read about suffix arrays: http://en.wikipedia.org/wiki/Suffix_array This method is faster than suffix tree for getting substrings in string.

Upvotes: 2

Related Questions