Binary search requires splitting the search space into two halves, then asking “is it in that half?”
Normally the “is it in that half?” check involves a numerical comparison: test value versus target value. “higher or lower” here gets you to “is it in that half?”
So finding the midpoint seems like a core part of the process, but really that’s just a shortcut in the case of comparable values, that helps you split into two and check membership.
I admit I couldn’t think of that either: just alter half the items and check for effect.
Ah, obvious now, thank you. For some reason
myhis brain couldn’t get to actually turning off half the breakers in one goBinary search requires splitting the search space into two halves, then asking “is it in that half?”
Normally the “is it in that half?” check involves a numerical comparison: test value versus target value. “higher or lower” here gets you to “is it in that half?”
So finding the midpoint seems like a core part of the process, but really that’s just a shortcut in the case of comparable values, that helps you split into two and check membership.
I admit I couldn’t think of that either: just alter half the items and check for effect.