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:
Claude
2026-11-22 19:47:36 +05:30
parent 3336e2ba15
commit ce12a80f58
39 changed files with 2110 additions and 0 deletions
@@ -0,0 +1,27 @@
lowerBound / upperBound on [1, 2, 2, 2, 2, 2, 3, 5, 5, 8] (indexes 0..9)
========================================================================
key | lowerBound | upperBound | first | last | count | iterative | Arrays.binarySearch
0 | 0 | 0 | -1 | -1 | 0 | -1 | -1
1 | 0 | 1 | 0 | 0 | 1 | 0 | 0
2 | 1 | 6 | 1 | 5 | 5 | 4 | 4
3 | 6 | 7 | 6 | 6 | 1 | 6 | 6
4 | 7 | 7 | -1 | -1 | 0 | -1 | -8
5 | 7 | 9 | 7 | 8 | 2 | 7 | 7
8 | 9 | 10 | 9 | 9 | 1 | 9 | 9
9 | 10 | 10 | -1 | -1 | 0 | -1 | -11
lowerBound for 2:
low=0 high=10 mid=5 a[mid]=2 -> 2 >= 2, mid might be the answer, high=5
low=0 high=5 mid=2 a[mid]=2 -> 2 >= 2, mid might be the answer, high=2
low=0 high=2 mid=1 a[mid]=2 -> 2 >= 2, mid might be the answer, high=1
low=0 high=1 mid=0 a[mid]=1 -> 1 < 2, everything up to mid is too small, low=1
low=1 high=1 -> range is empty, answer 1
lowerBound for 4:
low=0 high=10 mid=5 a[mid]=2 -> 2 < 4, everything up to mid is too small, low=6
low=6 high=10 mid=8 a[mid]=5 -> 5 >= 4, mid might be the answer, high=8
low=6 high=8 mid=7 a[mid]=5 -> 5 >= 4, mid might be the answer, high=7
low=6 high=7 mid=6 a[mid]=3 -> 3 < 4, everything up to mid is too small, low=7
low=7 high=7 -> range is empty, answer 7