Skip to content

Sorting Algorithm | Infographic

  • by

Sorting Algorithm is the process of arranging the elements of an array so that they can be placed either in ascending or descending order.

  • sorting algorithm
  • sorting algorithm time complexity

Heap Sort

Heap sort is a comparison-based sorting technique based on the binary heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element ad the beginning and repeat the same process for the remaining elements.

Quick Sort

Quick sort is also and divides and conquer algorithm. It picks an element as a pivot and partitions the given array around the picked pivot. This algorithm is used to quickly sort items within an array matter how big the array is.

Bubble Sort

Bubble sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and word-case time complexities is quite high.

Selection sort

The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning.

Merge sort

Merge sort is an algorithm that is considered an example of the divide and conquers strategy. So, the array is initially divided into two equal halves and then they are combined in a sorted manner.

Insertion sort

Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in the sorted part.

Shell sort

Shell sort is mainly a variation of Insertion Sort. In insertion sort, we move elements only one position ahead. When an element has to be moved far ahead, many movements are involved. The idea of ShellSort is to allow the exchange of far items. In Shell sort, we make the array h-sorted for a large value of h. We keep reducing the value of h until it becomes 1. An array is said to be h-sorted if all sublists of every h’th element are sorted.

Time Complexities of all Sorting Algorithms

The time complexity of an algorithm describes the amount of time an algorithm takes to run in terms of the characteristics of the input.

Sorting AlgorithmTime Complexity – BestTime Complexity – WorstTime Complexity – AverageSpace Complexity
Bubble Sortnn2n21
Selection Sortn2n2n21
Insertion Sortnn2n21
Merge Sortnlog nnlog nnlog nn
Quicksortnlog nn2nlog nlog n
Counting Sortn+kn+kn+kmax
Radix Sortn+kn+kn+kmax
Bucket Sortn+kn2nn+k
Heap Sortnlog nnlog nnlog n1
Shell Sortnlog nn2nlog n1

Big-O Complexity Chart

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading