If you have 5 distinct numbers, how many comparisons at most do you need to sort this using merge sort?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I find the question interesting, so I decided to explore it thoroughly (with a little experimentation in Python).
I downloaded
mergesort.pyfrom here and modified it to add acmpargument for a comparator function. Then:The resulting simple histogram (starting with a length of 4, as I did for developing and debugging this) is:
For the problem as posted, with a length of 5 instead of 4, I get:
and with a length of 6 (and a wider format;-):
Finally, with a length of 7 (and even wider format;-):
Surely some perfectly regular combinatorial formula lurks here, but I’m finding it difficult to gauge what it might be, either analytically or by poring over the numbers. Anybody’s got suggestions?