Stability of quicksort partitioning approach

后端 未结 8 2077
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 01:12

Does the following Quicksort partitioning algorithm result in a stable sort (i.e. does it maintain the relative position of elements with equal values):

  pa         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 01:27

    If you need a stable O(n*log(n)) sort, use mergesort. (The best way to make quicksort stable by the way is to chose a median of random values as the pivot. This is not stable for all elements equivalent, however.)

提交回复
热议问题