Question
A list of strings, each of length , is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
Official answer and solution
- Official answer
- Marks to all
- From
- Official GATE 2012 answer key
Official GATE answer key awarded Marks to All for this question.
Solution
Multiply the number of comparison operations in Merge Sort by the character comparison cost between strings of length n.
-
Standard merge sort on a list of elements makes at most element comparisons in the worst case.
-
Comparing two strings of length to establish lexicographic order takes character comparisons in the worst case (when they share a long common prefix).
-
Multiplying the number of element comparisons by the time required per comparison gives:
- Reason for Marks to All: Standard big- represents an asymptotic upper bound. Although is the tight bound corresponding to option (B), differing conventions regarding whether in the options referred to string length or total input size prompted GATE to award Marks to All.
Marks to All (Tight worst-case complexity is O(n^2 log n), Option B; full credit given to all candidates).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2012 Computer Science and Information Technology (CS)
- Question
- 39 of 65, printed as CS Q.39
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.