美文网首页
8. Quick Sort --- An application

8. Quick Sort --- An application

作者: 何大炮 | 来源:发表于2017-08-16 10:06 被阅读0次

Let a1,a2,...,an be a list of real numbers. The basic steps of Quicksort are as follows:

  1. Pick an element x as the pivot element.
  2. Partition the list into three sublists,
    R1 ={ai |ai <x}, R2 ={ai |ai =x}, andR3 ={ai |ai >x}.
  3. Sort the elements in R1 and R3 recursively, by invoking Quicksort (as the elements in R2 are already sorted.)
  4. Combine the three sorted lists R1, R2, R3 in this order into a sorted
    sequence.

评价:

  1. The running time of Quicksort is O(n^2) in the worst case.
  2. The running time is O(nlogn) in an average case: either for a random input, or using a random pivot.
  3. To make the worst case unlikely, use a random pivot or follow some rule justified by experience such as “median of three”.
  4. Small lists (less than 10–20 elements) are sorted faster by insertion sort. Therefore, use insertion sort on all small sublists rather than partitioning further.
  5. Implemented carefully,Quicksort is usually the fastest method for sorting arrays.
推导过程

The code in python3 is here

相关文章

  • 8. Quick Sort --- An application

    Let a1,a2,...,an be a list of real numbers. The basic ste...

  • 排序算法总结

    merge: quick sort:

  • sort

    bubble_sort: select_sort: insert_sort: merge_sort: quick_...

  • 刷题(11)各种排序算法

    把各种排序算法实现一遍 1. quick sort: public void quick_sort(int[] a...

  • Quick Sort

  • Quick Sort

    描述实现快速排序算法 分析随机选择待排序数组中一个元素为中心轴,将所有小于中心轴的元素移到左边,大于中心轴的元素移...

  • QUICK SORT

  • Quick sort

    快速排序是一种分治算法,将一个数组分成两个子数组,将两部分独立的排序。快速排序和归并排序是互补的:归并排序将数组分...

  • Quick Sort

  • Quick Sort

    quick sort体现了分治的思想。平均情况下快速排序的时间复杂度是Θ(nlgn),最坏情况是n^2。由于递归调...

网友评论

      本文标题:8. Quick Sort --- An application

      本文链接:https://www.haomeiwen.com/subject/vgymrxtx.html