MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / getMedian

Method getMedian

src/main/java/com/thealgorithms/others/BFPRT.java:137–142  ·  view source on GitHub ↗

Finds the median of the elements between the specified range. @param arr the input array @param begin the starting index @param end the ending index @return the median of the specified range

(int[] arr, int begin, int end)

Source from the content-addressed store, hash-verified

135 * @return the median of the specified range
136 */
137 public static int getMedian(int[] arr, int begin, int end) {
138 insertionSort(arr, begin, end);
139 int sum = begin + end;
140 int mid = sum / 2 + (sum % 2);
141 return arr[mid];
142 }
143
144 /**
145 * Sorts a portion of the array using insertion sort.

Calls 1

insertionSortMethod · 0.95