What is Sorting?

Sorting is a way of arranging items in a specific order, such as numbers from smallest to largest or names alphabetically. This helps computers and people find what they are looking for in a more organized way.

What is a Sorting Algorithm?

A sorting algorithm is a set of instructions or rules that tells a computer how to arrange a list of items in a particular order. Imagine you have an array of numbers, and you want to arrange them in ascending order. A sorting algorithm would be like a set of steps you follow to organize the numbers from the smallest to the largest.

Complexity Comparison of Sorting Algorithms

AlgorithmBest CaseAverage CaseWorst CaseMemoryStableMethod Used
Quick Sortnlognnlognn2nlognNoPartitioning
Merge SortnlognnlognnlognnYesMerging
Heap Sortnlognnlognnlogn1NoSelection
Insertion Sortnn2n21YesInsertion
Tim SortnnlognnlognnYesInsertion & Merging
Selection Sortn2n2n21NoSelection
Shell Sortnlognn4/3n3/21NoInsertion
Bubble Sortnn2n21YesExchanging
Tree SortnlognnlognnlognnYesInsertion
Cycle Sortn2n2n21NoSelection
Strand Sortnn2n2nYesSelection
Cocktail Shaker Sortnn2n21YesExchanging
Comb Sortnlognn2n2NoExchanging
Gnome Sortnn2n21YesExchanging
Odd Even Sortnn2n21YesExchanging

There are various types of sorting algorithms in computer science.

  • Selection Sort
  • Bubble Sort
  • Insertion Sort
  • Merge Sort
  • Quick Sort
  • Heap Sort
  • Counting Sort
  • Radix Sort
  • Bucket Sort
  • Bingo Sort Algorithm
  • ShellSort
  • TimSort
  • Comb Sort
  • Pigeonhole Sort
  • Cycle Sort
  • Cocktail Sort
  • Strand Sort
  • Bitonic Sort
  • Pancake sorting
  • BogoSort or Permutation Sort
  • Gnome Sort
  • Sleep Sort – The King of Laziness
  • Structure Sorting in C++
  • Stooge Sort
  • Tag Sort (To get both sorted and original)
  • Tree Sort
  • Odd-Even Sort / Brick Sort
  • 3-way Merge Sort