Implement a function to perform a binary search on a sorted array.

Instruction: Write a function that performs a binary search on a sorted array and returns the index of the element if found, otherwise -1.

Context: This question assesses the candidate's algorithm skills and their ability to implement efficient search algorithms.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

For a dense array of finite numbers sorted in ascending order and a finite numeric target, binary search repeatedly halves the candidate index interval...

Related Questions