I'm looking at Cracking the Coding Interview 6th edition page 49, example 8.
Suppose we have an algorithm that took in an array of strings, sorts each string, and then sort the full array. What would the runtime be?
If the length of the longest string is s and length of the array is a, the book says sorting each string would be:
O(a*s log s)
What I understand is the complexity depends on the upper bound in this case, so it should be:
O(s log s)
For example, if s is the length of longest string and s1, s2, s3 are lengths other strings, the complexity would be:
O(s log s + s1 log s1 + s2 log s2 + s3 log s3)
which is ultimately:
O(s log s)
because value of s is the highest. Why do we need to multiply if with a?