简体   繁体   English

java.util.Collections.sort() 方法的时间复杂度是多少?

[英]What is the time complexity of java.util.Collections.sort() method?

I have written the following class:我写了以下课程:

public class SortingObjectsWithAngleField implements Comparator<Point> {  
    public int compare(Point p1, Point p2) {
        double delta = p1.getAngle() - p2.getAngle();
        if(delta == 0.00001)
            return 0;
        return (delta > 0.00001) ? 1 : -1;
    }
}

Then, in my main() method, I have created a List to which I add some objects which has "X" and "angle" field.然后,在我的main()方法中,我创建了一个List ,我向其中添加了一些具有“X”和“角度”字段的对象。

I then use:然后我使用:

Collections.sort(list, new SortingObjectsWithAngleField());

What is the complexity of this sort method?这种排序方法的复杂性是多少?

You could have read up the docs on Collections sort, but here it is for you:您本可以阅读有关 Collections sort 的文档,但这里是为您准备的:

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist).排序算法是经过修改的合并排序(如果低子列表中的最高元素小于高子列表中的最低元素,则忽略合并)。 This algorithm offers guaranteed n log(n) performance.该算法提供有保证的 n log(n) 性能。

<\/blockquote>

Your Comparator doesn't change this complexity, unless you do anything with loops over your collection in it, which you don't.您的 Comparator 不会改变这种复杂性,除非您对其中的集合执行任何循环操作,而您没有这样做。

"

您应该在 API 中找到它: n log(n)<\/a> 。

"

Taken from Collections.sort -取自 Collections.sort -

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist).排序算法是经过修改的合并排序(如果低子列表中的最高元素小于高子列表中的最低元素,则忽略合并)。 This algorithm offers guaranteed n*log(n) performance该算法提供有保证的 n*log(n) 性能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 竞速java.util.Collections.sort - Racing java.util.Collections.sort 在 Java 中使用 java.util.Collections.sort() 按值对 ConcurrentHashMap 进行排序时出现问题 - Problem sorting ConcurrentHashMap by values using java.util.Collections.sort() in Java java.util.HashMap 类的 keySet() 方法的时间复杂度是多少? - What is the time complexity of java.util.HashMap class' keySet() method? 这种时间复杂度是多少? Java Hashmap - What is the time complexity of this sort? Java Hashmap java.util.TreeSet的tailSet操作的时间复杂度是多少? - What is the time complexity of the tailSet operation of java.util.TreeSet? Java Collections.unmodifiableList()时间复杂度 - Java Collections.unmodifiableList() time complexity 这种排序算法的时间复杂度是多少? - What is the time complexity for this sort algorithm? Java StringBuilder.substring()方法的时间复杂度是多少? 如果它是线性的,是否有一个恒定的时间复杂度方法来获得子串? - What is the time complexity of Java StringBuilder.substring() method? If it is linear, is there a constant time complexity method to get a substring? 在Java中使用HashSets时,方法retainAll的时间和空间复杂度是多少? - What is the time and space complexity of method retainAll when used on HashSets in Java? String 类的 Java hashCode 方法的时间复杂度是多少? - What is the time complexity of Java hashCode method for the String class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM