There are many types of sorting, like bubble sort, selection sort and insertion sort. In CSC108, we learned selection sort and insertion sort. In CSC148, we learned two new sorting called quick sort and merge sort.
Quick sort is the idea to choose a pivot, decide where the pivot goes with respect to the rest of the list and then repeat on the partitions. Merge sort is the idea to divide the list in half, (merge) sort the halves, then merge the sorted results.
Here are the examples for the two sorting method.
Depends on the different ways we sort, the problem of efficiency appears.
For efficiency, "Big O" is used. Here is a description of "Big O" on wikipedia:
Big O notation has two main areas of application. In mathematics, it is commonly used to describe how closely a finite series approximates a given function, especially in the case of a truncated Taylor series or asymptotic expansion. In computer science, it is useful in the analysis of algorithms.
Big O notation is useful when analyzing algorithms for efficiency. For example, the time (or the number of steps) it takes to complete a problem of size n might be found to be T(n) = 4n2 − 2n + 2. As n grows large, the n2 term will come to dominate, so that all other terms can be neglected—for instance when n = 500, the term 4n2 is 1000 times as large as the 2n term. Ignoring the latter would have negligible effect on the expression's value for most purposes. Further, the coefficients become irrelevant if we compare to any other order of expression, such as an expression containing a term n3 or n4. Even if T(n) = 1,000,000n2, if U(n) = n3, the latter will always exceed the former once n grows larger than 1,000,000 (T(1,000,000) = 1,000,0003= U(1,000,000)). Additionally, the number of steps depends on the details of the machine model on which the algorithm runs, but different types of machines typically vary by only a constant factor in the number of steps needed to execute an algorithm. So the big O notation captures what remains: we write either
Well, this is how "Big O" works.
And I will show an example of "Big O" by merge sort:
Therefore, sorting helped us to makes objects listed in some kind of order. And efficiency of sorting helped us to choose the most efficient to sort elements.