previous | start | next

Self Check

  1. Suppose you need to look through a sorted array with 1,000,000 elements to find a value. Using the binary search algorithm, how many records do you expect to search before finding the value?
  2. Why is it useful that the Arrays.binarySearch method indicates the position where a missing element should be inserted?
  3. Why does Arrays.binarySearch return -k - 1 and not -k to indicate that a value is not present and should be inserted before position k?

previous | start | next