Quicksort slower than Mergesort?

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

    Mergesort is a lot slower for random array based data, as long as it fits in ram. This is the first time I see it debated.

    • qsort the shortest subarray first.
    • switch to insertion sort below 5-25 elements
    • do a normal pivot selection

    Your qsort is very slow because it tries to partition and qsort arrays of length 2 and 3.

提交回复
热议问题