Data Structures & AlgorithmsHardAccenture · Infosys OA
Problem: Which best explains why merge sort is preferred over quicksort for sorting linked lists (as opposed to arrays)?
- A. There is no difference; both perform identically on linked lists
- B. Quicksort cannot be implemented on linked lists at all
- 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
- 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
- Problem: Which best explains the time complexity difference between recursive (top-down with memoization) and iterative (bottom-up…
- Problem: What is the time complexity of building a trie from n words with total character count L, and what is the space complexity?
- Problem: A problem is solved via binary search on the answer (not on an array index) -- e.g. 'minimum capacity to ship packages within D…
- Problem: Which of these is the correct worst-case time complexity of building a max-heap from an array of n unsorted elements using the…
- Problem: In a graph represented with an adjacency list, what is the space complexity, and how does it compare to an adjacency matrix for a…
- Problem: Which best explains why the greedy 'interval scheduling to maximize the number of non-overlapping intervals' problem is solved…