Consider the following statements 1. Insertion Sort and Merge Sort are stable.…

2020

Consider the following statements

1. Insertion Sort and Merge Sort are stable.
2. Heap Sort is inherently unstable.
3. Selection Sort is not inherently stable, but may be coded in such a way that it is stable.

  1. A.

    Only statement 1 is correct

  2. B.

    All statements are correct

  3. C.

    Statement 3 is not correct

  4. D.

    Only statement 1 and 2 is correct

Attempted by 231 students.

Show answer & explanation

Correct answer: B

  1. Statement 1 is correct: Insertion Sort and Merge Sort preserve the relative order of equal elements, making them inherently stable.

  2. Statement 2 is correct: Heap Sort uses a heap tree structure where non-adjacent elements are swapped, making it inherently unstable.

  3. Statement 3 is correct: Standard Selection Sort is unstable due to long-distance swaps, but it can be made stable by changing the swapping mechanism to an insertion-like shift.

Therefore, all statements are correct. The correct option is B.

Explore the full course: Coal India Management Trainee