QuickSort Dijkstra 3-Way Partitioning: why the extra swapping?

前端 未结 2 1025
抹茶落季
抹茶落季 2021-02-04 07:55

\"Algorithm\"

Given the algorithm here, look at the scenario where i is at \"X\", the following happens:

2条回答
  •  抹茶落季
    2021-02-04 08:14

    You are right, the extra swap operations are not necessary, this algorithm here is best for clarity, but not for performance. See the discussion of Quick Sort (3 Way Partition).

    In Quicksort is optimal by Robert Sedgewich himself, he has a different approach that uses much less swap operation, but you can imagine it also needs more code, and is less clear than the algorithm in the demo.

    enter image description here

提交回复
热议问题