Skip to content

Instantly share code, notes, and snippets.

@rootid
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save rootid/fef9e0ea56531b69dd6e to your computer and use it in GitHub Desktop.

Select an option

Save rootid/fef9e0ea56531b69dd6e to your computer and use it in GitHub Desktop.
//StringBuffer/StringBuilder vs String
//Linear time
public static String[] suffixArray(String s)
{
int N = s.length();
String[] suffixes = new String[N];
for (int i = 0; i < N; i++)
suffixes[i] = s.substring(i, N);
return suffixes;
}
//quadratic time and space : Need to retrive the substring and store the string to new string O(n^2)
public static String[] suffixArray(String s)
{
int N = s.length();
StringBuilder sb = new StringBuilder (s);
String[] suffixes = new String[N];
for (int i = 0; i < N; i++)
suffixes[i] = sb.substring(i, N);
return suffixes;
}
@rootid

rootid commented Apr 23, 2015

Copy link
Copy Markdown
Author

suffix array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment