Document on sorting
This should be equivalent to taking a course in sorting. Learning about the different sorting algorithms and time complexity of each one. Compare them and note the differences. Implement all of the algorithms listed below
-
Insertion Sort ― get element in the right place. It has average case of O(n^{2}). But it's efficient for small input sizes. As in the subject, extreme test is500. By pushing everything tostack B(except for three elements, which will be sorted in ascending order). Then by optimizing the cost of pushing an elementeback tostack A(usingpa), brute-force* on the group of available ranges, with priority to the open ranges, whereefits withinstack A. Using this process, we have picked the elementewith the smallest cost and the closest range.(*) The brute-force means iterating over all elements, counting the costs of the current range (starting from boundaries and going to the middle.
-
Merge Sort ― also divide and conquer using mid, but this time we shall keep going until we're left with either two or 1 element. repeat the same process backward, and merge every element in the right order. it's the ultimate sorting when it comes to complexity. It's has worst and best cases of O(nlog).NOTE: Merge Sort is very handy for sorting lists, since it does not require many movements back and forth, but instead, we can only re-order the
nextpointers when we satisfy the condition of splitting (either 1 or two elements). -
Quick Sort ― divide and conquer using mid, send everything that's relatively ordered tostack B, sort highest part, then sort the lowest. Although it has worst case ofO(n^2), it still a good algorithm since it's average isO(nlogn)Still need to document more.