edited by
28,808 views
72 votes
72 votes

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

  1. $O (n \log n) $
  2. $ O(n^{2} \log n) $
  3. $ O(n^{2} + \log n) $
  4. $ O(n^{2}) $
edited by

14 Answers

1 votes
1 votes
Actually you can think of it as:

$T(n^{2})=2T(\frac{n^{2}}{2})+n^{2}$
 

Work done will be to merge two strings of $\frac{n^{2}}{2}$.

With condition T(n)=1, because strings of length ‘n’ are already sorted.

Now it is pretty straight forward. $O(n^{2}logn)$
1 votes
1 votes

Hope this helps
the key concept  was element here is " n length string " (but in merge sort we studied element was a 1 length entity)

 This is how the recurrence relation will be:-

 

 

0 votes
0 votes
Since worst case time complexity of merge sort is O(nlogn) for a given string of length n. For n such strings we have to run an iterative loop n times,one for each performing worst case merge sort on a single string. So, complexity is given as O(n*nlogn)=O(n2logn)
0 votes
0 votes
merge sort take $mlogm$

total no.=n*n

           =n^{2}.

m=no. of elemets

n^{2}logn^{2}$total no.=n*n=n^{2}.

mlogm=n^{2}logn^{2} =2*n^{2}logn$$
Answer:

Related questions

59 votes
59 votes
5 answers
2
42 votes
42 votes
4 answers
3
35 votes
35 votes
3 answers
4
gatecse asked Aug 5, 2014
15,612 views
The recurrence relation capturing the optimal execution time of the $Towers \ of \ Hanoi$ problem with $n$ discs is$T(n) = 2T(n − 2) + 2$$T (n) = 2T(n − 1) + n$$T (...