Recursive and Iterative Binary Search: Which one is more efficient and why?

With regard to time complexity, recursive and iterative methods both will give you O(log n) time complexity, with regard to input size, provided you implement correct binary search logic.

Focusing on space complexity, the iterative approach is more efficient since we are allocating a constant amount O(1) of space for the function call and constant space for variable allocations, while the recursive approach takes O(log n) space.


There is no different w.r.t Big O analysis between these two versions. Both will run O(logn) if written correctly.
There have been concerns around the recursive program regarding the function stack it is going to use. However, once you see it carefully, the recursive version is a tail recursion. Most of the modern compiler converts the tail recursion into iterative program. Thus, there won't be any issue regarding the usage of the function stack.
Hence, both will run with same efficiency.

Personally, I like the recursive code. It is elegant, easy and maintainable. Binary search is a notoriously difficult algorithm to implement correctly. Even, java library had bug in the implementation.