Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion search.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,19 @@ def binary(data: List[Any], target: Any, comparator: Callable[[Any, Any], int])
- positive if a > b
Returns the index of the found element, or -1 if not found.
"""
pass
left, right = 0, len(data) - 1

while left <= right:
mid = (left + right) // 2
cmp_result = comparator(data[mid], target)

if cmp_result == 0:
return mid
elif cmp_result < 0:
left = mid + 1
else:
right = mid - 1

# Raise NotFoundError (required by your test suite)
raise NotFoundError(f"{target} not found")