The GATE Grind

GATE 2012 CS (CS1) – Question 49

Algorithms · Searching, Sorting and Hashing · 2 marks · MTA

Merge sort lexicographically sorts n strings, each of length n. What is the worst-case running time?

  1. $O(n\log n)$
  2. $O(n^2\log n)$
  3. $O(n^2+\log n)$
  4. $O(n^2)$

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: MTA

Explanation

The official final key gives marks to all. In a straightforward comparison implementation, merge sort makes O(n log n) comparisons and each string comparison can inspect n characters, giving O(n² log n), intended B. With longest-common-prefix information, repeated character scanning can be reduced; the problem does not specify string-comparison implementation or reuse. Preserve universal credit.

More Searching, Sorting and Hashing questions

All Searching, Sorting and Hashing questions →