What is sorting?

Sorting involves organizing elements in ascending or descending order. For example, we sort playing cards by value to make it easier to find the ones we need. Understanding sorting algorithms is the first step towards understanding algorithm analysis. Many sorting algorithms have been developed and analyzed.

Example

When we visit a library, the books are organized into streams (“Algorithms,” “Operating Systems,” “Networking,” and so on). Sorting arranges data components in a logical order to make searching simpler. It’s much easier to find a book we’re seeking when the books are put in appropriate indexing order.

Types of sorting

Internal sorting

In internal sorting, all items are read into memory simultaneously and the sorting is done in memory. Some common internal sorting algorithms are listed below:

  • Selection sort
  • Insertion sort
  • Bubble sort
  • Quicksort
  • Heap sort

External sorting

In external sorting, we sort the data in chunks because the complete dataset is too large to be loaded in memory simultaneously. An example of an external sort is the merge sort.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.