Quicksort slower than Mergesort?

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

    (1) There is an qsort algo, used by C qsort(), which doesn't require extra memory. This was most probably invented by Hoare. This makes qsort() fast in C.

    (2) Randomizing the data before running qsort will almost always speed it up.

    (3) selecting the median data for pivot may make it faster,

提交回复
热议问题