What will be the output list after completing first pass of bubble sort on…
2022
What will be the output list after completing first pass of bubble sort on input array 32, 51, 27, 85, 66, 23, 13, 57 ?
Answer: A. 32, 27, 51, 66, 23, 13, 57, 85 — After the first pass, the largest element (85) has been swapped repeatedly until it reached the final index. Here is the trace: (32, 51) → No swap. (51, 27) →…
- A.
32, 27, 51, 66, 23, 13, 57, 85
- B.
32, 51, 27, 66, 23, 13, 57, 8
- C.
27, 33, 51, 23, 13, 57, 66, 85
- D.
23, 13, 27, 33, 51, 57, 66, 85
Attempted by 689 students.
Show answer & explanation
Correct answer: A
After the first pass, the largest element (85) has been swapped repeatedly until it reached the final index. Here is the trace:
(32, 51) → No swap.
(51, 27) → Swap: 32, 27, 51, 85...
(51, 85) → No swap.
(85, 66) → Swap: 32, 27, 51, 66, 85, 23...
(85, 23) → Swap: 32, 27, 51, 66, 23, 85, 13...
(85, 13) → Swap: 32, 27, 51, 66, 23, 13, 85, 57...
(85, 57) → Swap: 32, 27, 51, 66, 23, 13, 57, 85.