哪个排序算法是最适合进行重新排序几乎完全排序列表?

编程入门 行业动态 更新时间:2024-10-26 19:25:36
本文介绍了哪个排序算法是最适合进行重新排序几乎完全排序列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已存储了由特定的比较函数的字符串列表。

I have a list of strings which has been sorted by a specific comparison function.

现在我不得不重新排序使用的不同的的比较函数列表中。

Now I have to re-sort this list using a different comparison function.

这个新的比较功能,例如比较某些特殊字符时,像变音符号表现略有不同。在大多数情况下,元素已被移动一个或两个时隙到达正确的位置。

This new comparison function behaves slightly different when comparing certain special characters, like Umlauts for example. In most cases the element has to be moved just one or two slots to get to the correct position.

哪个排序算法是最适合重新梳理这几乎完全分类列表中运行时执行速度方面?

Which sorting algorithm is best suited to re-sort this almost fully sorted list in terms of runtime execution speed?

推荐答案

插入排序小效果很好或近排序的列表。

Insertion sort works well on small or nearly sorted lists.

从这个 ACM纸:

这是随机生成的列表测试   列表长度的各种组合   和小有序性比率指示   该直插入排序就是最好的   对于小型或非常接近排序的列表   那Quickersort是最好的   并非如此。

Tests on randomly generated lists of various combinations of list length and small sortedness ratios indicate that Straight Insertion Sort is best for small or very nearly sorted lists and that Quickersort is best otherwise.

从wiki文章插入排序:

如果输入数组已经排序,   插入排序进行尽可能少的为N-1   比较,从而使插入   鉴于排序时,排序更有效   或近排序的阵列。

If the input array is already sorted, insertion sort performs as few as n-1 comparisons, thus making insertion sort more efficient when given sorted or "nearly-sorted" arrays.

SO问题:Is有过一个很好的理由来使用插入排序?

更多推荐

哪个排序算法是最适合进行重新排序几乎完全排序列表?

本文发布于:2023-11-29 18:18:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最适合   算法   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!