Combine QuickSort and Median selection algorithm

前端 未结 4 755
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 15:18

I want to modify QuickSort (in Java) so that every time Partition is called, the median of the proportioned array is used as the pivot.

I have a median selection algorit

4条回答
  •  日久生厌
    2021-01-25 16:04

    What you are looking for is the Selection Algorithm. Here's a link with pseudocode.

    From the link:

    In computer science, a selection algorithm is an algorithm for finding the kth smallest number in a list

    To find the median you want to find the k=floor((n+1)/2) smallest number in the list where n is the size of the list.

提交回复
热议问题