Quicksort - conditions that makes it stable

后端 未结 3 612
你的背包
你的背包 2021-02-15 23:45

A sorting algorithm is stable if it preserves the relative order of any two elements with equals keys. Under which conditions is quicksort stable?

Quick

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-16 00:06

    You can add these to a list, if that's your approach:

    • When the elements have absolute ordering
    • When the implementation takes O(N) time to note the relative orderings and restores them after the sort
    • When the pivot chosen is ensured to be of a unique key, or the first occurence in the current sublist.

提交回复
热议问题