Describe how a binary search algorithm works. Write a recursive and an iterative version of the algorithm.