You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a function called BinarySearch which takes in 2 parameters: a sorted array and the search key. Without utilizing any of the built-in methods available to your language, return the index of the array’s element that is equal to the search key, or -1 if the element does not exist.
Approach & Efficiency
Approach
Pass array and value into function
Declare a direction value
Find and declare midpoint
Check if the midpoint matches the value
Detect direction based on left and right of midpoint
While-loop to go in the direction until array end and test for match