anantdd
anantdd

Reputation: 135

Which sorting algorithm causes minimum disturbance in a given array?

I had got this question on an online portal,

There are 100 people, seated in a row of 100 chairs. You want to sort these people by their first names. However, the individuals are lazy and do not wish to move from their seats. Luckily, you know that of the 100 people, only a few are out of order. In order to disturb the fewest number of people, which algorithm would NOT be ideal?

Options

  1. bubble sort
  2. heap sort
  3. selection sort
  4. merge sort
  5. All of the above are going to upset approximately the same number of people

It seems that Selection Sort should be ideal while others move a lot of people. (I even confirmed it via code).
But that is not a valid option.

So am I wrong, or is the question?

Upvotes: 0

Views: 128

Answers (0)

Related Questions