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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:07:35+00:00 2026-05-27T08:07:35+00:00

I run Quicksort 10 times, and get the average mean time. I do the

  • 0

I run Quicksort 10 times, and get the average mean time.
I do the same thing for Qicksort/Insertion sort combination, and it seems to be slower than just quicksort.

Here’s the part of the code where I call InsertionSort

public static <T extends Comparable<? super T>> void OptQSort2 (T[] data, int min, int max) {
        int indexofpartition;
        if(max - min > 0) {
            if( (max - min) <= 10) {
                // Use InsertionSort now
                InsertionSort.sort(data);
                return;
            } else {
                indexofpartition = findPartition(data, min, max);

                OptQSort2(data, min, indexofpartition - 1);

                OptQSort2(data, indexofpartition + 1, max);
            }
        }

}

And the regular Quicksort is just the same as the above snippet, but without the if condition that calls InsertionSort.

FindPartition is as follows:

public static <T extends Comparable<? super T>> int findPartition(T[] data, int min, int max) {
    int left, right;
    T temp, partitionelement;
    int middle = (min + max)/2;

    partitionelement = data[middle];
    left = min;
    right = max;

    while(left < right) {
        while(data[left].compareTo(partitionelement) <= 0 && left < right)
            left++;

        while(data[right].compareTo(partitionelement) > 0)
            right--;

        if(left < right) {
            temp = data[left];
            data[left] = data[right];
            data[right] = temp;
        }
    }

The mean time for just Quicksort and OptSort2(which uses insertion sort) are

Sorted using QuickSort in: 3858841
Sorted using OptQSort2 in: 34359610

Any ideas why? Does the size of the sequence matter? I am using a 1000 element Integer[] array for this

  • 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-27T08:07:35+00:00Added an answer on May 27, 2026 at 8:07 am

    In OptQSort2, for small partitions, you have the following function call:

    InsertionSort.sort(data);
    

    Is this supposed to insertion sort the small partition? It looks like you are insertion sorting the entire array. Shouldn’t you pass the min and max indexes to InsertionSort?

    Another option is to simply do no work on small partitions during OptQSort2. Then perform a single InsertionSort pass over the entire array after OptQSort2 has done its work.

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

Sidebar

Related Questions

At run time I want to dynamically build grid columns (or another display layout)
I run into similar codes like this all the time in aspx pages: <asp:CheckBox
I find this Quicksort partitioning approach confusing and wrong, yet it seems to work.
I spend some time implementing a quicksort algorithm in C#. After finishing I compared
i am writing multikey quicksort,i compiles fine,but when i run ,stops working abnormaly,i think
I want to sort files by modification time ascending and descending. According to this
In Java6 both quicksort and mergesort were used in Arrays#sort , for primitive and
I am having simple code of paralellizing QuickSort algorithm in Java, in run method
I am having issues implementing a quicksort to sort an array of strings. I
I read that it's possible to make quicksort run at O(nlogn) the algorithm says

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.