简体   繁体   English

修改合并排序以使用插入排序Java实现合并排序

[英]Modification to merge sort to implement merge sort with insertion sort Java

I want to implement a modification to merge sort, where n/k sublists of length k are sorted using insertion sort and then merged using the standard merging mechanism of merg sort. 我想实现一种修改以合并排序,其中使用插入排序对长度为k的n / k个子列表进行排序,然后使用merg排序的标准合并机制进行合并。 I'm wondering what the value k has to equal for the modified version of merge sort to equal the original version of merge sort in terms of rum time complexity. 我想知道在朗姆酒时间复杂度方面,合并排序的修改版本等于合并排序的原始版本的值k必须等于什么。 This is a conceptual exercise by myself for myself. 这是我自己的概念性练习。 Code and or an explanation is appreciated. 感激代码和/或解释。

Your n/k-way merge is O(n^2/k) (explanation here ). 您的n / k路合并为O(n ^ 2 / k)( 在此说明)。 Each of your individual insertion sorts are O(k^2). 您的每种插入类型均为O(k ^ 2)。 Observe that for any value of k, your overall running complexity will remain O(n^2); 观察到,对于任何k值,您的总体运行复杂度将保持O(n ^ 2); therefore, no value of k will allow your modified merge sort to be O(nlogn) 因此,k的任何值都不允许修改后的合并排序为O(nlogn)

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

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