GATE / CS ARCHIVE

GATE CSE 2012 / QUESTION 39

Merge-sorting equal-length strings

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2012 paper

GATE 2012, Q39 2 marks · MCQ
Report issue

Searching, Sorting & Selection

Question 39, GATE 2012: A list of n strings, each of length n, is sorted lexicographically using mergesort. What is the worst-case running time?
(A) O(n log n) (B) O(n² log n) (C) O(n²+log n) (D) O(n²).
Tap to enlarge
Your answer
Answer & solution

Official answer: Marks to All

Our answer: B under the standard character-comparison model

Ordinary mergesort uses O(n log n) comparisons to sort n strings. A lexicographic comparison can inspect all n characters, so the standard upper bound is O(n² log n), option B. The bound is tight in the usual character-by-character implementation: strings can share a prefix of length n−O(log n) and have suitably ordered distinct suffixes, so a worst-case merge pattern performs Θ(n log n) comparisons each costing Θ(n). Treating entire strings as unit-cost keys, using LCP-aware comparison, or restricting how many distinct strings exist changes the analysis; those are extra models not specified. The official entry remains Marks to All. No official reason for awarding marks is asserted.

Check: At each merge level O(n) string comparisons may be needed, and there are Θ(log n) levels. Multiplying by the worst-case Θ(n) character work per comparison gives Θ(n² log n) under the ordinary implementation, rather than counting comparisons as constant-time operations.

Original paper, page 10 · Answer key