This same question has been asked here so many times by several people. This is a problem which was asked in an entrance exam.
And I am having difficulties in digesting the correct answer of this problem. Why is my approach incorrect?
Here is my approach:
The divide part of the merge sort recursively divides the list of strings into sub-lists with half number of strings each.
Then the merge part takes sorted lists from two of its child node and merge them into its own sorted list. This merging propagates upwards towards the root and the entire list is eventually sorted.
The merging works this way:
The two child-lists together have $(n1+n2) = O(n)$ strings. And for comparing two strings as the part of merging, we need to compare at most $n$ positions (since the strings are of length $n$).
So the merging takes $\theta(n*n) = \theta(n^2)$
Now the recurrence equation looks like: $T(n)= 2T(n/2) + \theta(n^2)$
Using master method $n^{log_22}=n$
And $f(n)=\theta(n^2)=\Omega(n^{log_22})$
Which is case 3 of Master method. so $T(n)=\theta(f(n))=\theta(n^2)$ should be the correct answer.