Trace through the bubble-sort and selection-sort algorithms on the following data. Indicate also the number of array element comparisons and swaps for each case.
2 7 1 4 3 6
Bubble-Sort
| i | j start | j end | 2 7 1 4 3 6 (initial) | comps | swaps |
|---|---|---|---|---|---|
| 0 | 5 | 1 | 1 2 7 3 4 6 | 5 | 3 |
| 1 | 5 | 2 | 1 2 3 7 4 6 | 4 | 1 |
| 2 | 5 | 3 | 1 2 3 4 7 6 | 3 | 1 |
| 3 | 5 | 4 | 1 2 3 4 6 7 | 2 | 1 |
| 4 | 5 | 5 | 1 2 3 4 6 7 | 1 | 0 |
| Total : | 15 | 6 | |||
Selection-Sort
| Begin | Check start | Check end | 2 7 1 4 3 6 (initial) | comps | swaps |
|---|---|---|---|---|---|
| 0 | 1 | 5 | 1 7 2 4 3 6 | 5 | 1 |
| 1 | 2 | 5 | 1 2 7 4 3 6 | 4 | 1 |
| 2 | 3 | 5 | 1 2 3 4 7 6 | 3 | 1 |
| 3 | 4 | 5 | 1 2 3 4 7 6 | 2 | 1 |
| 4 | 5 | 5 | 1 2 3 4 6 7 | 1 | 1 |
| Total : | 15 | 5 | |||