Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

GATE | GATE CS 2012 | Question 37

  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021

A list of n strings, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
(A) O(n log n)
(B) O(n2 log n)
(C) O(n2 + log n)
(D) O(n2)

Answer: (B)


When we are sorting an array of n integers, Recurrence relation for Total number of comparisons involved will be,

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

T(n) = 2T(n/2) + (n) where (n) is the number of comparisons in order to merge 2 sorted subarrays of size n/2.
= (nlog2n)

Instead of integers whose comparison take O(1) time, we are given n strings. We can compare 2 strings in O(n) worst case. Therefore, Total number of comparisons now will be (n2log2n) where each comparison takes O(n) time now.

In general, merge sort makes (nlog2n) comparisons, and runs in (nlog2n) time if each comparison can be done in O(1) time.

See question 5 of

This solution is contributed by Pranjul Ahuja

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :