Chapter 13. Sorting
In a chaotic environment, we look for events that are ordered and follow some rules in order to understand them. An ordered environment also helps in searching and choosing elements according to our requirements for a specific purpose.
Sorting can be in an increasing order (not decreasing when the data list has duplicate elements), and it can be in a decreasing order too. Remember the queue of students in school in the increasing order of height in parades, sorting a deck of cards to get the required card in a shorter time while playing cards?
A sorting algorithm arranges the elements of a collection in some order, generally, in either increasing or decreasing order. A sorting algorithm requires the comparison of elements and putting them in a required order. So, a sorting algorithm involves comparison and swapping of elements. Whenever we think of the complexity of a sorting algorithm, we think in the context of the number of comparisons and number of swaps. If the number...