Quicksort - conditions that makes it stable

后端 未结 3 677
花落未央
花落未央 2021-02-15 23:21

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:03

    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.

提交回复
热议问题