Modification to merge sort to implement merge sort with insertion sort Java

一笑奈何 提交于 2019-12-13 02:51:32

问题


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. 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. This is a conceptual exercise by myself for myself. Code and or an explanation is appreciated.


回答1:


Your n/k-way merge is O(n^2/k) (explanation here). Each of your individual insertion sorts are O(k^2). Observe that for any value of k, your overall running complexity will remain O(n^2); therefore, no value of k will allow your modified merge sort to be O(nlogn)



来源:https://stackoverflow.com/questions/19533057/modification-to-merge-sort-to-implement-merge-sort-with-insertion-sort-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!