edited by
29,203 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

6 votes
6 votes
5 answers
1
admin asked Mar 31, 2020
1,645 views
Merge sort uses :Divide-and-conquerBacktrackingHeuristic approachGreedy approach
48 votes
48 votes
2 answers
2
Kathleen asked Sep 23, 2014
22,950 views
If one uses straight two-way merge sort algorithm to sort the following elements in ascending order: $20, \ 47, \ 15, \ 8, \ 9, \ 4, \ 40, \ 30, \ 12, \ 17$then the o...