Algorithm: Linear Search
Sorting algorithms are used to sort/order a set of data according to a given rule, like- ascending order, descending order, or any other custom rule.
Sorting algorithms are used to sort/order a set of data according to a given rule, like- ascending order, descending order, or any other custom rule.
Sorting algorithms are used to sort/order a set of data according to a given rule, like- ascending order, descending order, or any other custom rule.
Quick sort uses the divide-and-conquer technique. This helps to achieve the O(n log n) time complexity in most of the cases.
With that, it uses a pivoting technique to break down the list of elements into subsets. Then the subsets use the pivoting technique again to sort themselves.
Merge sort uses the idea of divide-and-conquer, with the combination of recursion, to sort a set of elements. This divide-and-conquer technique enables the algorithm to achieve the time complexity of O(n log n).
Insertion Sort repeatedly takes the next element and inserts it into its correct position within the sorted part of the array.
Basically, it finds the correct position of an element and inserts it in that correct position. In that process, it shifts the rest of the elements to make space for that key element.
This is not a very efficient sorting algorithm, but it is easy to understand, as there are lots of swapping/shifting operations involved.
Selection sort is a comparison-based sorting algorithm. It works by repeatedly finding the smallest element from the unsorted part of the array, and placing it at the beginning.
It is easy to understand and implement the algorithm, but it has a time complexity of O(n^2). So, very inefficient for large datasets.
Sorting algorithms are used to sort/order a set of data according to a given rule, like- ascending order, descending order, or any other custom rule.
There are the big O notations that we commonly encounter- Big O Notation Name Description O(1) Constant O(n) Linear O(n^2) Quadratic O(n^3) Cubic O(log(n)) Logarithmic (Log Linear) O(n log(n)) Linearithmic O(n!) Factorial O(2^n) Exponintial
Bubble sort is one of the most common sorting algorithms. It is a really simple sorting algorithm, but it is a very inefficient algorithm to handle large set of data.
In this algorithm, we go through the data set, and bubble up the largest number(item) to the end of the list. We do it one by one, and by traversing through the set of data, and swapping the largest number to the end.