Advertisements
Advertisements
Question
Consider the following unsorted list:
10 5 55 13 3 49 36
Write the position of elements in the list after:
- 5th iteration of bubble sort
- 7th iteration of insertion sort
- 4th iteration of selection sort
Long Answer
Advertisements
Solution
Initial list: [10, 5, 55, 13, 3, 49, 36]
| Sorting method and iteration | Position/status of elements |
|---|---|
| (a) Bubble sort — 5th iteration | [3, 5, 10, 13, 36, 49, 55] |
| (b) Insertion sort — 7th iteration | [3, 5, 10, 13, 36, 49, 55] |
| (c) Selection sort — 4th iteration | [3, 5, 10, 13, 55, 49, 36] |
Note: In the usual insertion-sort implementation, a list of seven elements has six insertion passes because the first element is already considered sorted. If the first element is counted as iteration 1, the 7th iteration gives the fully sorted list shown above.
shaalaa.com
Is there an error in this question or solution?
