401 Data Structures and Algorithms

Binary Search

Description

The function called BinarySearch which takes in 2 parameters: a sorted array and the search key. It returns the index of the array’s element that is equal to the search key, or -1 if the element does not exist.

Approach & Efficiency

Iterative solution. Time complexity O(logN), space complexity: O(1)

Solution