What is the total number of swaps performed to sort the following list of…
2023
What is the total number of swaps performed to sort the following list of elements 18, 32, 17, 19, 41, 15, 23 in an ascending order, using bubble sort?
- A.
12
- B.
13
- C.
10
- D.
11
Attempted by 105 students.
Show answer & explanation
Correct answer: C
In bubble sort, the number of swaps equals the number of inversions in the list. For 18, 32, 17, 19, 41, 15, 23 there are 10 inversions, so 10 swaps are performed.