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?
I got this question as a homework. I know merge sort sorts in O(nlogn) time. For lexicographic order for length in is it n times nlogn ? or n^2 ?
hence solved
Each comparison of the algorithm is
O(n)
[comparing two strings isO(n)
worst case - you might detect which is "bigger" only on the last character], You haveO(nlogn)
comparisons in mergesort.Thus you get
O(nlogn * n) = O(n^2 * logn)
But according to the recurrence relation
T(n) = 2T(n/2) + O(m*n)
Will be T(n) = 2T(n/2) + O(n^2) when m = n
Then the result will be O(n^2) and not O(n^2logn).
Correct me if I'm wrong.
Time complexity recurrence relation is
So clearly the height of tree would be logn. Thus time complexity is O(n^2*logn).