Questions tagged [median-of-medians]

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.

62 questions
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
  • 303
  • 2
  • 11
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…
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
  • 7
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…
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
  • 147
  • 1
  • 1
  • 12
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
  • 18
0
votes
1 answer

Median of Medians algorithm error

I'm implementing a select-kth algorithm using the Median of Medians pivot method. Specifically, I'm following the pseudocode listed here.. However, my code crashes (error discussed below), I see why it crashes, but I don't understand what I can do…
kfriede
  • 177
  • 1
  • 14
0
votes
1 answer

Median of median algorithm recurrence relation

I know that the linear select (median of medians algorithm) recurrence equation is as follows: T(n) <= an + T(n/5) + T(7n/10) But where do these terms come from? I've been trying to understand, but I'm extremely confused. Can anyone please shed…
Vimzy
  • 1,501
  • 6
  • 23
  • 49
0
votes
1 answer

What is the worst case time complexity of median of medians quicksort?

What is the worst case time complexity of median of medians quicksort ( pivot is determined by the median of medians which take O(n) time to find )?
0
votes
1 answer

Weird bug in median of medians as pivot to find Kth max element

Finally I found the bug, please look at the second EDIT But there is still that question, you see, the last fourth row of "getMedian()" method, I sort the medians[] array to find the median of medians. Personally I think this breaks the worst case…
zproject89
  • 205
  • 5
  • 18
0
votes
1 answer

Median of medians is not the real median. Correct?

Personally, I think the median of medians is not the real median. Correct?So if the above statement is true, why using the median of medians as the pivot to partition the array to find the Kth min elem's time complexity worst case is O(n)? The "n"…
0
votes
1 answer

find approx median in unsorted list

i want to find approx median in unsorted list,i know two algorithm algorithm 1- quickselect algorithm 2- Median of medians i can't use quickselect in my project because it take O(n^2) in worst case. i heard about Median of medians,but my colleagues…
asd
  • 215
  • 3
  • 9
0
votes
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
  • 8,635
  • 25
  • 92
  • 179
-1
votes
1 answer

Finding block median in median of medians algorithm

I know that formula for the median of medians algorithm is : T(n)<= T(0.7n)+T(0.2n)+O(n) and O(n) came from finding median of each block(size of 5), and I'm wondering why It takes O(n) to find median of each block.. that sound like finding median of…
Jiseop Han
  • 37
  • 5
-1
votes
1 answer

Time complexity of median of medians algorithm

Hello I am taking Introduction to algorithm class this semeseter. However I have some problem in calculating time complexity of median of medians algorithm (here). I'm wondering how to get T(n)<=10cn from T(n)<=T(0.2n)+T(0.7n)+cn.. I think I cannot…
Jiseop Han
  • 37
  • 5