|
|
Revision:Sorting Algorithms
From The Student RoomTSR Wiki > Study Help > Subjects and Revision > Revision Notes > Mathematics > Sorting Algorithms
Bubble Sort
You may be required to count the number of comparisons and swaps you do in each pass. Here is an example:
Shuttle Sort
The effect of pass n is to pick up item in position n + 1 and insert it in the correct place in the already sorted sublist of the first n items. Shuffle sort cannot be terminated early. The number of passes is always one less than the length of the original list. EfficiencyWe usually measure the efficiency of an algorithm by considering the worst case scenario. For both bubble sort and shuffle sort, this is when the list is in reverse order. In this case, both algorithms use 1 + 2 + 3 + ... + (n-1) comparisons and swaps. Both algorithms are quadratic order because the measure of efficiency is a quadratic function of the size of the list.
For a very large problem, the quadratic term would dominate and the run time would be approximately kn2 for some constant k.
Also SeeSee the other D1 notes:
Comments |















