Einfügesortierung vs. Blasensortierung vs. Quicksortierungsalgorithmus

Ich arbeite an einer Studie in der Klasse, in der ich Bubble Sort und Insert Sort und Quick Sort getestet habe. Ich habe den Test mit Zufallszahlen durchgeführt. Die Ergebnisse zeigen, dass die Einfügesortierung schneller als die Blasensortierung und die schnelle Sortierung am langsamsten ist.

Also habe ich die folgende Rangliste in Bezug auf die Zeit

Einfügesortierung (am schnellsten)Blasensortierung (zweite Punktzahl)schnelle Sortierung (die langsamste)

Unter Berücksichtigung, dass Einfügung und Blasensortierung eine Komplexität von O (n2) aufweisen, während die schnelle Sortierung von O (n log n) und O (n log n) schneller sein sollte !!!

Könnte mir jemand Erklärungen geben?

Vielen Dank

(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;
}

Antworten auf die Frage(3)

Ihre Antwort auf die Frage