How to find median of medians in java for quicksort implementation
<p>So I have been working on properly implementing a quicksort algorithm for a homework assignment all night and after searching for a couple of hours I couldn't find any concrete implementation of the median partitioning. So, I am stuck at a huge roadblock where I don't know what part of my algorithm is horribly broken, and since all of the algorithms online are pseudo-code (so their description of the partitioning is excruciatingly vague), it's impossible for me to check against my implementation. So here is my Frankenstein code after reading document after document of how a median of medians pivot selection would work with quicksort in java.</p>

<p>Here are the only sources I've found even remotely helpful so far, and they are all painfully vague on the parts that make the algorithm work, deliberately it would seem after spending so much time searching:</p>

<p><a href="http://mitpress.mit.edu/algorithms/solutions/chap9-solutions.pdf" rel="nofollow">http://mitpress.mit.edu/algorithms/solutions/chap9-solutions.pdf</a></p>

<p><a href="http://www.cs.umd.edu/~meesh/351/mount/lectures/lect9-medians-selection.pdf" rel="nofollow">http://www.cs.umd.edu/~meesh/351/mount/lectures/lect9-medians-selection.pdf</a></p>

<p>*http://www.ics.uci.edu/~eppstein/161/960130.html</p>

<p>*http://en.wikipedia.org/wiki/Selection_algorithm</p>

<p>Here is my quicksort algorithm:</p>

<pre><code>{Removed Code}
</code></pre>

<p>And here is my selection method, I think the horribly messed up part is how I select the medians, and median of medians, but I couldn't find anything online to guide me on the partitioning:</p>

<pre><code>{Removed Code}
</code></pre>

<p>Also for my partitioning I used my regular quicksort partition method but changed it slightly so the pivot is given as a parameter, I don't know if there was anything else I was supposed to do since all of the sources online are vague in this area as well:</p>

<pre><code>{Removed Code}
</code></pre>

<p>Here is my insertion sort for sorting the groups of 5, just in case:</p>

<pre><code>{Removed Code}
</code></pre>

<p>Any insight into what part of the algorithm I screwed up would be immensely appreciated as I've been banging my head against a wall trying to find whats wrong. There is definitely a giant mistake in the selection algorithm since my JUnit test fails against a presorted array of [1..100] for selecting the median where the expected result is 50, but my algorithm always spits out 54. </p>
