Question: In this part, you will find an expression for the number of comparisons made using oddeven sort to sort a list of length n, and
In this part, you will find an expression for the number of comparisons made using oddeven sort to sort a list of length n, and compare its efficiency with bubble sort 1. First consider the figure below. Described image Figure 3 Figure 3 Figure 3(a) shows the four passes required to sort four items. The dots represent the items and the horizontal lines the comparisons between pairs of items. Notice that there are four rows of four dots and all the dots are matched with another dot, representing a comparison, except the four ringed ones. There are therefore 4 4 4 matched dots and each pair of dots corresponds to a comparison. So, we can divide this number by 2 to find that the number of comparisons is (4 4 4) / 2 = 6. In a similar way, Figure 3(b) shows the five passes required to sort five items. There are now five rows of five dots and all the dots are matched with another dot, except the five ringed ones. This means there are 5 5 5 matched dots and therefore (5 5 5) / 2 = 10 comparisons. Generally, this pattern holds: for n items, there will be n n dots, and exactly n dots will be unmatched. i.Write down an expression for the number of comparisons oddeven sort requires to sort n items. ii.Use your expression to calculate how many comparisons oddeven sort requires to sort 100 items. iii.The number of comparisons bubble sort 1 requires for n items is (n 1)2. What conclusion can you draw about the relative efficiency of the two algorithms, bubble sort 1 versus oddeven sort?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
