Middle Path
If printing "Hello World!" is 101, then writing an algorithm for binary search is 201; usually the first step on the next big thing you learn. Most of us learn algorithms repeatedly ignoring special conditions and even scale. So pretty early in our writing of professional code, our programs start to misbehave when pushed a little.It turns out that even the professional versions of these seemingly simple constructs aren't free of complacency, as the man who wrote binary search for arrays in Java ruefully realises.
1 comment:
Hey Ramanand,
The overflow problem arises even in the oh-so-oft-repeated-interview-question to swap 2 numbers without a third variable.
We usually do a=a+b; b=a-b; a=a-b;
But then for very high values of a or b it results in overflow. Simple way to avoid overflow is to use XOR instead of + or -
Post a Comment