Improving the Quick sort

前端 未结 14 1324
终归单人心
终归单人心 2021-02-05 22:33

If possible, how can I improve the following quick sort(performance wise). Any suggestions?

void main()
    {
      quick(a,0,n-1);
    }

    void quick(i         


        
14条回答
  •  离开以前
    2021-02-05 23:09

    Currently the most advanced quicksort widely used is implemented in Java's DualPivotQuicksort.java So you can simply follow that approach and you will see a nice performance improvement:

    • Use Insertion sort for small arrays (47 is the number used in Java)
    • Use that dual-pivot quicksort choosing the 2nd and 4th elements of 5 as the two pivots
    • Consider using mergesort for arrays with runs of sorted numbers

    Or if you want to add a bit more complexity then code a 3-pivot quicksort.

提交回复
热议问题