



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This course covers topics in algorithms and data structures including algorithm analysis, sorting, heaps, binary search trees, hashing techniques and hash tables, and (as time permits) graphs and graph-based algorithms. Key points in these slides are: Heapsort, Heapsort Exercise, Array-Based Heap Implementation, Sorting Algorithms,
Typology: Slides
1 / 7
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 )