What's the difference of dual pivot quick sort and quick sort?

前端 未结 3 718
无人及你
无人及你 2020-11-30 19:31

I\'ve never seen dual pivot quick sort before. If it is a upgrade edition of quick sort?
And what is the difference of dual pivot quick sort and quick sort?

3条回答
  •  抹茶落季
    2020-11-30 19:50

    For those who are interested, take a look how they implemented this algorithm in Java:

    http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/DualPivotQuicksort.java#DualPivotQuicksort.sort%28int%5B%5D%2Cint%2Cint%2Cint%5B%5D%2Cint%2Cint%29

    As stated in source:

    "Sorts the specified range of the array using the given workspace array slice if possible for merging

    The algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations."

提交回复
热议问题