Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE

Problem: Merge sort's merge step in Java uses `if (a[i] < b[j]) take a[i]; else take b[j];`. What property is lost compared with `<=`?

  1. A. Correct sorting – the output may be unsorted
  2. B. Stability – equal keys from the right half can jump ahead of equal keys from the left half
  3. C. O(n log n) time – it becomes O(n²)
  4. D. Nothing – both are identical for every input

Correct answer: B. Stability – equal keys from the right half can jump ahead of equal keys from the left half

On ties, < takes from the right half first, so equal elements change relative order. The result is still sorted and still O(n log n), but stability matters when sorting records by multiple keys.

More Coding Interview Problems questions

Exams that ask this topic