2 ms·
I remember reading the part about binary search in Programming Pearls and it left a big impression on me. It is a very neat example because it's something that
by ufo 6y ago
I remember reading the part about binary search in Programming Pearls and it left a big impression on me. It is a very neat example because it's something that everyone thinks they know how to do, but there are enough places to introduce an off-by-one error that it is very easy to mess up if you aren't careful.
The big takeaway for me was the importance of thinking about invariants, and of documenting said invariants in comments next to the code. It has become my go-to example if I need to teach someone about invariants.