posted 16 years ago
think of it like the guessing game. I've picked a number between 1 and 100. try and guess it in as few as possible, and i'll tell you higher or lower each time.
well, your going to start in the middle. (1+100)/2 = 50 (more or less - we'll always round down).
i tell you 'higher'.
You now know the number is between 50 and 100, so you guess in the middle of that... (50+100)/2 = 75.
i tell you lower. so now you guess (50+75)/2 = 62ish.
62 is too low.
so, (62+75)/2 = 68. too high.
(62+68)/2 = 65. too high.
(62+65)/2 = 63ish.
63 is correct!!!
[ September 13, 2007: Message edited by: Fred Rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors