Data Structures & AlgorithmsHardAccenture · Infosys OA

Problem: Which best explains why merge sort is preferred over quicksort for sorting linked lists (as opposed to arrays)?

  1. A. There is no difference; both perform identically on linked lists
  2. B. Quicksort cannot be implemented on linked lists at all
  3. C. Merge sort doesn't need random access for its merge step (sequential pointer traversal suffices), while quicksort's partitioning benefits heavily from O(1) random access, which linked lists lack
  4. D. Merge sort uses less memory than quicksort on linked lists

Correct answer: C. Merge sort doesn't need random access for its merge step (sequential pointer traversal suffices), while quicksort's partitioning benefits heavily from O(1) random access, which linked lists lack

Merge sort's merge step only ever needs the next node of each sublist (sequential access), which linked lists provide naturally; quicksort's partition step repeatedly needs to compare and swap arbitrary elements, which is far more costly without O(1) indexing.

More Coding Interview Problems questions

Exams that ask this topic