I have an sorted array of strings: eg: ["bar", "foo", "top", "zebra"] and I want to search if an input word is present in an array or not.
eg:
search (String[] str, String word) {
// binary search implemented + string comaparison.
}
Now binary search will account for complexity which is O(logn), where n is the length of an array. So for so good.
But, at some point we need to do a string compare, which can be done in linear time.
Now the input array can contain of words of different sizes. So when I am calculating final complexity will the final answer be O(m*logn) where
mis the size of word we want to search in the array, which in our case is "zebra" the word we want to search?
O(m)in the worst case, whatevern.