Binary search

Binary search is a search algorithm that finds the position of a target value within a sorted array. It compares the target value to the middle element of the array. Therefore, if they are unequal, the search continues on the remaining half until it is successful or the remaining half is empty.

Solutions A and B are explanations to the Binary Search described above. Choose the solution that gives a faster output and explain why.

Solution A
 ``def iterative_bsearch(a, value)`` `` low, hi = get_limits(a)`` `` while low < hi`` `` mid = (low + hi) / 2`` `` if a[mid] == value`` `` return mid`` `` elsif a[mid] < value`` `` low = mid + 1`` `` else`` `` hi = mid`` `` end`` `` end`` `` false`` ``end``

Solution B
 ``def recursive_bsearch(a, value)`` `` low, hi = get_limits(a)`` `` if low >= hi`` `` return false`` `` end`` `` mid = (low + hi) / 2`` `` if a[mid] == value`` `` mid`` `` elsif a[mid] < value`` `` recursive_bsearch(a[(mid+1)..hi], value)`` `` else`` `` recursive_bsearch(a[low..mid], value)`` `` end`` ``end`` ``def get_limits(a)`` `` [0, a.length - 1]`` ``end``