← all challenges

binary-search

Binary search implementation with full docs

the prompt

$ cat binary-search.prompt
Implement `binary_search(arr: list[int], target: int) -> int` in Python. It should return the index of target in a sorted list, or -1 if not found. Write a proper docstring with Args, Returns, and Raises sections. Add inline comments explaining the algorithm logic. Include 3 test cases as examples in the docstring.

rubric

correctness

Is the binary search algorithm correct? Does it handle edge cases (empty list, target not found, duplicates)?

quality

Is the loop/recursion clean? Correct handling of integer overflow for mid calculation?

documentation

Does it have Args/Returns/Raises docstring? Are inline comments meaningful (not just restating the code)? Are the 3 examples correct?

results

Claude Haiku 4.5

7.8
correctness 8.0quality 6.5documentation 9.013145ms

# Correct binary search logic and good edge-case handling, but the added `sorted(arr)` validation each call turns the algorithm into O(n log n), contradicting the claimed O(log n) efficiency and undermining the point of binary search; documentation is thorough and examples are accurate.