排序算法的稳定性

Jun 22, 2016


8中排序算法的稳定性

算法 稳定性 算法 稳定性
冒泡 选择
插入 快排
归并 希尔
基数 堆排序

java.util.Arrays的排序实现(jdk1.7)

  • 对于引用类型数组,采用TimSort。TimSort is a hybrid stable sorting algorithm , derived from merge sort and insert sort.
  • 对于primitive数组,采用Dual-Pivot QuickSort。Dual-Pivot QuickSort是QuickSort的变形,选择两个比较值,将元素放在他们之间。

Why java Arrays use two differt sort algorithm for different types?

  1. A stable merge sort for Reference (TimSort);
  2. For Primitive , can use quick sort which is not stable (Dual-Pivot QuickSort)

Reason: For primitive, there is no way to distinguish two same value;


上一篇博客:构造回文串
下一篇博客:扫描透镜