Sorting Algorithms
Bubble, Insertion, and Selection Sort can also be referred to as Quadratic Sorting Algorithms because their Big O is O(n²), though their time complexities can differ. They are pretty similar, so we’ll be taking a closer look at each of these and considering when is the best case to use them!
Bubble Sort
This algorithm works very well when you have data that is almost or fully sorted. This is because it iterates through and it has to do very little swaps.
Insertion Sort
This algorithm also works very well with nearly or fully sorted data. It iterates through the data, checking and comparing each item, and sorts them as needed.
This is ideal when we have frequent incoming data that is being added to the collection, so it needs to be continuously sorted. It can figure out where to place it with a single pass!
Selection Sort
Selection Sort on the other hand, doesn’t do too well with nearly sorted data because it will keep iterating through over and over, even though it may already be sorted.