COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
How many swaps needed to sort the following numbers using a selection sort.5, 1, 12, -5, 16, 2, 12, 14
|
8
|
|
6
|
|
7
|
|
5
|
Explanation:
Detailed explanation-1: -Expert-Verified Answer Total 18 swapping required to get the bubble sort.
Detailed explanation-2: -Total 10 swaps are required to sort the array.
Detailed explanation-3: -Selection sort performs (at most) n – 1 swaps between data elements, while the bubble sort swaps n * (n – 1) / 2 elements in the worst case (when the list is sorted in reverse order).
Detailed explanation-4: -Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations to sort the given array.
There is 1 question to complete.