What is the space complexity of the iterative version of binary search on an array?
Options
- A. O(1)
- B. O(log N)
- C. O(N)
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. O(1)
The iterative version of binary search generally requires O(1) auxiliary space. It uses a small number of variables such as low, high, and mid to maintain the current search range. A recursive implementation can require O(log N) stack space because recursive calls are stored on the call stack. Thus, iterative and recursive implementations can have the same time complexity but different auxiliary-space requirements.