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
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
  • 187
  • 1
  • 14
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
  • 225
  • 5
  • 19
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
-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
  • 7
-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
  • 7
-2
votes
1 answer

How to find the kth smallest element at O(n) if we know there is O(n) function that returns the median of an array

I am trying to find an algorithm that finds kth smallest element from unsorted array of size n at O(n) by using a function that returns the median of array of size n at O(n). I think I have to find a recursive function that has time complexity like…
kiarashmo
  • 1
  • 3
-2
votes
1 answer

What exactly is special on this case that my median algorithm doesn't work anymore?

I wrote a code in java for school to compute the median of an array. We have some test cases for this. The first column is the input, the second the expected and the third the actual output. Is anything special on the case that does not work? I've…
Boorow
  • 1
-3
votes
1 answer

Fixing a Median of Medians method I self translated from an algorithm

I'm copying this algorithm straight from a book, but I keep getting an ArrayIndexOutOfBoundsException at the "ERROR HERE!!!!" part... for the T[i] = ... It's driving me nuts and I need to get this done... can someone suggest how I can fix this? I…
user1189352
  • 3,628
  • 12
  • 50
  • 90
-3
votes
2 answers

Median in 500GB file java

Find median of all numbers in the given 500GB file at the command prompt. File format eg: 12 4 98 3 with one number in each line(numbers can be repeated).Can anyone please help on how to approach on this in JAVA? if we have to split the file and…
Siri
  • 15
  • 1
1 2 3 4
5