is an algorithm used for rearranging a given array or list in a specific manner according to a comparison operators on the elements. The comparison operator is used to decide the new order of elements in the perspective data structure.
Some of the most well-known sorting algorithms are:
is one of the simplest sorting algorithms. Bubble sort works by repeatdly swapping the adjacent elements if they are in the wrong order. This algorithm is not advised for a large data sets, because of it's high time complexity.
Just like Bubble Sort, insertion sort is one the simplest sorting algorithms. The array of list is split into two parts. Sorted and unsorted part. The values from the unsorted are separated picked and placed at the correct position in the sorted part.
A sorting algorithm that works by dividing an array into smaller subarrays. The subarrays are then sorted, and then merging the sorted subarrays back together to form the final sorted array. This process is repeated until the entire array/list is sorted. One of the main advantages of merge sort is the time complexity of O(n log n), which means it can sort large set of arrays relatively quickly and efficient.
Like merge sort, quick sort picks picks an element as a pivot and partitions the given array around the picked pivot. It partitions an array and calls itself recursively twice to solve the two resulting subarrays. Quick Sort is highly efficient for large sets of data with a time complexity of O(n2).
Similar to selection sort where we find the minimum element and place the minimum element at the beginning. This process is repeated until the entire array/list is sorted. Heap Sort is not very efficient sorting algorithm when working with highly complex data. It is also unstable, and might rearrange the relative order.
Sorting Algorithm is a set of instructions that take an array or list as an input and arrange an item into a particular order. The sorts mostly in numerical or alphabetical order, and can be in ascending or descending order.