2: Imagine if a phone book was not in order and had one name per page. If there are only a few names, it
doesn't make sense to sort it. If we use it many times, or there are lots of names, it makes sense to sort it
once, and then search, since our search will be much faster.
If we have 10,000 names, how many times do we need to search before Sort+Binary search makes
sense over Sequential Searchs? If we are going to be searching our phone 1,000,000 times, how big
does it need to be for sorting to be worth it? Answer the questions below.
As explained in class, sequential search is where we simply iterate through all records until we find what
we're looking for. If we sort our records first, we can do binary search, pseudocode for which is supplied
in the notes.
a. Write the formula for the number of steps to perform k sequential searches on a list of size n
f(n,k) =
b. Write the formula for the number of steps to perform k binary searches on a list of size n
g(n,k) =
c. If we have 10,000 names, how many times do we need to search before Sort+Binary search makes
sense (e.g. is less than) over sequential search?
I.e. solve $f(10,000,k) < g(10,000,k)$ (I recommend wolfram alpha!)
c. If we are searching 1,000,000 times, how big does the list need to be to make sorting worth it?
I.e. solve $g(n,1,000,000) < f(n,1,000,000)$