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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:11:12+00:00 2026-05-16T11:11:12+00:00

I found that java.util.Arrays.sort(Object[]) use 2 kinds of sorting algorithms(in JDK 1.6). pseudocode: if(array.length<7)

  • 0

I found that java.util.Arrays.sort(Object[]) use 2 kinds of sorting algorithms(in JDK 1.6).

pseudocode:

if(array.length<7)
   insertionSort(array);
else
   mergeSort(array);

Why does it need 2 kinds of sorting here? for efficiency?

  • 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-16T11:11:12+00:00Added an answer on May 16, 2026 at 11:11 am

    It’s important to note that an algorithm that is O(N log N) is not always faster in practice than an O(N^2) algorithm. It depends on the constants, and the range of N involved. (Remember that asymptotic notation measures relative growth rate, not absolute speed).

    For small N, insertion sort in fact does beat merge sort. It’s also faster for almost-sorted arrays.

    Here’s a quote:

    Although it is one of the elementary sorting algorithms with O(N^2) worst-case time, insertion sort is the algorithm of choice either when the data is nearly sorted (because it is adaptive) or when the problem size is small (because it has low overhead).

    For these reasons, and because it is also stable, insertion sort is often used as the recursive base case (when the problem size is small) for higher overhead divide-and-conquer sorting algorithms, such as merge sort or quick sort.

    Here’s another quote from Best sorting algorithm for nearly sorted lists paper:

    straight insertion sort is best for small or very nearly sorted lists

    What this means is that, in practice:

    • Some algorithm A1 with higher asymptotic upper bound may be preferable than another known algorithm A2 with lower asymptotic upper bound
      • Perhaps A2 is just too complicated to implement
      • Or perhaps it doesn’t matter in the range of N considered
        • See e.g. Coppersmith–Winograd algorithm
    • Some hybrid algorithms may adapt different algorithms depending on the input size

    Related questions

    • Which sorting algorithm is best suited to re-sort an almost fully sorted list?
    • Is there ever a good reason to use Insertion Sort?

    A numerical example

    Let’s consider these two functions:

    • f(x) = 2x^2; this function has a quadratic growth rate, i.e. "O(N^2)"
    • g(x) = 10x; this function has a linear growth rate, i.e. "O(N)"

    Now let’s plot the two functions together:

    alt text
    Source: WolframAlpha: plot 2x^2 and 10x for x from 0 to 10

    Note that between x=0..5, f(x) <= g(x), but for any larger x, f(x) quickly outgrows g(x).

    Analogously, if A1 is a quadratic algorithm with a low overhead, and A2 is a linear algorithm with a high overhead, for smaller input, A1 may be faster than A2.

    Thus, you can, should you choose to do so, create a hybrid algorithm A3 which simply selects one of the two algorithms depending on the size of the input. Whether or not this is worth the effort depends on the actual parameters involved.

    Many tests and comparisons of sorting algorithms have been made, and it was decided that because insertion sort beats merge sort for small arrays, it was worth it to implement both for Arrays.sort.

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

Sidebar

Related Questions

I use java.util.Timer to trigger jobs in my app, but I found that it
When I looked into the implementation of java.util.UUID.fromString , I found that it doesn't
I was reading through the java.util.concurrent API , and found that CountDownLatch : A
I am a java programmer, I found that Java is very good at doing
I am using a Java code that I found that generates a public and
I am learning Java and just found that the Interface can have fields, which
I am reading some materials on Java serialization and found that, for self defined
I've found examples on how to either set the classpath so that a Java
Is there any Java profiler that allows profiling short-lived applications? The profilers I found
I found a couple of threads that touch on development of C#/Java apps but

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.