Question: There is an array of strings, and each string in the array is sorted alphabetically; then the entire array of strings is sorted lexicographically. Time complexity of the whole operation?
analyze:
1. Assume the longest string length is s; there are n strings in the array
2. Sort each string: O(slogs)
3. Sort each string in the array alphabetically: O(n*slogs)
4. Sort the entire string array lexicographically: O(s*nlogn)
comprehensive:
Overall time complexity O = O(n slogs) + O(s nlogn) = O(n slogs+s nlogn) = O(n s (logn+logs))