依頼内容
“Flowchart of binary search: set low and high, loop while low ≤ high, compute mid, return mid if it matches the target, otherwise move low or high, and return -1 when the loop ends.”
次はこちらTurn it into the recursive versionAdd a check for an empty array
この図に含まれるもの
図の背後にある意思決定を読み解く。
01Loop condition "low <= high" is the sentinel
when low crosses high, -1 is returned.
02
Two separate update branches (sethi, setlo) make the asymmetric narrowing explicit and verifiable.
03Mid computed as (low + high) / 2
in production code use low + (high - low) / 2 to prevent integer overflow.
Extend to binary search on answer space (binary search on result) for optimization problems.
関連する図