-
Notifications
You must be signed in to change notification settings - Fork 0
Algo: Sorting
Rishav Ray edited this page May 16, 2025
·
1 revision
-
A sorting algorithm is a one that deals with ordering elements of a list, either in ascending or descending order.
-
There are 10 significant sorting algorithms: Selection, Bubble, Insertion, Merge, Quick, Heap, Cycle, Counting, Radix, & Bucket.
-
A stable sorting algorithm is one that preserves the original order of those that are equal in value. The opposite of this is unstable.
- Selection sort is an unstable sorting algorithm that sorts an list by repeatedly selecting the smallest (or largest) element from the unsorted portion and swapping it with the first unsorted element. This process continues until the entire list is sorted.
- Bubble sort is a stable sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.
- Insertion sort is a stable sorting algorithm that works by iteratively inserting each element of an unsorted list into its correct position in a sorted portion of the list.
- Merge sort is a recursive divide-and-conquer stable sorting algorithm that, in each function-call, splits the list into halves and merges the sorted halves into 1.
- Quick sort is a recursive divide-and-conquer unstable sorting algorithm that, in each function-call, finds a random pivot element, and partitions the list around that.
- Heap sort is an unstable sorting algorithm that uses a heap of all the elements and then pops from the heap to get the max or min (depending on the type of heap), and then the next max/min, and so on.
- Cycle sort is a algorithm for sorting lists that include a range of elements with no gaps or duplicates. The algorithm performs a series of swaps to place each element in its correct position within its cycle, until all cycles are complete and the list is sorted.
- Counting sort is a stable sorting algorithm that calculates the frequency of each distinct element in the input list and uses that info to place the elements in their correct sorted positions.
- Radix sort is a stable sorting algorithm that sorts elements by processing them digit by digit. This algorithm distributes the elements into buckets based on each digit's value. By repeatedly sorting the elements by their significant digits, from the least significant to the most significant, Radix Sort achieves the final sorted order.
- Bucket sort is an algorithm that involves dividing elements into various groups, or buckets. Once the elements are divided into buckets, they can be sorted using any other sorting algorithm, either stable or unstable. Finally, the sorted elements are gathered together in an ordered fashion.