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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:16:15+00:00 2026-06-13T00:16:15+00:00

I am working on a research in the class I tested bubble sort and

  • 0

I am working on a research in the class
I tested bubble sort and insertion sort and quick sort , i did the test on random numbers.
The results shows that insertion sort is more quicker than bubble sort and quick sort is the most slower one.

So I have the below ranking in terms of time

  1. insertion sort (the fastest)
  2. bubble sort (second score)
  3. quick sort (the slowest)

Taking into account that insertion and bubble sort have a complexity of O(n2) while
quick sort O(n log n) and O (n log n) should be faster !!!

Could anybody share with me explanations?

Thanks

(NSMutableArray *)quickSort:(NSMutableArray *)a
{
    // Log the contents of the incoming array
    NSLog(@"%@", a);

    // Create two temporary storage lists
    NSMutableArray *listOne = [[[NSMutableArray alloc]
    initWithCapacity:[a count]] autorelease];
    NSMutableArray *listTwo = [[[NSMutableArray alloc]
    initWithCapacity:[a count]] autorelease];
    int pivot = 4;

    // Divide the incoming array at the pivot
    for (int i = 0; i < [a count]; i++)
    {
        if ([[a objectAtIndex:i] intValue] < pivot)
        {
           [listOne addObject:[a objectAtIndex:i]];
        }
        else if ([[a objectAtIndex:i] intValue] > pivot)
        {
           [listTwo addObject:[a objectAtIndex:i]];
        }
    }

    // Sort each of the lesser and greater lists using a bubble sort
    listOne = [self bubbleSort:listOne];
    listTwo = [self bubbleSort:listTwo];

    // Merge pivot onto lesser list
    listOne addObject:[[NSNumber alloc] initWithInt:pivot]];

    // Merge greater list onto lesser list
    for (int i = 0; i < [listTwo count]; i++)
    {
        [listOne addObject:[listTwo objectAtIndex:i]];
    }

    // Log the contents of the outgoing array
    NSLog(@"%@", listOne);

    // Return array
    return listOne;
}
  • 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-06-13T00:16:16+00:00Added an answer on June 13, 2026 at 12:16 am

    O(nlogn) is “faster” then O(n^2), but let’s recall what the big O notation mean.

    It means that if algorithm A has complexity of O(nlogn), for some constants N_1, and c1, for each n>N – the algorithm is “faster” then c1*n*log(n). If algorithm B has O(n^2), there are some constants N_2,c2 such that the algorithm is “faster” then c2 * n^2 * log(n) for n > N_2.

    However – what happens before this N? and what is this constant C? We do not know. Algorithm B could still be “faster” then algorithm A for small inputs, but for large inputs – indeed, A will be faster (the asymptotic bound is better).

    For example, let’s take the case where algorithm A runs in T_1(n) = 10* nlog(n) ops, while algorithm B runs in T_2(n) = n^2. for n=3 – we get that T_1(3) = 10*3*2 = 60 (we tool the ceil for log(n)), and T_2(3) = 9 – thus algorithm B, though O(n^2) is faster then A for this input.

    Regarding quick sort and insertion sort:

    Quick sort is usually extremely fast, and decays into quadric time in very rare cases (the probability of this happening is slim if we chose a random element as a pivot).

    However, the constant behind the big O notation in quicksort is greater then insertion sort. Thus – a possible optimization is: use quicksort until you get to a certain threshold (say 30 elements), and then sort this subarray with insertion sort rather then quicksort. This post discusses this optimization.

    Bubble sort is (empirically) terrible for random arrays, but could be good if the array is almost sorted and the “out of place” elements are in its beginning.

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

Sidebar

Related Questions

I am currently in an introductory c++ class and am working assignment that sorts
I am a university student working on a research project that involves migrating a
I am working on software for scientific research that deals heavily with chemical formulas.
I am working with a solution that contains an ASP.NET website and class library
I am working on a research project with baseball data from retrosheet.org. I want
I am working on a research and I would like to come up with
I'm working on my first major Cocoa app for an undergraduate research project. The
We've been working with a Subversion repository for some time now for a research
I want to start working on a big project. I research about performance issues
Working with an undisclosed API, I found a function that can set the number

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.