Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should look into the <a href="http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm" rel="nofollow noreferrer">Median of Medians algorithm</a>. It is a linear time algorithm with the following recurrence...</p> <pre><code>T(n) ≤ T(n/5) + T(7n/10) + O(n) </code></pre> <p>... which is O(n). The algorithm details...</p> <ol> <li>divide the list into n/5 subsequences of 5 elements each</li> <li>find the median of each list, by brute force. there will be n/5 of these</li> <li>Let m_1,..., m_n/5 be these medians. </li> <li>recursively find the median of these medians. this will be 1 element, the pivot!</li> </ol> <p>... and some pseudo-code...</p> <pre><code>MedianOfMedians (A[1],...,A[n]) begin for i=1 to n/5 do { let m_i be the median of A[5i − 4], A[5i − 3],..., A[5i]; } pivot = Select(m1,...,m_n/5, n/10); // the pivot return pivot end </code></pre> <p><strong>References</strong></p> <ul> <li><a href="http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm</a></li> <li><a href="https://stackoverflow.com/questions/1790360/median-of-medians-in-java">Median of Medians in Java</a></li> <li><a href="http://www.cs.berkeley.edu/~luca/w4231/fall99/slides/l3.pdf" rel="nofollow noreferrer">http://www.cs.berkeley.edu/~luca/w4231/fall99/slides/l3.pdf</a></li> <li><a href="http://www.soe.ucsc.edu/classes/cmps102/Spring05/selectAnalysis.pdf" rel="nofollow noreferrer">http://www.soe.ucsc.edu/classes/cmps102/Spring05/selectAnalysis.pdf</a></li> <li><a href="http://webee.technion.ac.il/courses/044268/w0809_website/recitations/Median.pdf" rel="nofollow noreferrer">http://webee.technion.ac.il/courses/044268/w0809_website/recitations/Median.pdf</a></li> </ul> <p>I hope this helps.<br> Hristo </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload