Consider a list of 10 elements: numList = [7,11,3,10,17,23,1,4,21,5]. Display the partially sorted list after three complete passes of Bubble sort.
After three complete passes of Bubble sort, the partially sorted list is: [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]
Explanation
The question asks to trace Bubble sort for 3 passes. Using the algorithm from the context where adjacent elements are compared and swapped if the first is larger, we can trace each pass. In Bubble sort, after each pass, the largest element in the unsorted portion moves to its correct position at the end. The context shows that comparisons continue until the end of the unsorted portion is reached, with the largest element 'bubbling' to the end after each pass.
Solution Steps
Original List: [7, 11, 3, 10, 17, 23, 1, 4, 21, 5]
Pass 1: Compare adjacent elements and swap if first is bigger. 23 bubbles to end. Result: [7, 3, 10, 11, 17, 1, 4, 21, 5, 23]
Pass 2: Continue comparisons. 21 moves to position before 23. Result: [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
Pass 3: Continue comparisons. 17 moves to position before 21. Result: [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]