The following algorithm is a version of bubble sort.
Step 1 \quad Store the values to be sorted in locations L(1), L(2), \(\ldots\) , L(n) and set i to be the number, n, of values to be sorted.
Step 2 \quad Set j = 1.
Step 3 \quad Compare the values in locations L(j) and L(j+1) and swap them if that in L(j) is larger than that in L(j+1).
Step 4 \quad Add 1 to j.
Step 5 \quad If j is less than i then go to step 3.
Step 5 \quad Write out the current list, L(1), L(2), \(\ldots\) , L(n).
Step 6 \quad Subtract 1 from i.
Step 7 \quad If i is larger than 1 then go to step 2.
Step 8 \quad Stop.
- Apply this algorithm to sort the following list.
109 \quad 32 \quad 3 \quad 523 \quad 58.
Count the number of comparisons and the number of swaps which you make in applying the algorithm. [4]
- Put the five values into the order which maximises the number of swaps made in applying the algorithm, and give that number. [2]
- Bubble sort has quadratic complexity. Using bubble sort it takes a computer 1.5 seconds to sort a list of 1000 values. Approximately how long would it take to sort a list of 100 000 values? (Give your answer in hours and minutes.) [2]