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
0
votes
1 answer
Time complexity for median of medians
In several posts (e.g., https://cs.stackexchange.com/questions/125995/median-of-medians-proof-for-time-complexity) and articles on Google, I've seen the following time complexity recurrence written for the median of medians:
T(n) <= T(n/5) + T(7n /…

user5965026
- 465
- 5
- 16
0
votes
1 answer
Numpy median-of-means computation across unequal-sized array
Assume a numpy array X of shape m x n and type float64. The rows of X need to pass through an element-wise median-of-means computation. Specifically, the m row indices are partitioned into b "buckets", each containing m/b such indices. Next, within…

mgus
- 808
- 4
- 17
- 39
0
votes
2 answers
Why is my "median of medians"-algortihm always wrong by just a few positions?
I have a problem with my Java code... I've been staring at it for over 10 hours now and I am just not able to find the mistake(s) I made.
My task was to implement the "median of medians"-algorithm, by splitting an array into arrays of maximum length…

Mr. Moose
- 101
- 8
0
votes
0 answers
Dividing the list in 8 instead of 5 in the median of median algorithms
Image that explains the first algorithm
Generalized median-of-medians for sublist of size a
From this algorithm, we can see than in order to get linear running time for the algorithm, the constant has to be bigger than 4.
However, I wondered what…

juimdpp
- 37
- 1
- 4
0
votes
1 answer
Median of medians algorithm - which element to select as median for each group
(NOTE: I am dividing the array into sub-arrays containing 5 elements in my example)
I understand that the median-of-medians algorithms splits the n-input array into floor(n/5) groups with an additional group-containing (n)mod5 elements and then…

bgmn
- 498
- 2
- 7
- 25
0
votes
2 answers
Median of medians select algorithm
for the last few days I've been trying really hard to write this algorithm but without success. The code works and most of the time it gives me the right result but there are some cases where it fails. For example with this array {3, 8, 1, 9, 10, 7,…

Alessandro Mian
- 57
- 5
0
votes
0 answers
Median of 3 taking more time than usual quicksort in java
I have a quicksort code in java which I want to improve. The improved code should take less time than the quicksort code. However when using my improved code which implement median of 3 partitioning, it takes 400 miliseconds more. Can anybody help…

teddy
- 27
- 10
0
votes
1 answer
Modifying kth Element Found in Median of Median Quicksort
Note: This question was posted yesterday, late at night, and did not receive a sufficient answer. I've added some detail and reposted.
As an assignment, I've been tasked with creating a median of medians sort, that can also determine the nth…

MMMMMCK
- 307
- 3
- 14
0
votes
0 answers
How to design an clogn time algorithm of 2 sorted array to find median of all 2N?
I have given a question that there is given two array A and B are sorted in ascending order. I need to design an clogn time algorithm to find the median of all 2N integers. The question noted that the N may not power of 2. Hint to solve the question…

James
- 37
- 7
0
votes
0 answers
Random select and median of medians
I was planning to implement those algorithms in C++ and came upon one problem. What happens when I pass array with elements that repeats and ask for some order statistics? When I ask for a second order statistic from array [1,2,1] should it return 1…

ogarogar
- 323
- 2
- 14
0
votes
1 answer
array size n into k same size groups
I have an unsorted array of size n and I need to find k-1 divisors so every subset is of the same size (like after the array is sorted).
I have seen this question with k-1=3. I guess I need the median of medians and this is will take o(n). But I…

A.Shoob
- 9
- 2
0
votes
1 answer
Median of medians understanding the code
I found an implementation of algorithm in c++ here
https://gist.github.com/andlima/1774060
but I don't understand a purpose of few lines and how they work,
Should I add an if statement that if n is below certain amount we should just sort an…

Jędrzej
- 49
- 8
0
votes
3 answers
Method doesn't exit after return statement
Working on a method that picks a pivot for finding the kth smallest element in an array using median of medians algorithm; however it doesn't seem to exit pickCleverPivot after the return:
return median(A,left,right);
If it helps, assume that…

ProgrammingNoob
- 3
- 1
- 5
0
votes
1 answer
median of medians not working properly
I'm writing C code for the Median of Medians algorithm to find the kth smallest element in worst case linear time.
I've checked my code for Quick Sort, Swapping, etc.
Everything looks good but still it is not working properly every time.
Input given…

Mark Ben
- 177
- 1
- 1
- 14
0
votes
1 answer
Median of Medians algorithm not working consistently
I have implemented the select/median of medians algorithm using the following as a reference http://www.ics.uci.edu/~eppstein/161/960130.html (this has previously been linked here Median of Medians in Java).
My code seems to work for small arrays…

MMP
- 546
- 2
- 5
- 19