Asked • 05/13/19

Generate all unique substrings for given string?

Given a string `s`, what is the fastest method to generate a set of all its unique substrings? Example: for `str = "aba"` we would get `substrs={"a", "b", "ab", "ba", "aba"}`.The naive algorithm would be to traverse the entire string generating substrings in length `1..n` in each iteration, yielding an `O(n^2)` upper bound. Is a better bound possible?

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.