Sorting Algorithms
My first python class was actually very helpful. Link to various sorting algorithms implemented in Python.
Algorithm | Best Case(Ω) | Average Case(Θ) | Worst Case(O) |
---|---|---|---|
Selection Sort | |||
Insertion Sort | |||
Bubble Sort | |||
Merge Sort | |||
Quick Sort | |||
Heap Sort | |||
Radix Sort | |||
Counting Sort | |||
Bucket Sort |
https://www.bigocheatsheet.com/
Merge Sort Vs. Quick Sort
- Quicksort is likely faster in practice, but merge sort is faster on paper.
- Merge Sort divides the set into the smallest possible groups immediately then reconstructs the incrementally as it sorts the groupings.
- Quicksort continually partitions the data set by a pivot, until the set is recursively sorted
Custom Sorting in C++
You can do something like the following
For a C++ Vector,
Using the greater operator