CS 2401 Quiz based on Test #1

Date: Wednesday, February 23, 2011.

Name: ___________________________________________________________________

3-4. Write Java code for binary search and trace it on the following two examples. In both examples, the list consists of elements 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, and 7.0 (in this order). In the first example, we look for the number 6.0. In the second example, we look for the number 6.1. What is the worst-case complexity of binary search? Explain your answer.

7-8. Suppose that we have a linked list consisting of the elements 2, 15, and 2011, and we have a pointer pointing to the element 15. Show, step by step, how we can delete the element 15 to which the pointer points. Write Java code for deleting an element from the linked list and draw how the corresponding boxes change.