Last active
August 29, 2015 14:19
-
-
Save rootid/fef9e0ea56531b69dd6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
suffix array