Common search and sort algorithms
Let’s go over some common search and sort algorithms you can apply to your projects or possible avoid using due to performance impact.
01. Linear search
This is the most basic form of searching and something most projects use with smaller arrays . But using this type of search with larger arrays can have a huge performance impact. Imagine you have an array of 10,000 objects and the object you are looking for is the last one. This would mean you have go through 9999 items before getting to it. The two upsides with this type of search is that it is quick to implement and the array does not need to be sorted.
02. Binary search
This is one of the most efficient search algorithms and still fairly straightforward to implement. The only downside with this search is that the data set must be sorted. This algorithm compares the value in the middle of the dataset with the highest value to the left and the lowest value to the right and then makes a new search based on which side has the value. It then repeats the same processes until the value is found.
03. Bubble Sort
Similar to linear search the bubble sort is very good in best case scenario i.e array is mostly sorted and small but it can have a huge performance impact if array is large and not sorted at all. But it has the same benefit as linear search, meaning it is the easiest algorithm to implement for sorting. The algorithm iterates through the array and compares the value at the current index with the next index and if it is higher than the next swap them. It will continue to compare the values until no values have been swapped meaning array has been fully sorted.
04. Merge Sort
This is one of the most efficient sorting algorithms. The list gets divided in half until each element is individual. The process is then reversed but the values in each list is sorted when it is merged into a new list.