Sorting Algorithms

jonnynotbravo

Jonny

Posted on January 26, 2023

Sorting Algorithms

Sorting Algorithm

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:

  • Bubble Sort

  • Selection Sort

  • Insertion Sort

  • Merge Sort

  • Quick Sort

  • Heap Sort

Bubble Sort

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.

Bubble Sort

Selection Sort

Considering we're sorting a list/array in ascending order, selection sort sorts a list by repeatdly finding the minimum element from the unsorted part and shifting it to the beginning of the array.
Selection Sort

Insertion Sort

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.
Insertion Sort

Merge Sort

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.
Merge Sort

Quick Sort

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).
Quick Sort

Heap Sort

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.
Heap Sort

Conclusion

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.

Thank you!
Jonny

💖 💪 🙅 🚩
jonnynotbravo
Jonny

Posted on January 26, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related