comparison of ( sorting algorithms we have now seen three different array based sorting algorithmsall based on different sorting strategiesand all with ( time complexity so one might imagine that it does not make much difference which of these algorithms is used howeverin practiceit can actually make big difference which algorithm is chosen the following table shows the measured running times of the three algorithms applied to arrays of integers of the size given in the top rowalgorithm bubble sort insertion sort selection sort here denotes an array with entries which are already sortedand is an array which is sorted in the reverse orderthat isfrom biggest to smallest all the other arrays were filled randomly warningtables of measurements like this are always dependent on the random ordering usedthe implementation of the programming language involvedand on the machine it was run onand so will never be exactly the same so where exactly do these differences come fromfor startselection sort always makes ( )/ comparisonsbut carries out at most swaps each swap requires three assignments and takesin factmore time than comparison bubble sorton the other handdoes lot of swaps insertion sort does particularly well on data which is sorted already in such caseit only makes comparisons it is worth bearing this in mind for some applicationsbecause if only few entries are out of placeinsertion sort can be very quick these comparisons serve to show that complexity considerations can be rather delicateand require good judgement concerning what operations to count it is often good idea to run some experiments to test the theoretical considerations and see whether any simplifications made are realistic in practice for instancewe have assumed here that all comparisons cost the samebut that may not be true for big numbers or strings of characters what exactly to count when considering the complexity of particular algorithm is always judgement call you will have to gain experience before you feel comfortable with making such decisions yourself furthermorewhen you want to improve the performance of an algorithmyou may want to determine the biggest user of computing resources and focus on improving that something else to be aware of when making these calculations is that it is not bad idea to keep track of any constant factorsin particular those that go with the dominating sub-term in the above examplesthe factor applied to the dominating sub-termnamely varies it is / for the average case of bubble sort and selection sortbut only / for insertion sort it is certainly useful to know that an algorithm that is linear will perform better than quadratic one provided the size of the problem is large enoughbut if you know that your problem has size ofsayat most then complexity of ( / ) will be preferable to one of or if you know that your program is only ever used on fairly small samplesthen using the simplest algorithm you can find might be beneficial overall it is easier to programand there is not lot of compute time to be saved finallythe above numbers give you some idea whyfor program designersthe general rule is to never use bubble sort it is certainly easy to programbut that is about all it has going for it you are better off avoiding it altogether