Quicksort slower than Mergesort?

后端 未结 15 1138
名媛妹妹
名媛妹妹 2021-02-07 02:01

I was working on implementing a quicksort yesterday, and then I ran it, expecting a faster runtime than the Mergesort (which I had also implemented). I ran the two, and while th

相关标签:
15条回答
  • 2021-02-07 02:53

    Based on this wikipedia article your results are expected.

    0 讨论(0)
  • 2021-02-07 02:58

    For good performance of quicksort, it is important not to recurse all the way down to lists of length 1

    You should consider sorting lists of 2, 3 and even 4 as nested ifs swapping if necessary. Let us know how the performance changes.

    0 讨论(0)
  • 2021-02-07 02:59

    Were you datasets random enough? Were they partially sorted?

    That might affect the speed of the sort...

    Like for the QuickSort's partition(), you'd skip along if the numbers are in sorted order, until you find one that's not.

    0 讨论(0)
提交回复
热议问题