Reputation: 19
I was wondering what is the time complexity of this sorting algorithm that sorts a hashmap.
private HashMap<Pair<T,T>,Double> sortMapOfEdges(HashMap<Pair<T,T>,Double> mapOfEdges){
HashMap<Pair<T,T>, Double> sortedMapOfEdges =
mapOfEdges.entrySet().stream()
.sorted(Entry.comparingByValue())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue,
(e1, e2) -> e1, LinkedHashMap::new));
return sortedMapOfEdges;
}
Thank you.
Upvotes: 1
Views: 647
Reputation: 989
The only sorting done here is done by the line
.sorted(Entry.comparingByValue())
So the real question here is what is the runtime of a stream's .sorted
method. This I believe will depend on some internal details, but generally these built-in sort methods are near-optimal, so my guess would be O(n*log(n)).
Upvotes: 1