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

  • Home
  • SEARCH
  • 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 386575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:35:23+00:00 2026-05-12T15:35:23+00:00

If you have 5 distinct numbers, how many comparisons at most do you need

  • 0

If you have 5 distinct numbers, how many comparisons at most do you need to sort this using merge sort?

  • 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-05-12T15:35:23+00:00Added an answer on May 12, 2026 at 3:35 pm

    I find the question interesting, so I decided to explore it thoroughly (with a little experimentation in Python).

    I downloaded mergesort.py from here and modified it to add a cmp argument for a comparator function. Then:

    import collections
    import itertools
    import mergesort
    import sys
    
    class CountingComparator(object):
      def __init__(self):
        self.count = 0
      def __call__(self, a, b):
        self.count += 1
        return cmp(a, b)
    
    ms_histo = collections.defaultdict(int)
    
    for perm in itertools.permutations(range(int(sys.argv[1]))):
      cc = CountingComparator()
      lperm = list(perm)
      mergesort.mergesort(lperm, cmp=cc)
      ms_histo[cc.count] += 1
    
    for c in sorted(ms_histo):
      print "%d %2d" % (c, ms_histo[c])
    

    The resulting simple histogram (starting with a length of 4, as I did for developing and debugging this) is:

    4  8
    5 16
    

    For the problem as posted, with a length of 5 instead of 4, I get:

    5  4
    6 20
    7 48
    8 48
    

    and with a length of 6 (and a wider format;-):

    7    8
    8   56
    9  176
    10 288
    11 192
    

    Finally, with a length of 7 (and even wider format;-):

     9   16
    10  128
    11  480
    12 1216
    13 1920
    14 1280
    

    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?

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

Sidebar

Related Questions

I have two distinct scenarios. One, where there is a many to many case,
I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have this SQL query: SELECT DISTINCT tb.SERIAL_NUM, tb.REVISION_NUM, tb.JOB_NUM, tb.JOB_TOTAL, tb.TEST_PROC, tb.BOX_NUM, tb.TEST_BENCH,
You have (up to 100) distinct sets of (2-4) numbers. The order of the
I have to add many registries to a table and I need help since
I have a problem with ROW_NUMBER() , if i used it with DISTINCT in
If we have an (arbitrary) connected undirected graph G, whose edges have distinct weights,
I have two distinct (no inheritance) interfaces: IInvestable and IPricable and two classes: IndexClass
Say I have y distinct values and I want to select x of them
I have the following query: SELECT DISTINCT w.name, count(*) FROM widgets AS w JOIN

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.