CS 2401 Quiz based on Test #1

Date: Thursday, February 24, 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, 1, 2, 3, 4, 5, 6, and 7 (in this order). In the first example, we look for the number 6. In the second example, we look for the number 8. What is the worst-case complexity of binary search? Explain your answer.



















































5-6. Write a Java method for computing the sum of all the elements of a 2-D array of size m times n. What is the computational complexity of this method?