java - Collections.sort的BigO是什么?

标签 java algorithm sorting data-structures big-o

<分区>

我在两个列表上使用 collections.sort 来按字母顺序排列它们。 我把它放在一个函数中,我正在尝试确定它的 BigO

所以我想知道 Collections.sort(list) 的 BigO

    List list1 = new LinkedList();
    List list2 = new LinkedList();


    for(int i = 0; i < x.length(); i++){
        list1.add(x.charAt(i));
    }

    for (int i = 0; i < y.length(); i++){
        list2.add(y.charAt(i));
    }
    System.out.println(list1);
    Collections.sort(list1);
    System.out.println(list1);

    System.out.println(list2);
    Collections.sort(list2);

BigO 到底是什么? O(nlogn)?

最佳答案

引用javadoc :

Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.

关于java - Collections.sort的BigO是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25830497/

相关文章:

java多线程交通信号示例

javascript - 数据过滤算法

python - 在保持最小频率的同时减小集合大小

r - 尝试在 R 中运行 kNN 时,我收到由 coercionNAs 引入的错误 NAs?

java - List 的 removeIf() 未按预期工作

java - hibernate "No default constructor for entity"使用 @Data 注释创建

algorithm - 算法介绍 CLRS 插入排序 非递增

C:列表排序代码不起作用

java - Android 从抽屉导航上的 ActionLayout 获取开关

jquery - DataTable jquery - 如何从第一列中删除排序图标?