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
1
vote
2 answers

median of median implementation

Here is pseudo code for implementation of median by dividing array into 5 groups select(int A[],int first, int last, int i) { n = last - first + 1; /* n is the number elements to select from */ if (i > n) {return ERROR;} /* there is no ith…
dato datuashvili
  • 16,915
  • 53
  • 184
  • 303
1
vote
0 answers

Median of medians in Python doesn't run in O(n)

For a project, I want to compare the runtime of different median finding algorithms. I started with the "Medians of Medians" and basically used the code I found by Geeks for Geeks. I tested it by comparing to the standard python method of…
maxpower
  • 37
  • 5
1
vote
1 answer

correctness of fast small order statistic algorithm for odd-length array

Problem 9-3 of the textbook Intro to Algorithms (CLRS) describes a fast O(n) algorithm for finding the k-th order statistic (k-th element in the array when sorted) of a length-n array, for the particular case that k is much smaller than n. I am not…
xdavidliu
  • 1,198
  • 6
  • 23
1
vote
1 answer

Design of an algorithm problems of Clog n[C++ code]

Two sorted arrays of integers A[1..N] and B[1..N] are provided in ascending order. Q:Design an O(log N)-time algorithm for finding out the median of all 2N integers. N may not power of 2. To make thing easy, we can assume O(1) algorithm which return…
1
vote
2 answers

The time complexity of quick select

I read that the time complexity of quick select is: T(n) = T(n/5) + T(7n/10) + O(n) I read the above thing as "time taken to quick select from n elements = (time taken to select from 7n/10 elements)+ (time taken to quickselect from n/5 elements) +…
1
vote
2 answers

Median of Medians using blocks of 3 - why is it not linearic?

I understand why, in worst case, where T is the running time of the algorithm, that using the median of medians algorithm with blocks of size three gives a recurrence relation of T(n) = T(2n / 3) + T(n / 3) + O(n) The Wikipedia article for the…
Bar
  • 186
  • 8
1
vote
1 answer

Median of medians java implementation

I implemented Median of medians selection algorithm based on algs4 quickselect using the Wikipedia article, but my code doesn't work well: 1) it is said that median of medians finds kth largest element. However, my code finds kth smallest…
user1256821
  • 998
  • 3
  • 12
  • 33
1
vote
2 answers

"Moving Median" in Tableau

The setup: I have energy use data from a bunch of buildings built in a bunch of different years. I'd like to analyze the energy use by date constructed in Tableau. My initial problem was that there were not enough buildings in the sample to have a…
1
vote
2 answers

The median of an unordered set

I am a compsci student, and I received the following problem in Analysis & Design II class: The median of an unordered set is an element such that the number of elements less than the median is within one of the number of elements that are…
1
vote
0 answers

Selecting the Median

I realize this question has been asked a million times before, but I'm hoping this is a little different and a little more interesting. I came across the paper by Dor and Zwick that says it's possible to find the median in an array of n integers in…
user3270760
  • 1,278
  • 5
  • 16
  • 42
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,310
  • 6
  • 15
  • 47
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
  • 25,842
  • 54
  • 187
  • 349
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
  • 225
  • 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
  • 5
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
  • 7,127
  • 15
  • 62
  • 105