Whenever we are dealing with a collection of data (whether a list or an array), we might need algorithms to sort the data in order to make other operations faster. For example, searching an element from a list or merging two lists into one work best when the lists are sorted. If the data is sorted, it also makes tasks such as generating human-readable reports easy.
There are many algorithms for sorting a list or an array. In this chapter, we'll try to explain a few of the most commonly used sorting algorithms and how they work internally. The algorithms we are going to discuss here are as follows:
- Bubble sort
- Selection sort
- Insertion sort
- Merge sort
- Quick sort
- Heap sort