Below my code is trying to understand the median of the median algorithm (using blocks of size 5). I understand how to get input medians, but I'm not sure how to encode a block to preserve input recursion until I have a median. Then, having received this median, Iโm not sure how to use it as a core to throw out useless information to break the input. getMediansArray returns an array of size ceil (input.length / 5) and getMedians simply returns the median of the array (used only for arrays of length <= 5).
public static int[] findKthElement(int[] input, int k) { int numOfMedians = (int) Math.ceil(input.length/5.0); int[] medians = new int[numOfMedians]; medians = getMediansArray(input, medians)
java arrays algorithm median-of-medians
Emmanuel mudiay
source share