Skip to main contentSkip to solution

Consider the following list of six elements:

numList= [8, 7, 13, 1, -9, 4]

Arrange the following output after each pass in increasing order of passes after applying insertion sort on the above list.

(A) [1, 7, 8, 13, -9, 4]

(B) [-9, 1, 4, 7, 8, 13]

(C) [7, 8, 13, 1, -9, 4]

(D) [-9, 1, 7, 8, 13, 4]

Solution

✅ Correct Option: 1

Insertion sort takes each element in turn and inserts it into its correct place in the sorted part on its left.

PassElement insertedList after the pass
17[7, 8, 13, 1, -9, 4] (C)
213[7, 8, 13, 1, -9, 4] (no change, so same as C)
31[1, 7, 8, 13, -9, 4] (A)
4-9[-9, 1, 7, 8, 13, 4] (D)
54[-9, 1, 4, 7, 8, 13] (B)

The order is (C), (A), (D), (B).

Passes 1 and 2 give the same list because 13 is already larger than 8, so nothing moves in pass 2.

Keyboard Shortcuts

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