Sort the following elements using Bubble sort in ascending order. What is the…
2021
Sort the following elements using Bubble sort in ascending order. What is the intermediate sequence of 37, 54, 21, 85, 68, 12, 9, 57 after second pass?
- A.
21, 37, 12, 9, 54, 57, 68, 85
- B.
37, 21, 54, 68, 12, 9, 57, 85
- C.
21, 37, 54, 12, 9, 57, 68, 85
- D.
21, 12, 9, 37, 54, 57, 68, 85
Attempted by 251 students.
Show answer & explanation
Correct answer: C
Initial Array
37, 54, 21, 85, 68, 12, 9, 57
Pass 1
Compare adjacent elements:
37 and 54 → no swap
54 and 21 → swap
54 and 85 → no swap
85 and 68 → swap
85 and 12 → swap
85 and 9 → swap
85 and 57 → swap
After Pass 1:
37, 21, 54, 68, 12, 9, 57, 85
Pass 2
Now compare up to the second-last unsorted element:
37 and 21 → swap
37 and 54 → no swap
54 and 68 → no swap
68 and 12 → swap
68 and 9 → swap
68 and 57 → swap
After Pass 2:
21, 37, 54, 12, 9, 57, 68, 85
So, the intermediate sequence after the second pass is:
21, 37, 54, 12, 9, 57, 68, 85