3 ms·
It is being pedantic, but the issue is in the context of binary search: Let us say that I ask you to find the number I am thinking about between -1000 and 1000
by roflyear 4y ago
It is being pedantic, but the issue is in the context of binary search:
Let us say that I ask you to find the number I am thinking about between -1000 and 1000, by repeatedly guessing a number. With each guess, I tell you whether your guess is correct, smaller or larger than my number. A binary search algorithm tries to find a value in an interval by repeating finding the midpoint, using smaller and smaller intervals. You might start with 0, then use either -500 or 500 and so forth.
You don't need negative numbers to do this.... you can easily do it with only positive numbers.