Quicksort slower than Mergesort?

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

    I could imagine that by directly accessing the memory, using C for example, one can improve the performance of Quicksort more than it is possible with Mergesort.

    Another reason is that Mergesort needs more memory because it's hard to implement it as an in-place sort.

    And specifically for your implementation you could improve the choosing of the pivot, there are a lot of different algorithms to find a good pivot.

    As can be seen on wikipedia, one can implement Quicksort in different ways.

提交回复
热议问题