



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CPSC 223 -‐-‐ Fall 2010 2
CPSC 223 -‐-‐ Fall 2010 3
CPSC 223 -‐-‐ Fall 2010 10
CPSC 223 -‐-‐ Fall 2010 13 void heapsort(int theArray[], int size) { for(int i = (size-1)/2; i >= 0; i--) // build heapRebuild(theArray, size, i); int last = size-1; for(int j = 1; j < size; j++) { // delete swap(theArray[0], theArray[last]); heapRebuild(theArray, last, 0); last--; } }
CPSC 223 -‐-‐ Fall 2010 14 SelecSon Sort Bubble Sort Best Case Average Case Worst Case O ( n^2 ) O ( n^2 ) O ( n^2 ) O ( n ) O ( n^2 ) O ( n^2 ) InserSon Sort O ( n ) O ( n^2 ) O ( n^2 ) Quicksort O ( n log n ) O ( n log n ) O ( n^2 ) Treesort O ( n log n ) O ( n log n ) O ( n^2 ) Heapsort O ( n log n ) O ( n log n ) O ( n log n ) Mergesort O ( n log n ) O ( n log n ) O ( n log n )