COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
We are sorting the following list in descending order:1 4 2 9 3 8 5 What does the list look like after one pass of the selection sort algorithm.
|
1 4 2 9 3 8 5
|
|
9 4 2 1 3 8 5
|
|
4 2 9 3 8 5 1
|
|
None of the above
|
Explanation:
Detailed explanation-1: -Stable sort for descending order.
Detailed explanation-2: -In general, the average number of comparisons per pass in selection sort will always be one half of the number of items to be sorted. For eight items, we have 1/2(82 + 8) = 1/2(64 + 8) = 1/2(72) = 36 comparisons.
Detailed explanation-3: -Step 1: Set Min to location 0 in Step 1. Step 2: Look for the smallest element on the list. Step 3: Replace the value at location Min with a different value. Step 5: Continue until the list is sorted.
There is 1 question to complete.