简体   繁体   中英

What is the time complexity of this sort? Java Hashmap

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.

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)).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM