Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The insertion sort is applied to [3, 1, 2]. Count the total number of element moves (each shift of an element one place to the right is one move).

  1. A. 3
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: D. 2

Insertion sort shifts 3 right when inserting 1 (one move), then shifts 3 when inserting 2 (one more move), totalling 2 moves.

More Coding Interview Problems questions

Exams that ask this topic