Question

A binary search function is returning -1 (not found) even when the target element is present in the array. The array is sorted. Which of the following is a common debugging pitfall related to the low and high pointers or loop condition?

A The mid calculation (low + high) / 2 causes an integer overflow for very large low and high values.
B The while loop condition is while (low < high) instead of while (low <= high).
C The low pointer is updated to mid instead of mid + 1.
D The high pointer is updated to mid instead of mid - 1.
E The array is not checked for emptiness before starting the search.
Practice Next

Hey! Ask a query