Quicksort- how pivot-choosing strategies affect the overall Big-oh behavior of quicksort?

后端 未结 3 719
甜味超标
甜味超标 2021-02-10 00:43

I have came up with several strategies, but I am not entirely sure how they affect the overall behavior. I know the average case is O(NlogN), so I would assume that would be in

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 00:55

    The best pivot is the one which can divide the array exactly in two halves. The median of the array is off course the best choice. I will suggest this approach :-
    select some random indexes
    calculate median of these elements
    Use this as pivot element

    From the O(n) median finding algorithm, I think 5 random indexes should be sufficient enough.

提交回复
热议问题