Consider the following sorting algorithms: (i) Bubble sort (ii) Insertion sort…
2024
Consider the following sorting algorithms:
(i) Bubble sort
(ii) Insertion sort
(iii) Selection sort
Which ONE among the following choices of sorting algorithms sorts the numbers in the array [4, 3, 2, 1, 5] in increasing order after exactly two passes over the array?
- A.
(i) only
- B.
(iii) only
- C.
(i) and (iii) only
- D.
(ii) and (iii) only
Attempted by 186 students.
Show answer & explanation
Correct answer: B
Answer: Selection sort.
Why this is correct:
Pass 1 (select minimum from entire array): minimum is 1, swap with first element → [1,3,2,4,5].
Pass 2 (select minimum from rest): minimum in positions 1..4 is 2, swap with position 1 → [1,2,3,4,5].
After these two passes the whole array is in increasing order, so selection sort achieves the goal in exactly two passes.