Binary Search Iterative vs Recursive

Out of iterative Binary search and recursive binary search which one should I use in codes and why?

@tomarvikas738 It on you choose that one in which you have more confidence

Iterative binary search is likely to have lower constant factors because it doesn’t involve the overhead of manipulating the call stack. Recursive May reach to log(n) space (because of the stack), in iterative BS it should be O(1) space complexity.However, a recursively-written binary search may be optimized by the compiler to an iterative version. In this case, there won’t be much difference.

1 Like