Assume we want to sort integers into ascending order. To sort a small array that contains 42, 17, selection sort will perform one swap, or three assignments. How many assignments will it perform to sort an array that contains these 10 elements: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0?
a) 15
b) 18
c) 24
d) 27
e) 63

Respuesta :

Answer:

a) 15

Explanation:

Since we are given a list that contains 10  elements [tex][ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0][/tex]

To start with the first iteration:

We substitute element 9 with the least number in the list. In the list 0 is the least number, so by swapping it with 9 we have the list as:

[tex][ 0, 8, 7, 6, 5, 4, 3, 2, 1, 9][/tex]

For the second iteration:

we substitute element 8 with the minimum number in the list, Now the minimum number is 1, so by swapping it with 8 we have the list as:

[tex][ 0, 1, 7, 6, 5, 4, 3, 2, 8, 9][/tex]

For the third iteration:

we substitute element 7 with the minimum number in the list, Now the minimum number is 2, so by swapping it with 7 we have the list as:

[tex][ 0, 1, 2, 6, 5, 4, 3, 7, 8, 9][/tex]

For the fourth iteration:

we substitute element 6 with the minimum number in the list, Now the minimum number is 3, so by swapping it with 6 we have the list as:

[tex][ 0, 1, 2, 3, 5, 4, 6, 7, 8, 9][/tex]

For the fifth iteration:

we substitute element 5 with the minimum number in the list, Now the minimum number is 4, so by swapping it with 5 we have the list as:

[tex][ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9][/tex]

At this point, the array is completely sorted and there is no more room for swapping

Thus, the number of swaps required = 5

The no. of assignment required = 3 × 5

The no. of assignment required = 15

The number of assignments to sort the array of 10 elements is 15

How to determine the number of assignments?

A swap operation involves 2 elements, and 3 assignments.

So, the number of assignments is calculated as:

n = Elements/2 * 3

There are 10 elements in the array.

So, we have:

n = 10/2 * 3

Evaluate the product

n = 15

Hence, the number of assignments to sort the array is 15

Read more about sorting techniques at:

https://brainly.com/question/15049854