A company database has 10,000 customers sorted by last name, 20% of whom are known to be good customers. Under typical usage of this database, 60% of lookups are for the good customers. Two design options are considered to store the data in the database:
Put all the names in a single array and use binary search.
Put the good customers in one array and the rest of them in a second array. If we do not find the query name on a binary search of the first array, we do a binary search of the second array.
Given these options, answer the following.
i. Calculate the expected worst-case performance for each of the two structures above, given typical usage. Which of the two structures is the best option?
In the worst case for binary search, when the value is not in our array, the algorithm must continue iterating until the span has been made empty; this will have taken at most $log2(N)+1$ iterations. In our situation, it is $log2(10000)+1 = 13.28+1 = 14.28 = 15$? Not sure i'm on the right track. How does 20% of 10000 are good customers and 60% lookups are for good customers taking into account this problem?
ii. Suppose that over time the usage of the database changes, and so a greater and greater fraction of lookups are for good customers. At what point does the answer to part i change?
iii. Under typical usage again, suppose that instead of binary search we had used linear search. What is the expected worst-case performance of each of the two structures and which is the better option? Where is the cross-over this time?