If the array A contains the items 10, 4, 7, 23, 67, 12 and 5 in that order,…

2025

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?

  1. A.

    67, 12, 10, 5, 4, 7, 23

  2. B.

    4, 7, 10, 23, 67, 12, 5

  3. C.

    4, 5, 7, 67, 10, 12, 23

  4. D.

    10, 7, 4, 67, 23, 12, 5

Attempted by 229 students.

Show answer & explanation

Correct answer: B

Opt 2 :

Concept:

Insertion sort is the sorting mechanism where the sorted array is built having one item at a time. The analogy can be understood from the style we arrange a deck of cards. This sort works on the principle of inserting an element at a particular position, hence the name Insertion Sort.

Insertion Sort works as follows:

The first step involves the comparison of the element in question with its adjacent element.

And if at every comparison reveals that the element in question can be inserted at a particular position, then space is created for it by shifting the other elements one position to the right and inserting the element at the suitable position.

The above procedure is repeated until all the element in the array is at their apt position.

Explanation:

Array: 10, 4, 7, 23, 67, 12, 5

After 1st pass: 4, 10, 7, 23, 67, 12, 5 – 4 and 10 got swapped or 4 got inserted at its apt position

After 2nd pass: 4, 7, 10, 23, 67, 12, 5 – 7 got inserted at its apt position

After 3rd pass: 4, 7, 10, 23, 67, 12, 5 – No change because the value 10 is placed in its apt position already

Explore the full course: Coding For Placement