这种排序方法的时间复杂度是多少 [英] what is the time complexity of this sort method

查看:116
本文介绍了这种排序方法的时间复杂度是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个类:

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;
    }
}

然后在我的 main ()方法我创建了一个列表,我添加了一些具有X和角度字段的对象。然后我使用

and then in my main() method I have created a List to which I add some objects which has "X" and "angle" field. And then I use

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

我想知道这种排序方法的复杂性是什么?

I want to know that what is the complexity of this sort method?

感谢

推荐答案

您可以阅读收藏集上的文档,您:

You could have read up the docs on Collections sort, but here it is for you:


排序算法是修改的
mergesort(其中合并是
,如果最高元素在
低子列表小于最低
元素在高子表中)。这个
算法提供了保证n log(n)
的性能。

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.

您的Comparator不会改变这种复杂性,除非你对你的集合中的循环做任何事情,而你不是。

Your Comparator doesn't change this complexity, unless you do anything with loops over your collection in it, which you don't.

这篇关于这种排序方法的时间复杂度是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆