- Selection, Bubble, and Insertion Sort
Selection, Bubble, and Insertion sort are some of the first that new developers should work through. In any scenario when speed matters you’re not going to be using these algorithms but working with them is a great introduction to array traversal and manipulation. Selection sort helps in finding the minimum element in the unsorted portion of the array and swapping it with the first unsorted element. Repeat until the array is fully sorted. Bubble sort iterates through the array repeatedly, comparing adjacent pairs of elements and swapping them if they are in the wrong order. Repeat until the array is fully sorted. Insertion sort, on the other hand, helps to build up a sorted subarray from left to right by inserting each new element into its correct position in the subarray. Repeat until the array is fully sorted.
- Binary Search
Binary search is among the first things taught in any computer science class. Binary search is used to perform a very efficient search on sorted datasets. The time complexity is O(log2N). A binary search consists of taking a sorted array, iteratively splitting the array into two, and comparing an element that you are looking for against each half until you find the element. The idea is to repeatedly divide in half the portion of the list that could contain the item until we narrow it down to one possible item. A common application of this algorithm is when you search for the name of the song in a sorted list of songs, it performs binary search and string-matching to quickly return the results. It is perhaps the simplest example of how a little bit of ingenuity can make things, quite literally, exponentially more efficient.
Source Link: https://www.itscybertech.com/2023/04/top-8-algorithms-every-programmer.html