Generate all unique substrings for given string
Posted
by Yuval A
on Stack Overflow
See other posts from Stack Overflow
or by Yuval A
Published on 2010-04-01T12:28:07Z
Indexed on
2010/04/01
12:43 UTC
Read the original article
Hit count: 370
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?
(this is technically homework, so pointers-only are welcome as well)
© Stack Overflow or respective owner