I have written code to return anagrams from a list of words. I'm a newbie in time complexity analysis so pardon my ignorance if this is a blatantly obvious question. Am I right in thinking this is in O(n log n) time, since it's just performing a quicksort and the rest is done in O(1) time because it's hashmaps? Also any suggestions on improving the code?
public class anagram {
public static ArrayList<String> anagrams(String[] original) {
HashMap<String, ArrayList<String>> map = new HashMap();
for(String str : original) {
String key = sortChars(str);
if(!map.containsKey(key)) {
map.put(key, new ArrayList<String>());
}
ArrayList<String> anagramList = map.get(key);
anagramList.add(str);
}
ArrayList<String> result = new ArrayList();
for(String key : map.keySet()) {
ArrayList<String> anagramList = map.get(key);
if(anagramList.size() > 1) {
result.addAll(anagramList);
}
}
return result;
}