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.

Official answer available

Preview the opening of the answer, then unlock the full walkthrough.

To clarify the question, you're asking me to write a function that efficiently searches for a specific element in a sorted array using the binary search technique. The function should return the index of the element if it's found, and -1 if it's not. Correct?

Here's how I would approach this problem:...

Related Questions