Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:23:47+00:00 2026-06-01T08:23:47+00:00

So I have been working on properly implementing a quicksort algorithm for a homework

  • 0

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.

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:

http://mitpress.mit.edu/algorithms/solutions/chap9-solutions.pdf

http://www.cs.umd.edu/~meesh/351/mount/lectures/lect9-medians-selection.pdf

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

*http://en.wikipedia.org/wiki/Selection_algorithm

Here is my quicksort algorithm:

{Removed Code}

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:

{Removed Code}

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:

{Removed Code}

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

{Removed Code}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:23:48+00:00Added an answer on June 1, 2026 at 8:23 am

    Where you should pick the median from the 5-element “subsets” you are picking the element next to it: the median would have the index 2 but you are picking the index 3. You need:

    int median = subset[2]; // Or sslength/2 if you don't like hardcoded values
    

    By the way, the “median of medians” of [1..100] would be 48 or 53, not 50. Write the numbers in a grid of 5 by 20: the values in the middle row (3,8,13,…) are the medians of the “subsets”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been working on this question for a couple hours and have come close
I have been working on implementing the first 6 functions of the NSComparisonMethods protocol
OK, so I have been searching for hours about my problem but nothing seems
I have been developed a jnlp file, and it is working properly when client
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working with a string[] array in C# that gets returned from
We have been working with CVS for years, and frequently find it useful to
I have been working on some legacy C++ code that uses variable length structures
I have been working with relational databases for sometime, but it only recently occurred

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.