《算法导论》第二章

您所在的位置:网站首页 第二章思考题怎么写 《算法导论》第二章

《算法导论》第二章

2024-07-14 09:59| 来源: 网络整理| 查看: 265

(Insertion sort on small arrays in merge sort ) Although merge sort runs in Θ(nlgn) worst-case time and insertion sort runs in Θ(n2) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of length k are sorted using insertion sort and then merged using the standard merging mechanism, where k is a value to be determined. 1. Show that insertion sort can sort the n/k sublists, each of length k, in Θ(nk) worst-case time. 2. Show how to merge the sublists in Θ(nlg(n/k)) worst-case time. 3. Given that the modified algorithm runs in Θ(nk+nlg(n/k)) worst-case time, what is the largest value of k as a function of n for which the modified algorithm has the same running time as standard merge sort, in terms of Θ -notation? 4. How should we choose k in practice?



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3