News for hackers. Stuff that matters.
Re:The Median-of-Medians Algorithm by susi22 on Monday October 28, 2013 @03:12PM (#6629117)
Note that you shouldn't use the algorithm in practice (unless you need certain guarantees) since the average performance isn't that great. This is just like Mergesort vs Quicksort where Mergesort guarantees O(NlogN) yet Quicksort is usually much faster. The constant for the number of comparisons is quite high. Compare this to the average complexity for Quickselect with these pivot strategies:

- Random pivot (ie Median of 1) has 3.39N comparisons

- Median of 3 has 2.75N

If you want the fastest possible algorithm you should follow

http://dx.doi.org/10.1109/TSP.2012.2197394

which proposes to choose the median of N^{2/3}1/(4pi)^{1/3} elements as the pivot and then also uses a different strategy to choose the second pivot (close to the median yet "safe").

Another fast algorithm is Floyd & Rivest's SELECT (yes the same crypto Rivest) which is also asymptotically optimal and implementations exist. (Paper title: "Expected time bounds for selection")

Re:The Median-of-Medians Algorithm by wfunction on Monday October 28, 2013 @03:41PM (#6629287)
> "Note that you shouldn't use the algorithm in practice"

You certainly can:

1. Run the randomized algorithm

2. If if the usual way takes too long (more than O(n) for whatever constant factor makes sense to you), just stop doing more work and switch to the deterministic algorithm

Now you get the best of both speeds, within a small constant factor (like 2).

Re:The Median-of-Medians Algorithm by anonymous on Monday October 28, 2013 @03:59PM (#6629366)
Or, since we have enough cores, run both in two parallel threads, keeping the original list read-only.
Re:The Median-of-Medians Algorithm by crb002 on Monday October 28, 2013 @05:43PM (#6630045)
Or distribute out the median_5() work to many cores at once since each call is independent of the others.