If the array A contains the items 10, 4, 7, 23, 67, 12 and 5 in that order,…
2021
If the array A contains the items 10, 4, 7, 23, 67, 12 and 5 in that order, what will be the resultant array A after third pass of insertion sort?
- A.
67, 12, 10, 5, 4, 7, 23
- B.
4, 7, 10, 23, 67, 12, 5
- C.
4, 5, 7, 67, 10, 12, 23
- D.
10, 7, 4, 67, 23, 12, 5
- E.
Question not attempted
Attempted by 304 students.
Show answer & explanation
Correct answer: B
Insertion sort works by building a sorted portion of the array one element at a time. In each pass, the next unsorted element is inserted into its correct position in the already sorted portion. Initial array: 10, 4, 7, 23, 67, 12, 5 Pass 1: Compare 4 with 10. Since 4 < 10, swap them. Array becomes: 4, 10, 7, 23, 67, 12, 5 Pass 2: Compare 7 with 10 and 4. 7 > 4 but 7 < 10, so insert 7 after 4. Array becomes: 4, 7, 10, 23, 67, 12, 5 Pass 3: Compare 23 with 10, 7, and 4. 23 > 10, so it stays in place. Array becomes: 4, 7, 10, 23, 67, 12, 5 After the third pass, the first four elements are sorted: 4, 7, 10, 23. The remaining elements are not yet processed.