I have a list of incomplete ordered numbers. I want to find a particular number with as few steps as possible.
Are there any improvements on this algorithm, I assume you can count the set size without difficulty - it will be stored and updated every time a new item is added.
Your object is to get your cursor over the value x
The first number (smallest) is s, and the last number (greatest) is g.
- Take the midpoint m1 of the set: calculate is x < m1,
- If yes then s <= x < m1
- If no then m1 < x <= g
- If m1 = x then you're done.
Keep repeating till you find x. Basically dividing the set into two parts with each iteration till you hit x.
The purpose is to retrieve a numerical id from a very large table to then find the associated other records.
I would imagine this is the most trivial kind of indexing available, are there improvements?