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.
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
As the function naming implies, solution A is "iterative", and solution B is "recursive". I choose solution A as the better performer because iteration is usually faster than its recursive counterpart.
http://stackoverflow.com/questions/15688019/recursionversusiteration gives a nice description of why that is the case (in short, recursion needs to perform more memory allocation).
The existence of tail call optimisation in the language could speak in favor of recursion, but according to this SO post, you can't rely on Ruby to do tail call optimisations.
But, is solution A not just fast but precise as well?
As there are two solutions are given, I choose first one which is iterative as it required less space and faster then its recursive counter part