Add binary-search module: iterative/recursive search, overflow-safe midpoint, lowerBound/upperBound, rotated arrays, search on the answer, 10 interview problems (14 tests, 14 transcripts)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b3tGdV3Vm51QUZxg2x
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
Searching for 26 among 2, 4, 6, ... 32 (sixteen values, indexes 0..15)
|
||||
======================================================================
|
||||
|
||||
low=0 high=15 mid=7 a[mid]=16 -> 26 > 16, low=8
|
||||
low=8 high=15 mid=11 a[mid]=24 -> 26 > 24, low=12
|
||||
low=12 high=15 mid=13 a[mid]=28 -> 26 < 28, high=12
|
||||
low=12 high=12 mid=12 a[mid]=26 -> equals 26, return 12
|
||||
result: index 12 after 4 elements compared; a linear scan needs 13
|
||||
Reference in New Issue
Block a user