A binary search algorithm is one of the most important searching algorithm, user on sorted arrays. This algorithm searches for a given number (value) in an array A. How does the algorithm works ?1) check if the left is lower than right (if it is, the value is not in the array)2) compute the middle of the array3) check if the element in the middle is the number we are looking for (if true, return the position)4) compare the element in the middle with the value we are looking forif the value is lower, we are going to search in the left part of the arrayif the value is bigger, we are going to search in the right part of the array5) back to step 1, until left > right or a value is found.
BinarySearch(array A, value, left, right) { if(left > right) return "not found" mid = (left + right)/2; if(A[mid] == value) return value; if(A[min] > value) return BinarySearch(array A, value, left, mid - 1) else return BinarySearch(Array A, value, mid + 1, right)}