The median-of-medians algorithm is a deterministic, worst-case O(n)-time algorithm for the selection problem (given a list of values, find the kth largest value). The constant factor in the O(n) is large, and the algorithm is not commonly used in practice.
Questions tagged [median-of-medians]
70 questions
1
vote
1 answer
Median of Medians Big Example
Hello I am trying to understand how the median of medians algorithm works. In all examples I've seen so far there already are the groups of the numbers divided , before the execution of the algorithm begins. So I cannot understand how these groups…

JmRag
- 1,443
- 7
- 19
- 56
1
vote
2 answers
choosing pivot for the quickselect using median implemented in java?
I have found this code in github for quickselect algorithm otherwise known as order-statistics. This code works fine.
I do not understand medianOf3 method, which is supposed to arrange the first, middle and last index in sorted order. but actually…

brain storm
- 30,124
- 69
- 225
- 393
1
vote
2 answers
Algorithmic Reduction (Median of medians, quicksort)
I'm trying to better understand reduction, and I'm currently looking at the two algorithms, "Median of medians" and Quicksort.
I understand that both algorithms use a similar (effectively identical) partition subroutine to help solve their problems,…

cjhin
- 235
- 4
- 16
1
vote
2 answers
selection algorithm for median
I was trying to understand the selection algorithm for finding the median. I have pasted the psuedo code below.
SELECT(A[1 .. n], k):
if n<=25
use brute force
else
m = ceiling(n/5)
for i=1 to m
B[i]=SELECT(A[5i-4 .. 5i], 3)
mom=SELECT(B[1 ..m],…

user1773380
- 55
- 1
- 6
1
vote
1 answer
tukey's ninther for different shufflings of same data
While implementing improvements to quicksort partitioning,I tried to use Tukey's ninther to find the pivot (borrowing almost everything from sedgewick's implementation in QuickX.java)
My code below gives different results each time the array of…

damon
- 8,127
- 17
- 69
- 114
1
vote
1 answer
Finding the median of medians of quicksort
I am working on quick-sort with median of medians algorithm. I normally use the selection-sort to get the median of the subarrays of 5 elements. However, if there are thousands of subarrays, it means that I have to find a median of thousand medians.…

Tung Pham
- 579
- 4
- 11
- 29
1
vote
1 answer
Median-of-medians: what happens if the number of elements isn't a multiple of five?
I am currently studying the median of medians alg.
after studying from wiki, I have a question: what if the input size is not divisible by 5? how to find the median by using median of medians algorithm?

Jesse ZhAng
- 55
- 5
1
vote
2 answers
CUDA median calculation through reduction
I'm probably doing something incredibly stupid, but I can't seem to make this reduction work (there is probably a library that does this already, but this is for self-learning, so please bear with me). I'm trying to find the median of an array of…

wolfPack88
- 4,163
- 4
- 32
- 47
1
vote
2 answers
Complexity of finding k-th largest element using Median of Medians
I was reading the article on finding the k-th highest element in an array through the median-of-medians algorithm at ardendertat. In the portion explaining the complexity, the author seems to have discounted one factor, the cost of finding the…

SexyBeast
- 7,913
- 28
- 108
- 196
1
vote
1 answer
Selection routine with dupes?
I recently wrote a program after analyzing the k-th smallest element algorithm, first without the case of duplicates.
Now, however, I would like to analyze the expected asymptotic runtime for finding, say, the median of an array when there are…

CyberShot
- 2,265
- 6
- 28
- 36
0
votes
1 answer
Median Queries:- a subarray of A of length , you have to sort the elements of the subarray in a non-decreasing order
You are given an array A consisting of N elements. For a subarray of A of length len, you have to sort the elements of the subarray in a non-decreasing order. The element at the position ceil(len/2) is called the median of the subarray. Consider the…

V K Deewakar
- 11
- 2
0
votes
1 answer
Shouldn't the median of medians algorithm's running time be O(nlogn)?
Since we are dividing the subarray in an recursive manner, I think that the Time complexity of the algorithm should be O(nlogn).
For example an array size of 1000 and assuming that we are dividing the array into subarrays of size 5, the number of…
0
votes
0 answers
Median of medians algorithm: why divide the array into blocks of size 5 what if we divide into group of 4 is this effect time complexity
i was little confuse to make recursion (T) what if we divide the array (n/4). and why it is always recommended to use odd division of array why specifically 5. when we divide into 5 the recursion is like this
T(n) <= theta(n) + T(n/5) +…

Sam
- 1
- 1
0
votes
0 answers
find multiple elements of different ranks from unsorted array
I am working with very interesting [problem][1]:
Given an unsorted array of n distinct elements, We want to find this set of
logn elements: those at positions 1,2,4,8,16,..., n/2 in the sorted order. (The element at position 1 in the sorted order is…

user3699192
- 25
- 1
- 9
0
votes
1 answer
How to implement the medians of medians algorithm in Java
I am trying to implement the median of medians algorithm in Java. The algorithm shall determine the median of a set of numbers. I tried to implement the pseudo code on wikipedia:
https://en.wikipedia.org/wiki/Median_of_medians
I am getting a buffer…

user73347
- 47
- 3