Jas*_*ker 45 language-agnostic sorting algorithm bubble-sort
泡泡种类有任何现实世界的用途吗?每当我看到一个提到的,它总是要么:
Jer*_*fin 75
Bubble sort is (provably) the fastest sort available under a very specific circumstance. It originally became well known primarily because it was one of the first algorithms (of any kind) that was rigorously analyzed, and the proof was found that it was optimal under its limited circumstance.
Consider a file stored on a tape drive, and so little random access memory (or such large keys) that you can only load two records into memory at any given time. Rewinding the tape is slow enough that doing random access within the file is generally impractical -- if possible, you want to process records sequentially, no more than two at a time.
Back when tape drives were common, and machines with only a few thousand (words|bytes) of RAM (of whatever sort) were common, that was sufficiently realistic to be worth studying. That circumstance is now rare, so studying bubble sort makes little sense at all -- but even worse, the circumstance when it's optimal isn't taught anyway, so even when/if the right situation arose, almost nobody would realize it.
As far as being the fastest on an extremely small and/or nearly sorted set of data, while that can cover up the weakness of bubble sort (to at least some degree), an insertion sort will essentially always be better for either/both of those.
Rem*_*arp 43
这取决于您的数据分发方式 - 如果您可以做出一些假设.
我发现要了解何时使用冒泡排序的最佳链接之一 - 或者其他类型,这是一个关于排序算法的动画视图:
http://www.sorting-algorithms.com/
Bil*_*ard 19
它在现实世界中并没有得到很多应用.这是一个很好的学习工具,因为它易于理解和快速实施.它具有不良(O(n ^ 2))最坏情况和平均性能.当您知道数据几乎已经排序时,它具有良好的最佳案例性能,但是有许多其他算法具有此属性,具有更好的最差和平均案例性能.
wor*_*ad3 10
最近我在一个优化轶事中发现了它的一个很好的用途.一个程序需要一组精灵按每个帧的深度顺序排序.spites顺序在帧之间不会有太大变化,因此作为优化,它们通过每帧一次通过进行冒泡排序.这是在两个方向(从上到下和从下到上)完成的.因此,精灵总是几乎用非常有效的O(N)算法进行排序.