1.13k likes | 1.45k Views
Sorting & Recursion. Briana B. Morrison Adapted from Alan Eugenio & William J. Collins. Topics. Review Insertion Sort Selection Sort Bubble Sort This term Tree Sort Heap Sort Radix Sort New Merge Sort Quick Sort. Selection Sort.
E N D
Sorting & Recursion Briana B. Morrison Adapted from Alan Eugenio & William J. Collins
Topics • Review • Insertion Sort • Selection Sort • Bubble Sort • This term • Tree Sort • Heap Sort • Radix Sort • New • Merge Sort • Quick Sort Sorting
Selection Sort • Loops through input and “selects” smallest/largest value and swaps with current location • Worst case O(n2) • Average case O(n2) Sorting
Bubble Sort • Loops through input doing “adjacent” comparisons • Biggest/smallest element “bubble” to top/bottom • Worst case O(n2) • Average case O(n2) Sorting
FOR TREE SORT, EACH INSERTION TAKES LOGARITHMIC TIME AT MOST, SO FOR n INSERTIONS worstTime(n) IS O(n log n). therefore… averageTime(n) IS O(n log n) Sorting