This is a very wrong idea. This comes at a price since Merge Sort uses additional space to produce a sorted list. If the length of the list is less than or equal to one, then we already have a sorted list and no more processing is necessary. Conclusion Merge Sort works both with a large and small number of elements making it more efficient than Bubble, Insertion and Selection Sort.
Merge two sorted lists You might think that alternatively taking elements from the two sorted lists and putting it together will produce one single sorted list. That does not matter, as the lengths will differ by at most one.
Like all sorting algorithms, we consider a list to be sorted only if it is in ascending order.
Merge sort is a recursive algorithm that continually splits a list in half. Note that when the regrouping happens the sorted order must always be maintained. The first algorithm we will study is the merge sort.
Notice that the merge operation places the items back into the original list alist one at a time by repeatedly taking the smallest item from the sorted lists. It is easy to see how the splitting process eventually yields a list that can be immediately merged with other sorted lists.
The mergeSort function has been augmented with a print statement line 2 to show the contents of the list being sorted at the start of each invocation. Let us see why.