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 6683327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:48:32+00:00 2026-05-26T04:48:32+00:00

Not sure why i’d be getting such odd numbers when looking at the number

  • 0

Not sure why i’d be getting such odd numbers when looking at the number of calls to the Comparer.

For 2 strings: 5 calls?
Plus there are sequences in there like this
12 Strings: 66 calls
13 Strings: 85 calls
14 Strigns: 91 calls
15 Strings: 89 calls ?????

Could it really be more efficient to sort 15 strings than 14?

int Iterations = 20;
int LastCycle = 0;
int CallsToSort = 0;
while (Iterations > 0)
        {
            LastCycle = CallsToSort;
            CallsToSort = 0;
            var strings = new string[Iterations];
            for (int i = 0; i < Iterations; i++) { strings[i] = "test" + i; }

            Array.Sort(strings, (s1, s2) => { CallsToSort++; return s1.CompareTo(s2); });
            Console.WriteLine("Strings:{0}\nCalls to Sort: {1}\n\t\tDiff:{2}\n\n", Iterations, CallsToSort, LastCycle-CallsToSort);
            Iterations--;
        }
  • 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-26T04:48:33+00:00Added an answer on May 26, 2026 at 4:48 am

    The Array.Sort() method will (usually) end up using a version of QuickSort where the pivots are chosen deterministically. The number of comparisons QuickSort uses will depend heavily on the pivots, and you are seeing that in your results.

    Some code (from ILSpy):

        int num = left;
        int num2 = right;
        int num3 = num + (num2 - num >> 1);
        ArraySortHelper<T>.SwapIfGreaterWithItems(keys, comparer, num, num3);
        ArraySortHelper<T>.SwapIfGreaterWithItems(keys, comparer, num, num2);
        ArraySortHelper<T>.SwapIfGreaterWithItems(keys, comparer, num3, num2);
        T t = keys[num3];
    

    That t is the pivot. You can probably work out exactly why you see the results from there.

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

Sidebar

Related Questions

Not sure if this is possible or if I'm expressing correctly what I'm looking
Not sure why I'm getting this error. I have the following: int* arr =
Not sure why I'm getting this, but I just installed RVM, the new Ruby
Not sure why but I am not getting anything back from the json call.
Not sure why I'm getting the following error when the URI works just fine
not sure it is possible but I am looking for a solution that will
Not sure if possible, but is there a way to have an application running
Not sure whether this should be asked here or on another site such as
Not sure how to ask a followup on SO, but this is in reference
Not sure what exactly is going on here, but seems like in .NET 1.1

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.