At Westonci.ca, we connect you with the best answers from a community of experienced and knowledgeable individuals. Get quick and reliable solutions to your questions from a community of experienced professionals on our platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

An array similar to a phone book has 1000 names arranged as names [0], names[1]....names[999]. Nancy wants to search a name X in this array. Which of the following preconditions must she ensure to perform a binary search?

The list has a large number of names.
The name X is present in the list.

In addition to the two statements above, which of the following is correct?

a. There should be no duplicates in the list.
b. The names in the list should be alphabetical order.
c. The name X should occur near the middle of the list.

Sagot :

Answer:

Preconditions that she must ensure to perform a binary search are:

The list has a large number of names.

The name X is present in the list.

c. The name X should occur near the middle of the list.

Explanation:

Nancy's binary search for a name X should begin by comparing an element in the middle of the array or list with the name X (target value). If this name X's value matches the value of an element in the list, Nancy must return its position in the array.  If the name X's value is less than the element's value, Nancy will continue the search in the lower half of the array.  Usually, the name X should occur near the middle of the list or array.