Quicksort slower than Mergesort?

后端 未结 15 1135
名媛妹妹
名媛妹妹 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: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.

提交回复
热议问题