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.
- A.
Only statement 1 is correct
- B.
All statements are correct
- C.
Statement 3 is not correct
- D.
Only statement 1 and 2 is correct
Attempted by 231 students.
Show answer & explanation
Correct answer: B
Statement 1 is correct: Insertion Sort and Merge Sort preserve the relative order of equal elements, making them inherently stable.
Statement 2 is correct: Heap Sort uses a heap tree structure where non-adjacent elements are swapped, making it inherently unstable.
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.