I'm trying to use the bucket sort algorithm to sort strings. The task says the runtime should be about 0.05 seconds, but mine takes over 9. Why is mine taking so long, and how can I make it faster. It has about 90000 names in the file. Am I even doing the bucket sort properly?
public static void bucketSortByLength() {
String[] bucket = new String[14];
String[] insideBucket;
int index = 0;
for(int i = 0; i <= 13; i++)
bucket[i] = "";
for(int i = 0; i < numNames; i++)
bucket[names[i].length()] += names[i] + " ";
for(int i = 0; i <= 13; i++){
insideBucket = bucket[i].split("\\s+");
for(String s : insideBucket)
names[index++] = s;
}
}