Reference no: EM1348844
1. Suppose you have an array of n items (the "member items") and a separate list of k items (the "test items"). The member items are not stored in any particular order. You want to know which of the k test items belong to the set of member items. Here are two di?erent ways to solve the problem:
Algorithm 1:
Look up each test item in the array of member items, using sequential search.
Algorithm 2: Sort the array of member items, using an optimal comparison-based sorting algorithm, and then look up each test item in the array of member items using binary search.
Answer the following questions, and brie?y justify your answer to each part.
(a) What is the worst-case running time of Algorithm 1 (asymptotically, in terms of n and k)?
(b) What is the worst-case running time of Algorithm 2 (asymptotically, in terms of n and k)?
(c) For a given value of n, for what values of k is Algorithm 2 at least as e?cient as Algorithm 1? (Express your answer using asymptotic notation, in terms of n).