-
There are many methods, or algorithms, for doing this. They differ in the length of the code written in a programming language (Python, Fortran, C++, Basic…), but above all in their performance. The time required to complete a sort is crucial: if sorting a hundred data items already takes ten minutes, handling more data will be difficult! A parameter called time complexity measures the number of elementary operations performed to sort the data; this naturally provides an estimate of the algorithm's running time. The complexities generally used are the average-case complexity (calculated over all data sets) and the worst-case complexity (calculated for the least favorable data set). If n is the size of the data set, the complexities of standard algorithms are of order n2 (in Landau notation, we write O(n2)), or, better still, of order n log n (that is, O(n log n)). Of course, this does not give the exact running time, but it does show, for example, that if the number of data items is multiplied by 100, the computation time is multiplied by 10,000 in the first case and by 200 in the second. Although this is not the only criterion, it certainly gives us something to think about when choosing a method!
Sorting rows and columns --------------------------------
Using a spreadsheet raises some entertaining questions about inequalities. Given a table containing several values, we can sort each column (using a macro if the table is very large). We can then sort each row. But won't sorting the rows disrupt the ordering of the columns? Fortunately, the answer is no!