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.

70 questions
2
votes
1 answer

Find median of N 8-bit numbers

Given an array of N 8-bit numbers ( value 0-255)? How to find the median? I have tried radix sort and median of medians algorithms. Is there a better way given the values of the numbers are between 0 and 255?
Idan
  • 72
  • 1
  • 15
2
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"…
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…
user466534
1
vote
1 answer

Finding median of a list using quick select and median-of-medians

Suppose A = [1, 2, 3, 4, 5, 6, 7, 8, 9]. I have to find the median here which is 5 and I am required to use the concept of quick select and median-of-medians. I have made the following code but for some reason, it outputs 4 which is wrong. Where…
mrkupidooo
  • 35
  • 5
1
vote
1 answer

Quick select with random pick index or with median of medians?

To avoid the O(n^2) worst case scenario for quick select, I am aware of 2 options: Randomly choose a pivot index Use median of medians (MoM) to select an approximate median and pivot around that When using MoM with quick select, we can guarantee…
user5965026
  • 465
  • 5
  • 16
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
  • 47
  • 6
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
  • 2,411
  • 14
  • 33
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
  • 196
  • 10
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
  • 1,158
  • 3
  • 15
  • 35
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
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,871
  • 8
  • 30
  • 56
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,444
  • 5
  • 23
  • 45