Inserción ordenar vs burbuja ordenar vs Quicksort algoritmo
Estoy trabajando en una investigación en la clase que probé clasificación de burbujas, clasificación de inserción y clasificación rápida, hice la prueba en números aleatorios. Los resultados muestran que la ordenación por inserción es más rápida que la ordenación por burbuja y la ordenación rápida es la más lenta.
Así que tengo el siguiente ranking en términos de tiempo
ordenación por inserción (la más rápida)tipo de burbuja (segunda puntuación)ordenación rápida (la más lenta)¡Teniendo en cuenta que la inserción y la clasificación de burbujas tienen una complejidad de O (n2), mientras que la clasificación rápida O (n log n) y O (n log n) deberían ser más rápidas!
¿Alguien podría compartir conmigo las explicaciones?
Gracias
(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;
}