Skip to main contentSkip to solution

Given an array as [22, 20 30, 10, 2, 8]. What will be the position of element 2 after 2 iterations of selection sort and insertion sort, respectively?

Note: Indexing of the array starts from 0.

(A) 0

(B) 3

(C) 4

(D) 5

Solution

✅ Correct Option: 2

The array is read as [22, 20, 30, 10, 2, 8].

Selection sort picks the smallest remaining element each pass and swaps it into place. Insertion sort takes the next element and inserts it into the sorted prefix. This leaves 2 untouched in the second case.

IterationSelection sortInsertion sort
Start[22, 20, 30, 10, 2, 8][22, 20, 30, 10, 2, 8]
1[2, 20, 30, 10, 22, 8] (2 swapped with 22)[20, 22, 30, 10, 2, 8] (20 inserted before 22)
2[2, 8, 30, 10, 22, 20] (8 swapped with 20)[20, 22, 30, 10, 2, 8] (30 already in place)
Index of 204

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question