Suppose sa is a sorted array of integer values, and we wish to search for a number target in this array. If sa contains n elements, and we use the binary search strategy, what is the approximate maximum number of comparisons necessary to determine that the value target is or is not in the array? How would your answer change if the array were not sorted?

What will be an ideal response?


log2 n. But for an unsorted array, the answer would be n.

Computer Science & Information Technology

You might also like to view...

If there exists a class named Person and one wants to create a new class named Student based on the Person class, what code segment below shows the correct way to do so?

a. Public Class Student Inherits Person b. Public Class Student Extends Person c. Public Class Student Inherits From Person d. Public Class Student :Person

Computer Science & Information Technology

What is the difference between the prefix incre- ment operator and the postfix increment operator?

What will be an ideal response?

Computer Science & Information Technology

Check the ____________________ text box in the Print Preview area to make sure your computer is set to the right printer.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Solve the following system using the substitution method or the linear combination method.

A.
B.
C.
D. infinite number of solutions
E. no solution

Computer Science & Information Technology